CSRF Token Validation for Account Email Changes
Level 3 · node · Security · CSRF
Scenario
An authenticated account email-change API uses both a session cookie and a CSRF token. Valid requests and requests with no token behave as expected, but a token issued to a different login session can also change the email successfully. The session repository, CSRF middleware, account handler, and user repository are separated.
Requirements
- Email changes require a valid authenticated session - The CSRF token must exactly match the token issued to the current login session - A missing token or a token from another session returns 403 - CSRF validation failures must not change the stored user email - A correct session and CSRF token combination changes the email and returns 200
Acceptance criteria
- A request using the CSRF token issued to the current session changes the email successfully
- A request without a CSRF token is rejected with 403
- A request using a CSRF token from another login session is rejected with 403
- The previous email remains unchanged after CSRF validation failure
- A nonexistent session is handled with 401