docs: load mermaid from jsdelivr so the CSP allows it#339
Open
smecsia wants to merge 1 commit into
Open
Conversation
Follow-up to the startOnLoad fix (#338): diagrams still didn't render live. The docs site's Content-Security-Policy permits script-src from cdn.jsdelivr.net but NOT unpkg.com, and the mermaid2 plugin defaults to unpkg — so the library load was CSP-blocked and the page showed raw `graph TB ...` text. Point the plugin's `javascript:` at jsdelivr. The .esm bundle lazy-loads its chunks via relative URLs, so they resolve on jsdelivr too (also CSP-allowed). Verified by serving the built site with the production CSP header and rendering headless: the mermaid div now draws an <svg>. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Ilya Sadykov <177390656+universe-ops@users.noreply.github.com>
📊 Statement coverageMeasured on the documented included set (see
Baseline: |
Semgrep Scan ResultsRepository:
Scanned at 2026-06-22 14:46 UTC |
Security Scan ResultsRepository:
Scanned at 2026-06-22 14:47 UTC |
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.
Problem
After #338 (restoring
startOnLoad), mermaid diagrams still didn't render on the live docs (e.g. concepts/main-concepts) — the page showed the rawgraph TB ...source as text.Root cause
The docs site enforces a Content-Security-Policy whose
script-srcallows'self', googletagmanager, andcdn.jsdelivr.net— but notunpkg.com. Themermaid2plugin defaults to loading Mermaid fromunpkg.com, so the browser blocked the import:(My earlier local test missed this because
http.serversends no CSP.)Fix
Set the plugin's
javascript:option to the jsdelivr URL, which the CSP already allows. The.esmbundle lazy-loads its chunks via relative imports, so those resolve on jsdelivr too (also allowed) — whereas from unpkg they'd have been blocked as well.Verification
Built the site and served it with the production CSP header, then rendered headless: no CSP violations in the console, and the
<div class="mermaid">now contains a rendered<svg>(confirmed againstconcepts/main-concepts).🤖 Generated with Claude Code