fix(api): harden CSRF middleware and normalize CSRF errors for production#27
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…ng react module resolution
… release matrix job names
… and webhook Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Owner
Author
|
Opened follow-up tracking issue for upstream audit advisory (GHSA-v2v4-37r5-5v8g): #28. We’ll remove the temporary CI exception once upstream is fixed. |
dzhhem
approved these changes
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Addresses 4 CodeQL security alerts and 7 npm audit vulnerabilities. Rewrites the CSRF middleware to use proper double-submit cookie token validation (
csrf-csrfv4), normalizes CSRF errors so they always surface as structured403responses in production, and closes remaining security gaps flagged by static analysis.Changes by area:
doubleCsrftoken validation; addedGET /api/csrf-tokenendpoint; web client now caches and injects the token on every mutation, with automatic retry on 403doubleCsrfProtectionis now wrapped inapp.tsto convert rawHttpErrorintoAppError("CSRF validation failed", 403)so the global error handler always returns a consistent JSON shapecontentSecurityPolicy: falsein dev (CodeQL alert fix(vercel): stabilize basePath redirects and polish auth/profile UI #19) by using explicit CSP directives; changedcrossOriginResourcePolicyfromcross-origintosame-originuserMutationLimiter(60 req / 15 min) toPATCH /me,DELETE /me,DELETE /me/auth-methods/:id(CodeQL alert chore(api): harden docs/dev tooling, add system health docs, and clean up user/admin routes #20)sanitizeText→decodeHtmlEntitiesand removed</>→</>reversal that re-introduced unescaped HTML (CodeQL alert Seed: UserApiKey records fail to decrypt with different API_KEY_ENCRYPTION_SECRET #17)overridesfornodemailer,postcss,next,axios; CI audit job now blocks at--audit-level=moderatewithoutcontinue-on-errorResolves CodeQL alerts #17, #18, #19, #20 (Security tab)
Type of change
How Has This Been Tested?
API (Jest): rewrote
security.middleware.test.tsto usedoubleCsrfProtectiondirectly — verifies that a missing CSRF token on a mutation request callsnextwith a403error, and that the Stripe webhook path bypasses CSRF. All 59 API tests pass.Web (Vitest): updated
api.test.tsmock to includeinterceptors.request.usefor the new CSRF interceptor. All 19 web tests pass.To reproduce locally:
Checklist: