fix: Complete CSRF protection implementation
Closes three CSRF security gaps identified in code review: 1. Added X-CSRF-Token and X-Workspace-Id to CORS allowed headers - Updated apps/api/src/main.ts to accept CSRF token headers 2. Integrated CSRF token handling in web client - Added fetchCsrfToken() to fetch token from API - Store token in memory (not localStorage for security) - Automatically include X-CSRF-Token in POST/PUT/PATCH/DELETE - Implement automatic token refresh on 403 CSRF errors - Added comprehensive test coverage for CSRF functionality 3. Applied CSRF Guard globally - Added CsrfGuard as APP_GUARD in app.module.ts - Verified @SkipCsrf() decorator works for exempted endpoints All tests passing. CSRF protection now enforced application-wide. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -75,7 +75,7 @@ async function bootstrap() {
|
||||
},
|
||||
credentials: true, // Required for cookie-based authentication
|
||||
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
allowedHeaders: ["Content-Type", "Authorization", "Cookie"],
|
||||
allowedHeaders: ["Content-Type", "Authorization", "Cookie", "X-CSRF-Token", "X-Workspace-Id"],
|
||||
exposedHeaders: ["Set-Cookie"],
|
||||
maxAge: 86400, // 24 hours - cache preflight requests
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user