Last active
March 25, 2019 21:03
-
-
Save l0gicgate/6e9f44cd4c8b4ddd50d628358d210621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$app->add(function ($request, $response, $next) { | |
$detectedIp = $request->getAttribute('ip_address', null); | |
$trustedIps = ['1.1.1.1', '2.2.2.2']; | |
if (!$detectedIp || !in_array($detectedIp, $trustedIps)) { | |
return $response->withJson(['error' => 'Unauthorized ip address', 401]); | |
} | |
return $next($request, $response; | |
}); | |
$checkProxyHeaders = true; // Note: Never trust the IP address for security processes! | |
$trustedProxies = ['10.0.0.1', '10.0.0.2']; // Note: Never trust the IP address for security processes! | |
$app->add(new RKA\Middleware\IpAddress($checkProxyHeaders, $trustedProxies)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment