Repository navigation
feat(markdown): render svg fences as inline SVG (fixes #421) - #455
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 49 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
| // block inside a fence could restyle the app. The reference implementation | ||
| // in #421 leaves <style> in place; this PR removes it. | ||
| const UNSAFE_TAGS = ["script", "foreignObject", "style"]; | ||
| const UNSAFE_HREF = /^\s*(javascript|data:text\/html)/i; |
There was a problem hiding this comment.
🔥 The Roast: The UNSAFE_HREF regex only blocks javascript: and data:text/html. But data:image/svg+xml,<svg><script>alert(1)</script></svg> sails right through. An attacker could embed a <use xlink:href="data:image/svg+xml,..."> or <image href="data:image/svg+xml,..."> and the browser will happily parse and execute the nested SVG's scripts. The sanitizer strips <script> tags inside the current document, but it doesn't stop you from referencing an external (data:) SVG that brings its own party.
🩹 The Fix:
| const UNSAFE_HREF = /^\s*(javascript|data:text\/html)/i; | |
| const UNSAFE_HREF = /^\s*(javascript|vbscript|data:)/i; |
📏 Severity: warning
| el.removeAttribute(attr.name); | ||
| continue; | ||
| } | ||
| if (/^(href|xlink:href)$/i.test(attr.name) && UNSAFE_HREF.test(attr.value)) { |
There was a problem hiding this comment.
🔥 The Roast: The attribute sweep checks href and xlink:href against UNSAFE_HREF, but style attributes get a free pass. An element with style="background: url('javascript:alert(1)')" or the classic IE expression(alert(1)) would survive. Modern browsers mostly neuter CSS-based XSS, but "mostly" is a scary word in security.
🩹 The Fix:
| if (/^(href|xlink:href)$/i.test(attr.name) && UNSAFE_HREF.test(attr.value)) { | |
| if (/^(href|xlink:href|style)$/i.test(attr.name) && (UNSAFE_HREF.test(attr.value) || /expression\s*\(/i.test(attr.value))) { |
📏 Severity: suggestion
| // block inside a fence could restyle the app. The reference implementation | ||
| // in #421 leaves <style> in place; this PR removes it. | ||
| const UNSAFE_TAGS = ["script", "foreignObject", "style"]; | ||
| const UNSAFE_HREF = /^\s*(javascript|data:text\/html)/i; |
There was a problem hiding this comment.
🔥 The Roast: vbscript: is missing from the blocked protocols. It's 2026 and IE is dead, but some embedded WebViews and legacy engines still honor it. Costs nothing to add.
🩹 The Fix:
| const UNSAFE_HREF = /^\s*(javascript|data:text\/html)/i; | |
| const UNSAFE_HREF = /^\s*(javascript|vbscript|data:)/i; |
📏 Severity: nitpick
Code Review Roast 🔥Verdict: No Issues Found | Recommendation: Merge Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything. The previous review's three security holes are all properly patched:
The new test is a proper torture chamber covering every fixed vector, and it even verifies benign styles survive. That's the kind of thoroughness I pretend to have on good days. 📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are. Ship it. Files Reviewed (2 files)
Previous Review Summary (commit 67d4dc9)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 67d4dc9)Verdict: 3 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)
🏆 Best part: The sanitizer correctly sweeps the 💀 Worst part: The 📊 Overall: Solid feature with a security hole the size of a Files Reviewed (3 files)
Reviewed by free · Input: 39.6K · Output: 3.9K · Cached: 127.1K |
|
Hi @anhnt256, thank you for your contribution, and apologies for the long wait on this PR. We really appreciate the time and effort you have put into it. We are working through a major refactor of ompweb, including switching to our own build of omp. We are close to finishing that work; once the refactor is complete, we will turn our attention back to the pending PRs, including this one. Thank you for your patience and for helping improve ompweb! |
* fix(windows): let in-app updates replace an npm-global install Port of ompweb-dev/ompweb#519. * fix(windows): stop a failed host candidate that got the old daemon's pid Port of ompweb-dev/ompweb#526. * fix(outbox): prune delivered rows inside the add's write transaction Port of ompweb-dev/ompweb#535. * fix(windows): find the host's scheduled task without administrator rights Port of ompweb-dev/ompweb#539. * fix(updates): build the tray at release and resume host update downloads Port of ompweb-dev/ompweb#532. The committed bin/tau-tray.exe was still the omp-web build; releases now build it from native/tray. The omp runner download resume does not apply: tau has no runner download. * fix(hosts): report pi to the server once it answers after the daemon started Port of ompweb-dev/ompweb#542. A daemon whose startup read found no pi reads the version again (30 s, doubling to 5 min) and sends a pi_version link message, so a host that gets pi after its daemon started comes online without a restart. The runner download retry does not apply: tau has no runner download. * docs(agents): note the pi_version link message * fix(chat): count only completed subagents in the subagents header Port of ompweb-dev/ompweb#440. * feat(chat): render svg code fences inline Port of ompweb-dev/ompweb#455. * fix(sidebar): mark a completed session seen once it is opened Port of ompweb-dev/ompweb#336. * fix(i18n): add the zh-TW completed-subagents summary Port of ompweb-dev/ompweb#545. * perf(sessions): strip unused assistant fields from the session response Port of ompweb-dev/ompweb#454. * feat(api): app-info handshake and a per-connection heartbeat Port of ompweb-dev/ompweb#407. * feat(directory-picker): add a Browse… button that opens the OS folder dialog Port of ompweb-dev/ompweb#544. * feat(sessions): navigation-only reads, context ETag and a prompt-less state Port of ompweb-dev/ompweb#415. A rename now falls back to pi's session_info entry only when pi refused it or the child is gone. * feat(notifications): answer a pending dialog from the notification Port of ompweb-dev/ompweb#414, without omp's formDialog and session-move aliases. * perf(events): hold tool snapshots to one frame per second Port of ompweb-dev/ompweb#418. * fix(ui): prevent file-panel tabs from clipping on overflow Port of ompweb-dev/ompweb#547. * fix(projects): keep a re-added workspace's display data and avoid worktree path collisions Port of ompweb-dev/ompweb#554 (rework of ompweb-dev/ompweb#297). * feat(composer): fullscreen edit mode and one-line collapse for long sent messages Port of ompweb-dev/ompweb#556. * docs(changelog): note the ports from ompweb * chore: use tau names in the ported update and tray code * fix(markdown): sanitize svg fences with an element allowlist A tab inside the scheme (java	script:), a prefixed xlink href, <set>/<animate> retargeting an href, and CDATA or processing instructions re-parsed as HTML on insertion all got past the blocklist sanitizer. * fix(directory-picker): offer the folder dialog only to a page on this machine Behind a reverse proxy on this machine every connection is loopback, so the page's own Origin (or same-origin Referer) must be loopback too. The picker can be closed while a dialog is pending, and the zenity check runs once. * fix(composer): queue or steer from the full-screen editor during a run Send and Ctrl+Enter called handleSend, which ignores a message while a run streams, so the editor closed and nothing was sent. * fix(notifications): keep a shared child's dialogs announceable after this server leaves it Leaving a host-owned child that keeps running retracted its pending dialogs permanently, so the next holder could not announce a question that was still waiting. They are now forgotten (a temporary retraction), as after a resync. * docs(notifications): drop omp-only dialog kinds from the ported comments * fix(dialogs): answer pi's dialogs under their own ids and show the ask tool's questions The wrapper still accepted only omp's numeric dialog ids, so every answer to a pi dialog (UUID ids) failed with invalid_ui_response, from the web dialog and from a notification. The ask tool's payload ({questions: [{question, options: string[], multiSelect}]}) reached the dialog unconverted, which expects a question list with option objects; RpcProcess now converts it. * fix(tray): read tau's settings and logs from ~/.pi/agent The native tray still read ~/.omp/agent/web-service.json and its logs, so it ignored the saved port, hostname and mode. Releases now build this source (scripts/build-tray.sh). * fix(hosts): never build the local link URL from an unbracketed IPv6 address * test(notifications): name the registry-key answer test for what it checks * test(hosts): give the fake children pi's string dialog ids * fix(dialogs): keep host tool calls out of dialog answers, and settle a dead child's dialogs for good A ui_response naming a pending host tool call is refused, so its bookkeeping sees the real host_tool_result. Dialogs are only forgotten when this server leaves a shared child that is still alive. The ask tool's questions get distinct ids, and pageIsLoopback sits above handle's doc comment. * fix(events): stop releasing held tool snapshots once the sink falls behind * fix(composer): paste images and leave IME keys alone in the full-screen editor * fix(directory-picker): require Origin on a non-GET, and read the Windows chooser's path as UTF-8 * fix(worktrees): report an occupied fallback worktree directory as worktree_directory_exists * fix(notifications): keep pushes within 3993 bytes, refuse expired dialogs and settled replays * fix(updates): release only the stopped server's own processes and recheck each pid before stopping it * docs(notifications): name the /api/events notifications channel * fix(updates): release every install locker after the server stops again Scoping that release to the stopped trees missed their children on Linux and macOS, where a dead parent's children are re-parented, so the leftover check refused the update. * fix(notifications): keep the question in a push that drops its dialog, and close expired dialogs in open tabs * fix(updates): skip a locker whose re-listing fails; document the notifications subscribe body * fix(updates): fail the install cleanup when a re-listing fails Skipping the locker let rollback take an unfinished cleanup as done and restore the installation while a runtime still ran from it. * fix(notifications): do not carry a request id past the dialog id limit pi's ids are UUIDs; an oversized one could take the push past 3993 bytes on its own.
Fixes #421.
Observable behavior changed: a ```svg fence rendered as a plain code block (line numbers, an svg chip, only a Copy action), even though omp/omp CLI sessions emit exactly those fences expecting an inline picture. The fence now renders inline, next to the existing mermaid branch.
Change: components/MarkdownCode.tsx dispatches lang === "svg" to a new SvgBlock (components/SvgBlock.tsx), which parses with DOMParser, falls back to CodeBlock on malformed or still-streaming markup, sanitizes (strips script/foreignObject/style, on* attributes, javascript:/data:text/html hrefs), and renders inside a wrapper defining the omp theme-variable aliases (--fg/--muted/--surface/--c1..--c6) the web theme lacks, so omp-style fills stay visible on dark themes.
Two deliberate deviations from the reference implementation attached to the issue: (1) <style> elements are stripped too — inline SVG CSS applies to the whole document, so a style block inside a fence could restyle the app; (2) the attribute sweep covers the root itself — the reference's querySelectorAll("") misses on handlers on the root (caught by test).
Tests: new components/SvgBlock.test.mjs (7 tests: valid-svg normalization, sanitizer strip cases, explicit-fill preservation, malformed/non-svg fallback, inline render with theme aliases, renderer dispatch). All pass; MarkdownBody + MermaidBlock suites still 27/27 pass. npm run typecheck passes; scoped eslint on all three files is clean.
Not verified visually: inline rendering in a live session needs a running app with an omp backend. The reporter's verification table on a locally patched 0.6.0 (valid fence renders, theme vars resolve, script/onload/foreignObject/javascript: removed, malformed falls back, mermaid/json unchanged) is quoted from the issue as supporting evidence.