From 8392ca90bde771c597508106e51cf11be781f746 Mon Sep 17 00:00:00 2001 From: Franck Perrin Date: Wed, 30 Oct 2019 12:56:02 +0100 Subject: [PATCH] Check IP with Symfony HttpFoundation IpUtils to allow the use of a netmask in the allowed IPs --- README.md | 2 +- src/bundle/Event/Subscriber/MaintenanceModeSubscriber.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 267d6f8..16f4dc5 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ ezpublish: default: maintenance_mode: enabled: true - allowed_ips: ['::1', '10.0.0.1'] + allowed_ips: ['::1', '10.0.0.1', '192.168.0.0/16'] response_code: 404 template: '@Acme/custom_maintenance.html.twig' ``` \ No newline at end of file diff --git a/src/bundle/Event/Subscriber/MaintenanceModeSubscriber.php b/src/bundle/Event/Subscriber/MaintenanceModeSubscriber.php index a1a2cab..1a7e6d4 100644 --- a/src/bundle/Event/Subscriber/MaintenanceModeSubscriber.php +++ b/src/bundle/Event/Subscriber/MaintenanceModeSubscriber.php @@ -9,6 +9,7 @@ use eZ\Publish\Core\MVC\ConfigResolverInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\IpUtils; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Twig\Environment; @@ -61,7 +62,7 @@ public function onKernelRequest(GetResponseEvent $event): void $allowedIps = $this->configResolver->getParameter('maintenance_mode.allowed_ips'); - if (\in_array($request->getClientIp(), $allowedIps, true)) { + if (IpUtils::checkIp($request->getClientIp(), $allowedIps)) { return; }