diff --git a/core/modules/ban/ban.services.yml b/core/modules/ban/ban.services.yml index 4dc6085..7baeaa9 100644 --- a/core/modules/ban/ban.services.yml +++ b/core/modules/ban/ban.services.yml @@ -8,4 +8,6 @@ services: class: Drupal\ban\BanMiddleware arguments: ['@ban.ip_manager'] tags: + # Ensure to come before page caching, so you don't serve cached pages to + # banned users. - { name: http_middleware, priority: 250 } diff --git a/core/modules/ban/src/BanMiddleware.php b/core/modules/ban/src/BanMiddleware.php index d7f450d..ca4f1d7 100644 --- a/core/modules/ban/src/BanMiddleware.php +++ b/core/modules/ban/src/BanMiddleware.php @@ -50,11 +50,9 @@ public function __construct(HttpKernelInterface $http_kernel, BanIpManagerInterf public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { $ip = $request->getClientIp(); if ($this->banIpManager->isBanned($ip)) { - $response = new Response(String::format('Sorry @ip has been banned', ['@ip' => $ip]), 403); - return $response; + return new Response(String::format('Sorry @ip has been banned', ['@ip' => $ip]), 403); } return $this->httpKernel->handle($request, $type, $catch); } } -