Skip to content

Commit ce169c0

Browse files
Update HAProxy SPOA documentation with new cookie management approach
- Add new cookie management section explaining the improved approach - Update HAProxy configuration examples to include http-after-response directives - Add automatic cookie setting/clearing based on captcha_status - Improve documentation for CAPTCHA cookie handling
1 parent fae3a28 commit ce169c0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

crowdsec-docs/unversioned/bouncers/haproxy_spoa.mdx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ frontend http-in
170170
filter spoe engine crowdsec config /etc/haproxy/crowdsec.cfg
171171
http-request set-header X-CrowdSec-Remediation %[var(txn.crowdsec.remediation)]
172172
http-request lua.crowdsec_handle if { var(txn.crowdsec.remediation) -m found }
173+
174+
## Handle captcha cookie management via HAProxy (new approach)
175+
## Set captcha cookie when SPOA provides captcha_status (pending or valid)
176+
http-after-response set-header Set-Cookie %[var(txn.crowdsec.captcha_cookie)] if { var(txn.crowdsec.captcha_status) -m found } { var(txn.crowdsec.captcha_cookie) -m found }
177+
## Clear captcha cookie when cookie exists but no captcha_status (Allow decision)
178+
http-after-response set-header Set-Cookie %[var(txn.crowdsec.captcha_cookie)] if { var(txn.crowdsec.captcha_cookie) -m found } !{ var(txn.crowdsec.captcha_status) -m found }
179+
173180
use_backend <whatever>
174181
175182
backend crowdsec-spoa
@@ -212,6 +219,23 @@ recaptcha
212219
turnstile
213220
```
214221

222+
#### Cookie Management (New Approach)
223+
224+
The HAProxy SPOA bouncer now supports improved cookie management for CAPTCHA handling. This new approach uses `http-after-response` directives to manage CAPTCHA cookies more efficiently:
225+
226+
```haproxy
227+
## Handle captcha cookie management via HAProxy (new approach)
228+
## Set captcha cookie when SPOA provides captcha_status (pending or valid)
229+
http-after-response set-header Set-Cookie %[var(txn.crowdsec.captcha_cookie)] if { var(txn.crowdsec.captcha_status) -m found } { var(txn.crowdsec.captcha_cookie) -m found }
230+
## Clear captcha cookie when cookie exists but no captcha_status (Allow decision)
231+
http-after-response set-header Set-Cookie %[var(txn.crowdsec.captcha_cookie)] if { var(txn.crowdsec.captcha_cookie) -m found } !{ var(txn.crowdsec.captcha_status) -m found }
232+
```
233+
234+
This approach provides:
235+
- Automatic cookie setting when CAPTCHA status is pending or valid
236+
- Automatic cookie clearing when the decision is to allow (no CAPTCHA status)
237+
- More reliable cookie management compared to previous methods
238+
215239
### Prometheus Metrics
216240

217241
Enable and expose metrics:
@@ -393,6 +417,12 @@ frontend test
393417
http-request set-header X-CrowdSec-IsoCode %[var(txn.crowdsec.isocode)] if { var(txn.crowdsec.isocode) -m found }
394418
http-request lua.crowdsec_handle if { var(txn.crowdsec.remediation) -m found }
395419
420+
## Handle captcha cookie management via HAProxy (new approach)
421+
## Set captcha cookie when SPOA provides captcha_status (pending or valid)
422+
http-after-response set-header Set-Cookie %[var(txn.crowdsec.captcha_cookie)] if { var(txn.crowdsec.captcha_status) -m found } { var(txn.crowdsec.captcha_cookie) -m found }
423+
## Clear captcha cookie when cookie exists but no captcha_status (Allow decision)
424+
http-after-response set-header Set-Cookie %[var(txn.crowdsec.captcha_cookie)] if { var(txn.crowdsec.captcha_cookie) -m found } !{ var(txn.crowdsec.captcha_status) -m found }
425+
396426
use_backend test_backend
397427
```
398428

0 commit comments

Comments
 (0)