fix: patch XSS vulnerability in input fields (OWASP A03 - Injection)#1319
fix: patch XSS vulnerability in input fields (OWASP A03 - Injection)#1319IshitaSingh0822 wants to merge 1 commit into
Conversation
- Add src/lib/sanitize.ts with stripHtml and validateTextInput helpers - Sanitize goal label on both frontend (GoalTracker) and backend (goals API) - Strip HTML tags from all text inputs before storing to DB - Add CSP, X-Frame-Options, X-Content-Type-Options headers in next.config.mjs
|
@IshitaSingh0822 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):
|
|
Thanks for the XSS sanitization work @IshitaSingh0822! The Problems that need fixing:
What to keep:
Please scope the PR to only: (1) add |
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
This PR has 4 merge conflicts with current main. The XSS sanitization approach also needs discussion — blanket DOMPurify sanitization on all inputs can break legitimate use cases. Please rebase and scope the fix more narrowly (only apply sanitization at render/output points, not at input change handlers).
|
Your PR has conflicts with the current |
Summary
Patches a critical XSS vulnerability (OWASP A03: Injection) across DevTrack's input fields. User-supplied text was being stored and rendered without sanitization, allowing script injection via fields like the goal label. This fix adds a shared sanitization utility, backend validation, frontend defence-in-depth, and CSP headers.
Closes #1316
Type of Change
Changes Made
src/lib/sanitize.ts— sharedstripHtml()andvalidateTextInput()helpers that work in both Node and browsersrc/app/api/goals/route.ts— validates and strips HTML fromlabelbefore writing to DB; returns400if input is empty or contains tagssrc/components/GoalTracker.tsx— callsstripHtml()before sending to API and again when renderinggoal.labelfrom DBnext.config.mjs— added CSP, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, and Permissions-Policy headers on all routesHow to Test
npm run dev<script>alert(1)</script>in the goal label field and submit — no alert should fire<img src=x onerror=alert('XSS')>in the same field — same result expectedcurl -I http://localhost:3000and confirm CSP headers are present in the responseScreenshots (if UI change)
N/A — no visual changes, security fix only.
Checklist
npm run lintpasses locallynpm run type-check)