Skip to content

Commit e8e1461

Browse files
committed
ipv6 support: base64_encode cache keys
1 parent 52a7202 commit e8e1461

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/ApiCache.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function configure(
8888
*/
8989
private function addRemediationToCacheItem(string $ip, string $type, int $expiration, int $decisionId): string
9090
{
91-
$item = $this->adapter->getItem($ip);
91+
$item = $this->adapter->getItem(base64_encode($ip));
9292

9393
// Merge with existing remediations (if any).
9494
$remediations = $item->isHit() ? $item->get() : [];
@@ -130,7 +130,7 @@ private function addRemediationToCacheItem(string $ip, string $type, int $expira
130130
*/
131131
private function removeDecisionFromRemediationItem(string $ip, int $decisionId): bool
132132
{
133-
$item = $this->adapter->getItem($ip);
133+
$item = $this->adapter->getItem(base64_encode($ip));
134134
$remediations = $item->get();
135135

136136
$index = false;
@@ -149,7 +149,7 @@ private function removeDecisionFromRemediationItem(string $ip, int $decisionId):
149149
'type' => 'CACHE_ITEM_REMOVED',
150150
'ip' => $ip,
151151
]);
152-
$this->adapter->delete($ip);
152+
$this->adapter->delete(base64_encode($ip));
153153

154154
return true;
155155
}
@@ -426,7 +426,7 @@ private function miss(string $ip): string
426426
*/
427427
private function hit(string $ip): string
428428
{
429-
$remediations = $this->adapter->getItem($ip)->get();
429+
$remediations = $this->adapter->getItem(base64_encode($ip))->get();
430430

431431
// We apply array values first because keys are ids.
432432
$firstRemediation = array_values($remediations)[0];
@@ -447,7 +447,7 @@ public function get(string $ip): string
447447
throw new BouncerException('CrowdSec Bouncer configured in "stream" mode. Please warm the cache up before trying to access it.');
448448
}
449449

450-
if ($this->adapter->hasItem($ip)) {
450+
if ($this->adapter->hasItem(base64_encode($ip))) {
451451
$remediation = $this->hit($ip);
452452
$cache = 'hit';
453453
} else {

0 commit comments

Comments
 (0)