first commit
This commit is contained in:
38
app/Http/Middleware/IpWhitelist.php
Normal file
38
app/Http/Middleware/IpWhitelist.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Ограничение доступа к административным разделам по списку IP/подсетей.
|
||||
*
|
||||
* Мера ФСТЭК: УПД — управление доступом, ЗИС.17. Включается через
|
||||
* config('security.ip_whitelist'). Используется для admin-маршрутов.
|
||||
*/
|
||||
class IpWhitelist
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (! config('security.ip_whitelist.enabled')) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$ranges = (array) config('security.ip_whitelist.ranges');
|
||||
|
||||
if ($ranges !== [] && ! IpUtils::checkIp($request->ip(), $ranges)) {
|
||||
Log::channel(config('audit.siem.channel', 'stack'))->warning('ip_whitelist.denied', [
|
||||
'ip' => $request->ip(),
|
||||
'path' => $request->path(),
|
||||
]);
|
||||
|
||||
abort(Response::HTTP_FORBIDDEN, 'Доступ с данного адреса запрещён.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user