Skip to content

Fix CSRF vulnerability on recovery-email endpoint (csrf-csrf) - #7

Open
farahIslamTaha wants to merge 2 commits into
Advanced-Computer-Lab-2026:mainfrom
farahIslamTaha:main
Open

farahIslamTaha wants to merge 2 commits into
Advanced-Computer-Lab-2026:mainfrom
farahIslamTaha:main

Conversation

@farahIslamTaha

Copy link
Copy Markdown

Summary

  • Added anti-CSRF protection to the account settings recovery-email update using the csrf-csrf package (double-submit-cookie pattern).
  • Issued a per-session CSRF token via a new GET /api/csrf-token endpoint, and required it on all state-changing requests.
  • Kept GET requests and the pre-auth routes (login/register/logout) exempt.
  • Updated the client to attach the token in an x-csrf-token header on every mutating request.

Result

  • A forged cross-site POST with no CSRF token is now rejected with 403 and the recovery email is left unchanged.
  • The legitimate update still works.
  • The shipped test suite passes on CI (server and client CSRF tests green).

Files changed

  • server/src/app.js: configured csrf-csrf, added /api/csrf-token route and the protection middleware.
  • client/src/api.js: added a request interceptor that attaches the CSRF token on writes.
  • server/package.json: added the csrf-csrf dependency.

@farahIslamTaha
farahIslamTaha force-pushed the main branch 2 times, most recently from 75e4a29 to ae15ef2 Compare December 3, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant