fix: XSS sanitization, CSP headers, and no-danger ESLint rule [FE-04] - #304
Merged
Leothosine merged 7 commits intoJul 21, 2026
Merged
Conversation
…ization-csp-headers
npm ci was failing because package.json added dompurify and @types/dompurify but package-lock.json was never regenerated.
Leothosine
approved these changes
Jul 21, 2026
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the XSS vector in contact message and menu item rendering by introducing DOMPurify sanitization, adding Content-Security-Policy headers to all responses, and flagging future
dangerouslySetInnerHTMLusage via ESLint.Files Changed
New
frontend/lib/utils/sanitize.ts—sanitize(input)wrappingDOMPurify.sanitizewith a strict allowlist: no<script>, no event handler attributes, nojavascript:ordata:URIs;stripTags(input)for plain-text-only output; safe server-side fallback (strips tags via regex whenwindowis absent)frontend/lib/utils/sanitize.test.ts— 9 unit tests covering plain text,<script>injection, event attributes,javascript:URIs,data:URIs, safe formatting tags, empty string, and nested XSSModified
frontend/package.json— addeddompurify@^3.2.6and@types/dompurify@^3.0.5frontend/next.config.ts— addedheaders()config applying CSP +X-Content-Type-Options,X-Frame-Options,X-XSS-Protection,Referrer-Policy,Permissions-Policyto all routesfrontend/eslint.config.mjs— added"react/no-danger": "error"to flag any newdangerouslySetInnerHTMLusageAcceptance Criteria
<script>alert(1)</script>renders as escaped text, not executable markupContent-Security-Policyheader present on all page responsesreact/no-dangerESLint rule addedcloses #272