Skip to content

feat(middleware): add CSRF protection [H11]#559

Merged
lakhansamani merged 1 commit intomainfrom
fix/h11-csrf-protection
Apr 4, 2026
Merged

feat(middleware): add CSRF protection [H11]#559
lakhansamani merged 1 commit intomainfrom
fix/h11-csrf-protection

Conversation

@lakhansamani
Copy link
Copy Markdown
Contributor

Summary

  • H11 (High): No CSRF validation existed despite cookie-based auth with SameSite=None
  • Requires Content-Type: application/json or X-Requested-With header on state-changing requests
  • Exempts OAuth callback routes (provider redirects) and token endpoint
  • Browsers cannot send custom headers cross-origin without CORS preflight

Test plan

  • All packages compile
  • Verify GraphQL mutations still work (they send Content-Type: application/json)
  • Verify OAuth flows still work (callbacks exempted)
  • Verify plain form POST without headers is rejected

X-CSRF-Token was listed in allowed CORS headers but never validated.
Combined with Allow-Credentials: true and SameSite=None cookies, all
POST mutations were CSRF-vulnerable.

Adds middleware requiring Content-Type: application/json or
X-Requested-With header on POST/PUT/DELETE/PATCH requests. Browsers
cannot send these headers cross-origin without CORS preflight.

OAuth callback and token routes are exempted (provider redirects,
client credentials flow).

Fixes: H11 (High)
@lakhansamani lakhansamani merged commit a70aeda into main Apr 4, 2026
@lakhansamani lakhansamani deleted the fix/h11-csrf-protection branch April 4, 2026 11:39
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