Skip to content

Commit 2f4e11b

Browse files
authored
Merge pull request #692 from favicode/fix/maintenance-ips-in-rate-limiting
Fix for checking if current IP is in maintenance IP list
2 parents a5748c1 + a0622b7 commit 2f4e11b

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

Model/FrontControllerPlugin.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -334,26 +334,24 @@ private function verifyBots($ip)
334334
return false;
335335
}
336336

337-
private function readMaintenanceIp($ip)
337+
private function readMaintenanceIp($clientIps)
338338
{
339339
$tag = self::FASTLY_CACHE_MAINTENANCE_IP_FILE_TAG;
340-
$data = json_decode($this->cache->load($tag));
341-
if (empty($data)) {
342-
$data = [];
340+
$allowedIps = json_decode($this->cache->load($tag));
341+
if (empty($allowedIps)) {
342+
$allowedIps = [];
343343
$flagDir = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
344344
if ($flagDir->isExist('.maintenance.ip')) {
345345
$temp = $flagDir->readFile('.maintenance.ip');
346-
$data = explode(',', trim($temp));
347-
$this->cache->save(json_encode($data), $tag, []);
346+
$allowedIps = explode(',', trim($temp));
347+
$this->cache->save(json_encode($allowedIps), $tag, []);
348348
}
349349
}
350350

351-
foreach ($data as $key => $value) {
352-
if (!empty($value) && trim($value) == $ip) {
353-
return true;
354-
}
355-
}
356-
return false;
351+
$ips = array_map("trim", explode(",", $clientIps));
352+
$isAllowed = array_intersect($allowedIps, $ips);
353+
354+
return !empty($isAllowed);
357355
}
358356

359357
private function log($message)

0 commit comments

Comments
 (0)