Skip to content

Instantly share code, notes, and snippets.

@l0gicgate
Last active March 25, 2019 21:03
Show Gist options
  • Save l0gicgate/6e9f44cd4c8b4ddd50d628358d210621 to your computer and use it in GitHub Desktop.
Save l0gicgate/6e9f44cd4c8b4ddd50d628358d210621 to your computer and use it in GitHub Desktop.
<?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