Skip to content

Commit 742769d

Browse files
Merge pull request #111 from julienloizelet/fix/stream-mode-clean-ip-cache-for-ten-years
fix(stream): Cache bypass for ten years in stream mode
2 parents 5bb86cc + cbd8638 commit 742769d

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77

8+
## [0.33.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v0.33.0) - 2022-11-10
9+
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v0.32.0...v0.33.0)
10+
11+
### Fixed
12+
- In stream mode, a clean IP decision (`bypass`) was not cached at all. The decision is now cached for ten years as expected.
13+
14+
---
15+
816
## [0.32.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v0.32.0) - 2022-09-29
917
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v0.31.0...v0.32.0)
1018

src/AbstractCache.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,15 @@ protected function defferUpdateCacheConfig(array $config): void
339339
protected function formatRemediationFromDecision(?array $decision): array
340340
{
341341
if (!$decision) {
342-
$duration = time() + $this->cacheExpirationForCleanIp;
343-
if ($this->streamMode) {
344-
/**
345-
* In stream mode we consider a clean IP forever... until the next resync.
346-
* in this case, forever is 10 years as PHP_INT_MAX will cause trouble with the Memcached Adapter
347-
* (int to float unwanted conversion)
348-
* */
349-
$duration = 315360000;
350-
}
351-
352-
return [Constants::REMEDIATION_BYPASS, $duration, 0];
342+
/**
343+
* In stream mode we consider a clean IP forever... until the next resync.
344+
* in this case, forever is 10 years as PHP_INT_MAX will cause trouble with the Memcached Adapter
345+
* (int to float unwanted conversion)
346+
*
347+
*/
348+
$duration = $this->streamMode ? 315360000 : $this->cacheExpirationForCleanIp;
349+
350+
return [Constants::REMEDIATION_BYPASS, time() + $duration, 0];
353351
}
354352

355353
$duration = self::parseDurationToSeconds($decision['duration']);

src/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Constants
7676
/** @var string Path for html templates folder (e.g. ban and captcha wall) */
7777
public const TEMPLATES_DIR = __DIR__ . "/templates";
7878
/** @var string The last version of this library */
79-
public const VERSION = 'v0.32.0';
79+
public const VERSION = 'v0.33.0';
8080
/** @var string The "disabled" x-forwarded-for setting */
8181
public const X_FORWARDED_DISABLED = 'no_forward';
8282
}

0 commit comments

Comments
 (0)