feat(security): Standardize Security Headers and CORS Policy Restrictions for Production Deployments#657
Conversation
…production hardening Closes ritesh-1918#637 - Update Frontend/vite.config.js: add CSP, X-Content-Type-Options, X-Frame-Options, X-XSS-Protection, Referrer-Policy, Permissions-Policy to Vite dev server and preview server headers; add rollupOptions chunk splitting for vendor/ui bundles - Add backend/middleware/security_headers.py: Helmet-equivalent SecurityHeadersMiddleware that injects HSTS, CSP, X-Frame-Options, X-Content-Type-Options, and friends into every FastAPI response; CORS origins now read from ALLOWED_ORIGINS env var (comma-separated) so production/staging environments need no code changes; add_security_middleware() convenience function replaces the inline CORS block in main.py
|
@advikdivekar is attempting to deploy a commit to the ritesh Team on Vercel. A member of the Team first needs to authorize it. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@ritesh-1918 please review my PR, thank you |
Summary
Fixes #637
This PR hardens the web frontend and FastAPI backend against XSS, Clickjacking, and MIME-sniffing vulnerabilities by enforcing standard HTTP security headers and restricting CORS to authorized origins only.
Changes
Frontend/vite.config.js— CSP + Security Headers for ViteContent-Security-Policyheader: whitelists self, Supabase (REST/Auth/Realtime), Google Fonts, Gemini API, local backend — blocks everything elseX-Content-Type-Options: nosniffX-Frame-Options: DENY(clickjacking protection)X-XSS-Protection: 1; mode=blockReferrer-Policy: strict-origin-when-cross-originPermissions-Policylocks camera/mic/geolocationStrict-Transport-Securityin preview (production) moderollupOptions.manualChunksfor vendor/ui bundle splittingbackend/middleware/security_headers.py— Helmet-equivalent FastAPI middlewareSecurityHeadersMiddleware(Starlette BaseHTTPMiddleware) injects all headers into every response_parse_allowed_origins()readsALLOWED_ORIGINSenv var (comma-separated), falling back to existing defaultsadd_security_middleware(app)convenience function replaces the inlineCORSMiddlewareblock inmain.py— CORS origins are now environment-drivenGET,POST,PUT,PATCH,DELETE,OPTIONS) instead of wildcardMigration
In
backend/main.py, replace the existing inline CORS block:Set
ALLOWED_ORIGINS=https://helpdeskaiv1.vercel.app,https://staging.helpdesk.aiin your.env.Test Plan
vite devand inspect response headers in browser DevTools — all security headers presentcurl -v /health— all Helmet headers in responseAccess-Control-Allow-Origin)ALLOWED_ORIGINSorigin → CORS headers present