Skip to content

fix(security): sanitize HTML sinks + block non-http(s) hrefs (P4.1/P4.2) - #51

Merged
franciszver merged 3 commits into
mainfrom
fix/p4-frontend-xss
Jul 24, 2026
Merged

fix(security): sanitize HTML sinks + block non-http(s) hrefs (P4.1/P4.2)#51
franciszver merged 3 commits into
mainfrom
fix/p4-frontend-xss

Conversation

@franciszver

Copy link
Copy Markdown
Owner

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.

  • Sanitize all 7 dangerouslySetInnerHTML sinks with DOMPurify.sanitize(...): ClauseBrowser, ClauseIntegration, ClauseLibrary, SuggestionsPanel, CitationBrowser, TemplateEditor, DocumentFormatter. (dompurify + @types/dompurify added.)
  • HTML-escape interpolated fields in citationFormatter.ts (escapeHtml helper) — defense in depth before the sanitize layer.
  • safeHref() scheme guard (allowlist http(s):// only) applied to all 3 dynamic <a href> sinks: CitationBrowser, CitationManager, SuggestionsPanel. Rejects javascript:/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 commit 9204b57 (sinks unsanitized, javascript: href unblocked) → green. Covers DOMPurify stripping onerror/<script>, citationFormatter field escaping, safeHref scheme 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-review run via a fresh cold reviewer with no implementation context. First pass flagged 3 missed sinks (TemplateEditor, DocumentFormatter, CitationManager) — all fixed in commit eb44cc7 before this PR, then a full grep sweep confirmed no remaining unsanitized/unguarded sinks. Secret scan clean.

Assisted-by: Claude Code (Fable orchestrator + Sonnet implementer/reviewer)

franciszver and others added 3 commits July 24, 2026 05:45
…ed (#47 #48)

Assisted-by: Claude Code (Sonnet)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
#47 #48)

Assisted-by: Claude Code (Sonnet)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…href (#47 #48)

Assisted-by: Claude Code (Sonnet)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@franciszver
franciszver merged commit b5006c8 into main Jul 24, 2026
2 checks passed
@franciszver
franciszver deleted the fix/p4-frontend-xss branch July 24, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant