Files
romm/backend/tests/handler/auth
Dakota Brown b53c7cf98a fix(auth): accept a stale user-bound CSRF token on anonymous requests
Logging in failed once with a CSRF error and succeeded on retry.

`_csrf_tokens_match` validates the user id embedded in the token against
the current request's user. A browser holding a token bound to user N,
whose server-side session is gone (container restart, session expiry,
Redis flush), makes an anonymous login POST. N != None, so the request is
rejected. The rejection response then rotates the cookie, which is why the
second attempt works.

Keep the double-submit check and the cookie/header user agreement
unconditionally, and enforce the caller binding only when there is a
caller. An anonymous request cannot be forged this way regardless: an
attacker cannot read the cookie cross-origin, so it cannot produce the
matching header.

This is the mirror of #3420, which fixed the authenticated direction by
rotating the cookie on safe requests. That path is untouched here, and
test_authenticated_user_binding_still_enforced pins it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-03 12:41:12 -04:00
..
2026-03-10 09:23:12 -04:00