fix(security): sanitize HTML sinks + block non-http(s) hrefs (P4.1/P4.2) - #51
Merged
Conversation
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.
Closes #47
Closes #48
Summary
Fixes the stored-XSS → account-takeover chain (P4.1) and
javascript:URL execution (P4.2) surfaced by the Phase-4 security review.dangerouslySetInnerHTMLsinks withDOMPurify.sanitize(...): ClauseBrowser, ClauseIntegration, ClauseLibrary, SuggestionsPanel, CitationBrowser, TemplateEditor, DocumentFormatter. (dompurify+@types/dompurifyadded.)citationFormatter.ts(escapeHtmlhelper) — defense in depth before the sanitize layer.safeHref()scheme guard (allowlisthttp(s)://only) applied to all 3 dynamic<a href>sinks: CitationBrowser, CitationManager, SuggestionsPanel. Rejectsjavascript:/data:/obfuscated schemes.Shared libraries remain user-editable per owner decision D18; the defense is render-side sanitization, not write restriction.
Red-first / tests
src/test/security-xss.test.tsx— red commit9204b57(sinks unsanitized,javascript:href unblocked) → green. Covers DOMPurify strippingonerror/<script>, citationFormatter field escaping,safeHrefscheme rejection, and the TemplateEditor/DocumentFormatter preview sinks.Verification
npm test -- --run: 536 passed (525 baseline + 11 new).npm run build: clean (tsc -b && vite build, no type errors).Gates
/simplify+/security-review+/code-reviewrun via a fresh cold reviewer with no implementation context. First pass flagged 3 missed sinks (TemplateEditor, DocumentFormatter, CitationManager) — all fixed in commiteb44cc7before this PR, then a fullgrepsweep confirmed no remaining unsanitized/unguarded sinks. Secret scan clean.Assisted-by: Claude Code (Fable orchestrator + Sonnet implementer/reviewer)