Repository navigation
dsh-mermaid-fence: a third mermaid fence renderer — only worth it for the post-render hardening pass (and here is what that pass cannot do) #7614
XiaoBinGan
started this conversation in
Show Your Plugins!
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
中文摘要:这是第三个 dsh mermaid 围栏渲染插件,但它不比前两个强 ——
AKS1st/dsh-mermaid和timedomain1/dsh-mermaid-renderer功能都更多(懒加载、缩放、全屏查看器、报错回环)。这个包只多做一件事:在 mermaid 渲染完成后对 SVG 再加固一遍。而且这一步不能阻止 mermaid 渲染阶段自己发起的那次请求,下面有实测数据。What this is
dsh-mermaid-fencerenders settled ```mermaid fences as SVG diagrams in the Web GUI chat. MIT, published as a community package under thedsh-plugintopic — the route `CONTRIBUTING.md` names, since external PRs are not accepted.Two plugins already do this and both do more than mine. If you want any of the following, install one of them, not this:
AKS1st/dsh-mermaidtimedomain1/dsh-mermaid-rendererI am not going to pretend a third renderer is news. The one thing this package adds happens after mermaid returns.
The one difference: hardening the SVG after mermaid runs
securityLevel: 'strict'is hardcoded here and not configurable, same as the other two. But strict is not the end of the story: with mermaid 11.17.2 in Chromium, the label<img src=x onerror=alert(1)>comes back from mermaid as<img src="x">— the handler is stripped, the element and its URL are not. Settingflowchart.htmlLabels: falsedoes not change that. So the plugin passes mermaid's SVG through a hardening pass before it reaches the page: removescript/iframe/object/embed/img/image/audio/video/source/track, strip everyon*attribute, and drop anyhref/xlink:href/src/srcset/data/poster/action/formactionthat is not a#fragmentor adata:image/URI. (It also strips the<a xlink:href="https://…">that aclick C "https://…"directive produces under strict, leaving the anchor inert.)Measured with a second origin counting hits — mermaid 11.17.2, the plugin's exact config, label
<img src="http://<attacker>/x.gif">:mermaid.render()<img>elements left in the DOMAnd the honest caveat: hardening runs after
mermaid.render()resolves, and mermaid inserts its markup into the live document while building it — so that request during render is mermaid's own, and this plugin cannot prevent it. What hardening buys is narrower than "no network request": no<img>element survives in the page, and re-inserting the same markup cannot re-fetch. If that is not worth a 3.5 MB inlined bundle to you, that is a reasonable conclusion — use one of the two plugins above. A separate thread in this repo covers mermaid'sstrictbehaviour itself in more depth; this post is only about what the plugin does about it.Install
Not on npm — the public registry 404s for the name, so git only:
client.jsis committed, so no build step runs. Disclosure: I verified the npm git-install form on my machine (six files unpack,client.jsbyte-identical to the repo copy, sha256 match), but I do not have thedshCLI installed, so thedsh pluginline above is the documented route rather than something I ran.Verified, not asserted
node --check client.jsexit 0;npm pack --dry-run= 6 files, ~968 kB packedclient.jsis 3,461,602 bytes (962,140 gzipped) because mermaid is inlined; the README explains why a split chunk cannot resolve for a standalone pluginFeedback welcome — especially from the two plugins above. If the hardening pass is worth borrowing, borrow it; that would be a better outcome than a third plugin existing.
All reactions