You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: move session management to global level (#113)
* refactor: move session management to global manager
- Replace per-captcha session managers with single global session manager
- Sessions are now managed by SPOA instead of individual Captcha instances
- Reduces goroutine overhead (one GC goroutine instead of N per host)
- Simplifies reload logic (sessions persist automatically)
- Prepares architecture for AppSec session integration
- Captcha now only handles cookie generation from UUIDs
* refactor: remove unused context from captcha and appsec initialization
- Remove Cancel field from Captcha struct (never used during requests)
- Remove ctx parameter from Captcha.Init() and AppSec.Init()
- Remove Cancel() calls since there's no cleanup needed
- Validate() uses context.Background() so it's not affected by reloads
- Sessions persist in global manager, so no context lifecycle needed
* refactor: extract session/cookie creation and improve captcha resilience
- Extract session and cookie creation logic into createNewSessionAndCookie helper
- Use helper in both initial session creation and session recovery after reload
- Make URL reading non-critical for captcha remediation (only affects redirect)
- Improve error messages to clarify critical vs non-critical failures
- Ensure captcha remediation is preferred when captcha is configured, only falling back on truly critical failures
}).Warn("failed to read ssl flag from message, cookie secure flag will default to false - ensure HAProxy is sending the 'ssl_fc' variable as 'ssl' in crowdsec-http message")
417
+
}
418
+
419
+
// Create a new session using global session manager
// handleCaptchaRemediation handles all captcha-related logic including cookie validation,
406
450
// session management, captcha validation, and status updates.
407
451
// Returns the remediation and parsed HTTP request data for reuse in AppSec processing.
@@ -433,40 +477,18 @@ func (s *Spoa) handleCaptchaRemediation(req *request.Request, mes *message.Messa
433
477
}
434
478
435
479
ifuuid=="" {
436
-
ssl, err:=readKeyFromMessage[bool](mes, "ssl")
437
-
iferr!=nil {
438
-
s.logger.WithFields(log.Fields{
439
-
"error": err,
440
-
"key": "ssl",
441
-
}).Warn("failed to read ssl flag from message, cookie secure flag will default to false - ensure HAProxy is sending the 'ssl_fc' variable as 'ssl' in crowdsec-http message")
}).Error("failed to read url from message, cannot proceed with captcha remediation - ensure HAProxy is sending the 'url' variable in crowdsec-http message")
// Read URL - this is not critical for showing the captcha page, only for redirect after validation
534
+
url, err:=readKeyFromMessage[string](mes, "url")
535
+
iferr!=nil {
536
+
s.logger.WithFields(log.Fields{
537
+
"error": err,
538
+
"key": "url",
539
+
"host": matchedHost.Host,
540
+
}).Warn("failed to read url from message, captcha will still be shown but redirect after validation may not work - ensure HAProxy is sending the 'url' variable in crowdsec-http message")
541
+
// Continue with captcha even without URL - we just won't be able to redirect after validation
542
+
} elseifcaptchaStatus!=captcha.Valid&&url!=nil {
510
543
// Update the incoming url if it is different from the stored url for the session ignore favicon requests
0 commit comments