Skip to content

Commit b0f8f29

Browse files
feat(cache): Add configuration for captcha flow cache
1 parent bae5156 commit b0f8f29

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

inc/admin/advanced-settings.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ function adminAdvancedSettings()
185185
return (int) $input > 0 ? (int) $input : 1 ;
186186
}, ' seconds. <p>The duration between re-asking LAPI about an already checked bad IP.<br>Minimum 1 second.<br> Note that this setting can not be apply in stream mode.', '...', 'width: 115px;', 'number', (bool) get_option('crowdsec_stream_mode'));
187187

188+
// Field "crowdsec_captcha_cache_duration"
189+
addFieldString('crowdsec_captcha_cache_duration', 'Captcha flow cache lifetime', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
190+
if ( (int) $input <= 0) {
191+
add_settings_error('Captcha cache duration', 'crowdsec_error', 'Captcha cache duration: Minimum is 1 second.');
192+
193+
return Constants::CACHE_EXPIRATION_FOR_CAPTCHA;
194+
}
195+
196+
return (int) $input > 0 ? (int) $input : Constants::CACHE_EXPIRATION_FOR_CAPTCHA ;
197+
}, ' seconds. <p>The lifetime of cached captcha flow for some IP. <br>If a user has to interact with a captcha wall, we store in cache some values in order to know if he has to resolve or not the captcha again.<br>Minimum 1 second. Default: '.Constants::CACHE_EXPIRATION_FOR_CAPTCHA.'.', Constants::CACHE_EXPIRATION_FOR_CAPTCHA, 'width: 115px;', 'number');
198+
199+
188200
/***************************
189201
** Section "Remediation" **
190202
**************************/

inc/bouncer-instance.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ function getDatabaseSettings(): array
6464
Constants::CACHE_EXPIRATION_FOR_CLEAN_IP,
6565
'bad_ip_cache_duration' => (int)get_option('crowdsec_bad_ip_cache_duration') ?:
6666
Constants::CACHE_EXPIRATION_FOR_BAD_IP,
67+
'captcha_cache_duration' => (int)get_option('crowdsec_captcha_cache_duration') ?:
68+
Constants::CACHE_EXPIRATION_FOR_CAPTCHA,
6769
// Geolocation
6870
'geolocation' => []
6971
];

inc/options-config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ function getCrowdSecOptionsConfig()
1616
['name' => 'crowdsec_memcached_dsn', 'default' => '', 'autoInit' => true],
1717
['name' => 'crowdsec_clean_ip_cache_duration', 'default' => Constants::CACHE_EXPIRATION_FOR_CLEAN_IP, 'autoInit' => true],
1818
['name' => 'crowdsec_bad_ip_cache_duration', 'default' => Constants::CACHE_EXPIRATION_FOR_BAD_IP, 'autoInit' => true],
19+
['name' => 'crowdsec_captcha_cache_duration', 'default' => Constants::CACHE_EXPIRATION_FOR_CAPTCHA,
20+
'autoInit' => true],
1921
['name' => 'crowdsec_fallback_remediation', 'default' => Constants::REMEDIATION_CAPTCHA, 'autoInit' => true],
2022
['name' => 'crowdsec_hide_mentions', 'default' => false, 'autoInit' => true],
2123
['name' => 'crowdsec_trust_ip_forward_array', 'default' => [], 'autoInit' => true],

0 commit comments

Comments
 (0)