fix(security): Harden Content-Security-Policy header — add base-uri, object-src, Supabase connect-src#2159
Conversation
- Add base-uri 'none' to block <base> tag injection attacks - Add object-src 'none' to disable Flash/plugin XSS vectors - Add upgrade-insecure-requests for automatic HTTP→HTTPS sub-resource upgrade - Expand connect-src to include Supabase (*.supabase.co, wss://*.supabase.co) and Upstash Redis (*.upstash.io) so authenticated API calls are not blocked - Add worker-src blob: for next-pwa service worker compatibility - Add blob: to img-src for canvas-generated image exports - Restructure as an array joined with '; ' for improved readability Closes Priyanshu-byte-coder#2148
|
@gowthamrdyy is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the app’s Content Security Policy (CSP) configuration in next.config.mjs to be more explicit, add protections against common injection vectors, and allow required external connections (Supabase/Upstash).
Changes:
- Refactors CSP header from a single string into a directive array joined by
;for readability/maintainability. - Adds additional CSP directives (
base-uri,object-src,upgrade-insecure-requests,worker-src) and expandsimg-src/connect-srcallowlists.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| value: [ | ||
| "default-src 'self'", | ||
| "script-src 'self' 'unsafe-eval' 'unsafe-inline'", | ||
| "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com", | ||
| "font-src 'self' https://fonts.gstatic.com", | ||
| "img-src 'self' data: blob: https://avatars.githubusercontent.com https://github.githubassets.com", | ||
| "connect-src 'self' https://api.github.com https://groq.com https://api.groq.com https://*.supabase.co wss://*.supabase.co https://*.upstash.io", | ||
| "frame-ancestors 'none'", | ||
| "base-uri 'none'", | ||
| "object-src 'none'", | ||
| "upgrade-insecure-requests", | ||
| "worker-src blob:", | ||
| ].join("; "), |
| "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com", | ||
| "font-src 'self' https://fonts.gstatic.com", | ||
| "img-src 'self' data: blob: https://avatars.githubusercontent.com https://github.githubassets.com", | ||
| "connect-src 'self' https://api.github.com https://groq.com https://api.groq.com https://*.supabase.co wss://*.supabase.co https://*.upstash.io", |
| "frame-ancestors 'none'", | ||
| "base-uri 'none'", | ||
| "object-src 'none'", | ||
| "upgrade-insecure-requests", |
Summary
Closes #2148
This PR hardens the existing
Content-Security-Policy(CSP) header innext.config.mjsby closing several attack vectors that the current policy left open.Changes
base-uri'none'<base>tag injection — an attacker-controlled<base href>can redirect all relative URLs (scripts, links) to a malicious domainobject-src'none'upgrade-insecure-requestsconnect-srcapi.github.com,groq.com*.supabase.co,wss://*.supabase.co,*.upstash.ioimg-srcdata:blob:blob:object URLsworker-srcblob:next-pwaservice worker registration'; 'Testing
pnpm run type-check)pnpm run lint)GSSoc'26