diff --git a/core/lib/Drupal/Core/Flood/MemoryBackend.php b/core/lib/Drupal/Core/Flood/MemoryBackend.php index f911a98..770581f 100644 --- a/core/lib/Drupal/Core/Flood/MemoryBackend.php +++ b/core/lib/Drupal/Core/Flood/MemoryBackend.php @@ -47,7 +47,7 @@ public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) if (!isset($identifier)) { $identifier = ip_address(); } - $limit = REQUEST_TIME - $window; + $limit = microtime() - $window; $number = count(array_filter($this->events[$name][$identifier], function ($timestamp) use ($limit) { return $timestamp > $limit; })); @@ -60,12 +60,12 @@ public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) public function garbageCollection() { foreach ($this->events as $name => $identifiers) { foreach ($this->events[$name] as $identifier => $timestamps) { - $expired = array_filter(array_keys($timestamps), function ($expiration) { - return $expiration < REQUEST_TIME; + // Filter by key (expiration) but preserve key => value associations. + $this->events[$name][$identifier] = array_filter($timestamps, function () use (&$timestamps) { + $expiration = key($timestamps); + next($timestamps); + return $expiration > REQUEST_TIME; }); - foreach($expired as $expiration) { - unset($this->events[$name][$identifier][$expiration]); - } } } }