Skip to content

fix: protect cookie authentication against CSRF - #653

Merged
david-loe merged 1 commit into
mainfrom
fix/cookie-csrf-origin
Oct 29, 2026
Merged

david-loe merged 1 commit into
mainfrom
fix/cookie-csrf-origin

Conversation

@david-loe

Copy link
Copy Markdown
Owner

Cookie-authenticated writes accepted cross-site form submissions, allowing an attacker to transfer report ownership through an administrator's session when SameSite=None was enabled. Require an exact trusted Origin and a session-bound X-CSRF-Token for cookie-authenticated writes, including logout and multipart uploads. LDAP login and magic-link requests require only a trusted Origin; external login callbacks and bearer/usage-token authentication retain their existing behavior.

Add GET /auth/csrf with a non-cacheable response and generate its token from the session using HMAC. The frontend keeps the token in memory, shares concurrent token requests, clears it when the session changes, and supports pending offline logout without retrying mutations. Regression tests cover ownership preservation, invalid origins/tokens, session rotation, multipart requests, bearer access, and magic-link queue side effects.

Validation: backend and frontend suites; targeted CSRF/session tests; HTTPS/proxy tests with SameSite=None; production frontend build and smoke checks; Chromium and Firefox production interactions and service-worker migration; Biome and dependency-sync checks.

Deploy frontend and backend together and reload existing frontend tabs. No database migration or new dependencies.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 8254fc1 and b77785a.

Files selected for processing: 17
  • backend/app.ts
  • backend/controller/authController.ts
  • backend/controller/authentication.ts
  • backend/csrf.ts
  • backend/tests/_agent.ts
  • backend/tests/_setup.ts
  • backend/tests/api/csrf.ts
  • backend/tests/api/sessionWrites.ts
  • backend/tests/api/user.ts
  • backend/tsoa.json
  • frontend/src/api.ts
  • frontend/src/csrf.ts
  • frontend/src/helper.ts
  • frontend/src/session.ts
  • frontend/tests/browser/fixture.mjs
  • frontend/tests/csrf.test.ts
  • frontend/tests/http.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@david-loe
david-loe force-pushed the fix/cookie-csrf-origin branch from 67d070c to b77785a Compare October 29, 2026 10:03
@david-loe
david-loe merged commit d1782a9 into main Oct 29, 2026
10 checks passed
@david-loe
david-loe deleted the fix/cookie-csrf-origin branch November 2, 2026 09:10
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