Skip to content

Commit 8670c0f

Browse files
authored
Merge pull request #32 from crowdsecurity/no-exp-limit-in-stream-mode
No expiration limits in stream mode
2 parents 44741cf + e0270ff commit 8670c0f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/ApiCache.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,20 @@ private static function parseDurationToSeconds(string $duration): int
208208
private function formatRemediationFromDecision(?array $decision): array
209209
{
210210
if (!$decision) {
211-
return [Constants::REMEDIATION_BYPASS, time() + $this->cacheExpirationForCleanIp, 0];
211+
$duration = time() + $this->cacheExpirationForCleanIp;
212+
if (!$this->liveMode) {
213+
// In stream mode we considere an clean IP forever... until the next resync.
214+
$duration = PHP_INT_MAX;
215+
}
216+
return [Constants::REMEDIATION_BYPASS, $duration, 0];
212217
}
213218

214-
$duration = min($this->cacheExpirationForBadIp, self::parseDurationToSeconds($decision['duration']));
219+
$duration = self::parseDurationToSeconds($decision['duration']);
220+
221+
// Don't set a max duration in stream mode to avoid bugs. Only the stream update has to change the cache state.
222+
if ($this->liveMode) {
223+
$duration = min($this->cacheExpirationForBadIp, $duration);
224+
}
215225

216226
return [
217227
$decision['type'], // ex: ban, captcha

src/RestClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function request(
9696

9797
$this->logger->debug('', [
9898
'type' => 'HTTP CALL',
99-
'method' => $this->baseUri,
99+
'method' => $method,
100100
'uri' => $this->baseUri.$endpoint,
101101
]);
102102

src/templates/captcha.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function displayCaptchaTemplate(bool $error, string $captchaImageSrc, string $ca
4545
<p class="desc">Please complete the security check.</p>
4646

4747
<img src="<?php echo $captchaImageSrc; ?>" alt="captcha to fill" />
48-
<p><small><a href="#" onclick="newImage()">refresh image</a></small></p>
48+
<p><small><a id="refresh_link" href="#" onclick="newImage()">refresh image</a></small></p>
4949

5050
<form method="post" id="captcha" action="<?php echo $captchaResolutionFormUrl; ?>">
5151
<input type="text" name="phrase" placeholder="Type here..." autofocus autocomplete="off" />

0 commit comments

Comments
 (0)