Skip to content

Commit 2e5e2ae

Browse files
committed
fix fallback remediation
1 parent 7e61deb commit 2e5e2ae

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

src/ApiCache.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ private function saveRemediationsForIp(array $decisions, string $ip): string
280280
if (\count($decisions)) {
281281
foreach ($decisions as $decision) {
282282
if (!\in_array($decision['type'], Constants::ORDERED_REMEDIATIONS)) {
283-
$highestRemediationLevel = Constants::ORDERED_REMEDIATIONS[0];
284-
$this->logger->warning('', ['type' => 'UNKNOWN_REMEDIATION', 'remediation' => $decision['type']]);
285-
$decision['type'] = $highestRemediationLevel;
283+
$fallback = $this->config['fallback_remediation'];
284+
$this->logger->warning('', ['type' => 'UNKNOWN_REMEDIATION', 'unknown' => $decision['type'], 'fallback' => $fallback]);
285+
$decision['type'] = $fallback;
286286
}
287287
$remediation = $this->formatRemediationFromDecision($decision);
288288
$remediationResult = $this->addRemediationToCacheItem($ip, $remediation[0], $remediation[1], $remediation[2]);

src/Bouncer.php

-14
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,6 @@ private function capRemediationLevel(string $remediation): string
8989
return $remediation;
9090
}
9191

92-
/**
93-
* If the CrowdSec remediation is not handled by this library,
94-
* replace it with the value of the configuration "fallback_remediation".
95-
*/
96-
private function handleUnknownRemediation(string $remediation): string
97-
{
98-
if (!\in_array($remediation, Constants::ORDERED_REMEDIATIONS)) {
99-
return $this->config['fallback_remediation'];
100-
}
101-
102-
return $remediation;
103-
}
104-
10592
/**
10693
* Get the remediation for the specified IP. This method use the cache layer.
10794
* In live mode, when no remediation was found in cache,
@@ -116,7 +103,6 @@ public function getRemediationForIp(string $ip): string
116103
throw new BouncerException("IP $ip should looks like x.x.x.x, with x in 0-255. Ex: 1.2.3.4");
117104
}
118105
$remediation = $this->apiCache->get(long2ip($intIp));
119-
$remediation = $this->handleUnknownRemediation($remediation);
120106

121107
return $this->capRemediationLevel($remediation);
122108
}

0 commit comments

Comments
 (0)