-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
feat: add sandboxBaseUrl config to resolve relative URLs in sandbox mode #7203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
… sandbox mode
When securityLevel is 'sandbox', diagrams are rendered inside a data: URI iframe.
Since data URIs have no base URL context, relative URLs in diagram links (e.g.,
"./page.html") cannot be resolved by the browser and fail to navigate.
This change adds a `sandboxBaseUrl` configuration option that, when provided,
pre-resolves all relative URLs in the rendered SVG to absolute URLs before
base64-encoding and embedding in the sandbox iframe.
Changes:
- Add `sandboxBaseUrl` to config schema and TypeScript types
- Create `resolveRelativeUrls` utility in `utils/sandboxUrl.ts`
- Integrate URL resolution into `putIntoIFrame` function
- Add comprehensive unit tests for the URL resolution logic
Example usage:
```javascript
mermaid.initialize({
securityLevel: 'sandbox',
sandboxBaseUrl: 'https://example.com/docs/',
flowchart: { htmlLabels: false }
});
```
Improves performance by eliminating parse/serialize round-trip: - Rename resolveRelativeUrls -> resolveRelativeUrlsInElement - Operate directly on live DOM element instead of parsing SVG string - Call URL resolution before innerHTML extraction in mermaidAPI - Remove sandboxBaseUrl parameter from putIntoIFrame - Update tests to work with DOM elements
|
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@mermaid-js/examples
mermaid
@mermaid-js/layout-elk
@mermaid-js/layout-tidy-tree
@mermaid-js/mermaid-zenuml
@mermaid-js/parser
@mermaid-js/tiny
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7203 +/- ##
==========================================
- Coverage 3.56% 3.56% -0.01%
==========================================
Files 473 475 +2
Lines 47566 47616 +50
Branches 734 735 +1
==========================================
+ Hits 1696 1697 +1
- Misses 45870 45919 +49
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
Replace innerHTML with DOM manipulation (createElement + textContent) to prevent potential XSS attacks flagged by CodeQL.
Add tests for catch blocks when URL resolution fails with invalid base URL.
Prevent sandboxBaseUrl from being set via diagram directives, which could allow attackers to redirect relative links to malicious domains.
📑 Summary
Add
sandboxBaseUrlconfiguration option to enable relative URL resolution in sandbox mode.When
securityLevel: 'sandbox'is used, diagrams render insidedata:URI iframes for security isolation. However, this breaks relative links (./page.html,#section) because data URIs have no base URL context. This PR adds an opt-insandboxBaseUrloption that pre-resolves relative URLs to absolute URLs before embedding.Example:
📏 Design Decisions
Why this approach?
URLs are resolved directly on the live DOM before
innerHTMLextraction, rather than post-processing the serialized SVG string. This:DOMParser/XMLSerializerround-tripsandboxBaseUrlis not setURL handling behavior
./page.html#sectionhttps://...mailto:,javascript:Security
sandboxBaseUrlset by page author, not diagram contentURLconstructor📋 Tasks
Make sure you
MERMAID_RELEASE_VERSIONis used for all new features.pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.