非生产环境的 server 不对检查客户端 ip 白名单
This commit is contained in:
parent
6c54737d13
commit
436a084581
|
@ -15,6 +15,18 @@ class InternalApi
|
|||
app()->configure('internal_api');
|
||||
}
|
||||
|
||||
private function isClientIPPermitted ($ip) {
|
||||
if (!app()->environment('production', 'staging')) {
|
||||
return true;
|
||||
}
|
||||
if (Str::startsWith($ip, [
|
||||
'127.0.0.', '192.168.', '10.0.',
|
||||
])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
|
@ -25,11 +37,8 @@ class InternalApi
|
|||
public function handle($request, Closure $next)
|
||||
{
|
||||
$ip = $request->getClientIp();
|
||||
|
||||
if (!Str::startsWith($ip, [
|
||||
'127.0.0.', '192.168.', '10.0.'
|
||||
])) {
|
||||
return new JsonResponse('', 404);
|
||||
if (!$this->isClientIPPermitted($ip)) {
|
||||
return new JsonResponse("$ip is forbidden", 403);
|
||||
}
|
||||
|
||||
$params = $request->all();
|
||||
|
|
Loading…
Reference in New Issue
Block a user