Skip to content

fix(editor): render Mermaid HTML labels without stripping foreignObject - #12581

Closed
bbingz wants to merge 2 commits into
stablyai:mainfrom
bbingz:fix/12414-mermaid-html-labels
Closed

bbingz wants to merge 2 commits into
stablyai:mainfrom
bbingz:fix/12414-mermaid-html-labels

Conversation

@bbingz

@bbingz bbingz commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve Mermaid HTML labels during Orca's final SVG cleanup. The sanitizer now retains foreignObject and its XHTML label contents using Mermaid's own DOMPurify integration-point options. HTML labels are enabled by default, and preview, editor and comment call sites no longer force them off. Mermaid's strict security mode remains enabled.

This restores formatted labels such as bold text, italics and line breaks while the final cleanup still removes scripts, event-handler attributes and JavaScript URLs. Related: #12414.

Validation

At e7ec906cd1120ae1543a8ce40abd1e33b79ec1dd:

  • All 7 tests passed across configuration, sanitizer and Chromium suites, with no skips. The independent worktree selected installed Chrome via channel: 'chrome' in the two launch calls; the committed assertions were unchanged.
  • A separate real-Chrome render imported the actual sanitizer, Mermaid configuration and Mermaid package. Bold/italic node labels remained visible with nonzero dimensions; hostile SVG lost scripts and event handlers, and the test payload did not execute. Screenshot inspected.
  • CLI, Node and Web TypeScript (--composite false), changed-file lint, formatting and diff whitespace checks passed. Independent Cursor review passed after inspecting the Chromium evidence.

The default Chromium test launch still skips when its Playwright browser is unavailable. Happy-dom alone is not treated as the security verifier. Full repository tests, packaged builds and rendered checks of every Orca embedding surface were not run; the browser proof covers the actual rendering/sanitizer pipeline rather than a complete Electron session.

AI disclosure

Cursor ported and reviewed this change. Codex independently ran the existing assertions in Chrome, inspected a rendered proof and checked the source and validation results before updating the PR.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0c8171fb-817a-440a-b665-475dd4b47d91

📥 Commits

Reviewing files that changed from the base of the PR and between e7ec906cd1120ae1543a8ce40abd1e33b79ec1dd and cb46b23.

📒 Files selected for processing (1)
  • src/renderer/src/components/editor/mermaid-sanitize.chromium.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

Mermaid rendering now enables HTML labels by default. Rendered SVG uses a shared Mermaid-compatible DOMPurify configuration that preserves safe foreignObject XHTML formatting and removes unsafe content. Mermaid preview call sites use the default behavior. Configuration tests and browser-based regression tests cover label preservation and sanitization of scripts, event handlers, and javascript: URLs.

Priority: ➖ Normal

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation and validation, but it omits most required template sections. It lacks the required ELI5, What Changed, Why, Visual Proof, Review, Agent skill upstream boun… Complete the repository template. Add the required section headings and content, use the required linked-issue format such as “Fixes #12414” or provide the required issue link, attach before-and-after visual proof or state N/A with a reason…
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving Mermaid HTML labels without stripping foreignObject content.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the implementation and validation, but it omits most required template sections. It lacks the required ELI5, What Changed, Why, Visual Proof, Review, Agent skill upstream boundary, Notes, and Checklist sections. It also provides only “Related: #12414” instead of the required linked-issue format and does not provide the required visual attachment or N/A statement.

Resolution

Complete the repository template. Add the required section headings and content, use the required linked-issue format such as “Fixes #12414” or provide the required issue link, attach before-and-after visual proof or state N/A with a reason, complete the Testing and Checklist items, and address the Review, Agent skill upstream boundary, and Notes sections.

  • Fix all pre-merge checks with AI

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d2449154-7a14-4d46-afb5-706caa5144a8

📥 Commits

Reviewing files that changed from the base of the PR and between 9ee3595 and ade522b573e99d1535f3f97638b5e3134037ec6c.

📒 Files selected for processing (10)
  • src/renderer/src/components/editor/MarkdownPreview.tsx
  • src/renderer/src/components/editor/MermaidBlock.tsx
  • src/renderer/src/components/editor/MermaidViewer.tsx
  • src/renderer/src/components/editor/RichMarkdownCodeBlock.tsx
  • src/renderer/src/components/editor/mermaid-config.test.ts
  • src/renderer/src/components/editor/mermaid-config.ts
  • src/renderer/src/components/editor/mermaid-sanitize.chromium.test.ts
  • src/renderer/src/components/editor/mermaid-sanitize.test.ts
  • src/renderer/src/components/editor/mermaid-sanitize.ts
  • src/renderer/src/components/sidebar/CommentMermaidBlock.tsx

@bbingz
bbingz force-pushed the fix/12414-mermaid-html-labels branch from ade522b to d6b019f Compare August 5, 2026 00:34
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

bbingz and others added 2 commits September 20, 2026 19:04
Enable htmlLabels by default under securityLevel strict, and sanitize
rendered SVG with Mermaid's own DOMPurify options (including
HTML_INTEGRATION_POINTS.foreignobject) so formatting tags survive while
scripts and javascript: URLs are still stripped. Adds happy-dom and
Chromium regression coverage for the label/XSS contract (stablyai#12414).

Co-authored-by: Cursor <[email protected]>
@bbingz
bbingz force-pushed the fix/12414-mermaid-html-labels branch from e7ec906 to cb46b23 Compare September 20, 2026 11:06
nwparker added a commit that referenced this pull request Oct 5, 2026
Keep explicit SVG, HTML, and MathML profiles so formatted and math labels render while filter primitives retain the previous restriction. Extend the adopted bbingz #12581 Chromium coverage for embedded documents, encoded handlers and URLs, namespace transitions, and browser reparsing.
nwparker added a commit that referenced this pull request Oct 5, 2026
Keep explicit SVG, HTML, and MathML profiles so formatted and math labels render while filter primitives retain the previous restriction. Extend the adopted bbingz #12581 Chromium coverage for embedded documents, encoded handlers and URLs, namespace transitions, and browser reparsing.
@nwparker

Copy link
Copy Markdown
Contributor

Thanks! #25554 takes the same approach to #12414 (HTML labels under strict security) and is being rebased onto current main. Closing in favor of that one to keep one review thread.

@nwparker nwparker closed this Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants