ZBBS-WORK-395: harden the admin mermaid note-render path against XSS#234
Merged
Merged
Conversation
The notes viewer's mermaid path was the one v-html sink fed from semi-trusted data (notes are authored by agents and the dream pipeline's LLM output) whose only sanitization was an implicit third-party default: mermaid 11.x's securityLevel defaulting to 'strict'. No app-level backstop, no CSP — a future 'loose' tweak or a mermaid sanitizer bypass (they have securityLevel-bypass CVEs in their history) would have been live stored XSS. Three coupled changes in notes.js: - Pin securityLevel: 'strict' explicitly so it can't silently regress. - htmlLabels: false (+ flowchart.htmlLabels) — labels render as native SVG <text> instead of foreignObject+XHTML. Verified empirically against the repo's exact dists (mermaid 11.15.0 / dompurify 3.4.8, headless Firefox): with HTML labels on, the SVG sanitize profile destroys every flowchart label, and re-allowing foreignObject still loses its HTML children to DOMPurify's namespace rules. Pure-SVG output sanitizes losslessly (flowchart 124->124, sequence 64->64, adversarial 81->81 elements; payloads survive only as inert escaped label text; DOM scan shows no on* attrs / script / javascript: URLs). - App-level DOMPurify pass (SVG profiles) on mermaid's output before the v-html assignment, mirroring the markdown path's belt-and-suspenders. code_review 1 round: no blocking issues, ship as-is. Pre-existing non-blockers left untouched: the error-fallback <pre> construction and the Date.now() render-id (collision-prone only sub-millisecond). CSP for the admin app remains the ticket's deferred item 3. Frontend-only; no migration. vite build:admin passes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
jeffdafoe
added a commit
that referenced
this pull request
Jun 16, 2026
…234) The notes viewer's mermaid path was the one v-html sink fed from semi-trusted data (notes are authored by agents and the dream pipeline's LLM output) whose only sanitization was an implicit third-party default: mermaid 11.x's securityLevel defaulting to 'strict'. No app-level backstop, no CSP — a future 'loose' tweak or a mermaid sanitizer bypass (they have securityLevel-bypass CVEs in their history) would have been live stored XSS. Three coupled changes in notes.js: - Pin securityLevel: 'strict' explicitly so it can't silently regress. - htmlLabels: false (+ flowchart.htmlLabels) — labels render as native SVG <text> instead of foreignObject+XHTML. Verified empirically against the repo's exact dists (mermaid 11.15.0 / dompurify 3.4.8, headless Firefox): with HTML labels on, the SVG sanitize profile destroys every flowchart label, and re-allowing foreignObject still loses its HTML children to DOMPurify's namespace rules. Pure-SVG output sanitizes losslessly (flowchart 124->124, sequence 64->64, adversarial 81->81 elements; payloads survive only as inert escaped label text; DOM scan shows no on* attrs / script / javascript: URLs). - App-level DOMPurify pass (SVG profiles) on mermaid's output before the v-html assignment, mirroring the markdown path's belt-and-suspenders. code_review 1 round: no blocking issues, ship as-is. Pre-existing non-blockers left untouched: the error-fallback <pre> construction and the Date.now() render-id (collision-prone only sub-millisecond). CSP for the admin app remains the ticket's deferred item 3. Frontend-only; no migration. vite build:admin passes. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.
Why
The notes viewer's mermaid path is the one
v-htmlsink in the admin SPA fed from semi-trusted data (notes come from agents and the dream pipeline's LLM output). Its only sanitization was mermaid's implicitsecurityLevel: 'strict'default — a single point of failure with bypass CVEs in its history, one careless 'loose' tweak away from stored XSS, with no CSP behind it. Full audit inshared/tasks/pending/zbbs-work-395-admin-mermaid-xss-hardening(all other render surfaces verified framework-escaped).What
In notes.js, three coupled changes:
securityLevel: 'strict'so a regression is a visible diff line.htmlLabels: false— labels become native SVG<text>. Required for the next piece: verified against the repo's exact dists in headless Firefox that with HTML labels on, the SVG sanitize profile destroys every flowchart label, and re-allowingforeignObjectstill loses its HTML children to DOMPurify's namespace rules.DOMPurify.sanitize(svg, { USE_PROFILES: { svg: true, svgFilters: true } })before the v-html assignment — belt-and-suspenders matching the markdown path.Verified lossless on flowchart / sequence / adversarial-payload diagrams (zero element loss, labels intact, payloads inert as escaped text, DOM scan clean of on*/script/javascript:).
vite build:adminpasses. Frontend-only, no migration.code_review: 1 round, no blocking issues. CSP for the admin app stays deferred (ticket item 3).
— Work
🤖 Generated with Claude Code