feat: standardize security headers and env-configurable CORS (#637)#668
feat: standardize security headers and env-configurable CORS (#637)#668lb1192176991-lab wants to merge 1 commit into
Conversation
|
@lb1192176991-lab is attempting to deploy a commit to the ritesh Team on Vercel. A member of the Team first needs to authorize it. |
|
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7cceee886d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| <link rel="icon" type="image/png" href="/favicon.png" /> | ||
|
|
||
| <!-- Security Headers (Content Security Policy) --> | ||
| <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https:; connect-src 'self' https://helpdeskaiv1.vercel.app https://*.supabase.co wss://*.supabase.co; frame-ancestors 'none'; form-action 'self'; base-uri 'self'" /> |
There was a problem hiding this comment.
Allow the actual backend origins in CSP
With the default frontend config, production API calls go to https://ritesh19180-ai-helpdesk-api.hf.space and local development goes to http://localhost:8000 (Frontend/src/config.js), but this new connect-src only allows the frontend origin and Supabase. In those default production/local environments the browser will block every fetch/axios request before CORS is reached, making auth and ticket APIs unusable unless the CSP also includes the configured backend origin(s).
Useful? React with 👍 / 👎.
What
Adds comprehensive HTTP security headers and makes CORS origins configurable via environment variable.
Backend (FastAPI)
_SecurityHeadersMiddlewarethat sets:X-Content-Type-Options: nosniff,X-Frame-Options: DENY,X-XSS-Protection: 1; mode=block,Strict-Transport-Security: max-age=31536000; includeSubDomains,Referrer-Policy: strict-origin-when-cross-origin,Permissions-Policy: camera=(), microphone=(), geolocation=()allow_originsconfigurable viaALLOWED_ORIGINSenv variable (comma-separated), falling back to the existing hardcoded defaultsFrontend (Vite)
X-Content-Type-Options,X-Frame-Options, andReferrer-Policyhttp-equiv meta tags for environments where server-side headers are not setWhy
Without these protections, the application is vulnerable to:
Testing