Skip to content

build: override Mermaid's KaTeX to 0.18, drop the which dependency - #1199

Merged
juliasilge merged 2 commits into
quarto-dev:mainfrom
nealrichardson:build/katex-override-drop-which
Oct 14, 2026
Merged

juliasilge merged 2 commits into
quarto-dev:mainfrom
nealrichardson:build/katex-override-drop-which

Conversation

@nealrichardson

@nealrichardson nealrichardson commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Two small dependency cleanups.

Changes

  • KaTeX override. Mermaid 11.17.2 depends on katex ^0.16.47, which has GHSA-238p-pmpm-9mq7 (low: prototype pollution elsewhere on the page can turn on KaTeX's trust option). The fix is in 0.18.2, and no 0.16.x release has it. The root package.json now has "overrides": { "mermaid": { "katex": "^0.18.2" } }, which resolves to 0.18.10.
    • Why it's safe: Mermaid 12.2 moved to katex ^0.18.0, and its KaTeX code (renderKatexUnsanitized: dynamic import("katex"), then renderToString with MathML output by default) is identical to 11.17.2's. KaTeX's breaking changes don't apply here. 0.17 changed an internal __defineFunction API, and 0.18 prefixes KaTeX's CSS classes, which only matters for HTML output styled by KaTeX's stylesheet. We use MathML output and don't load that stylesheet.
    • When to remove it: once Mermaid is at 12.2 or later. npm overrides can't carry a comment, so this is recorded here.
    • This is scanner hygiene, not a security fix. It clears the runtime finding from npm audit, Dependabot and Snyk, so it doesn't sit open until Mermaid 12. The one place it changes code is the notebook renderer, where the advisory already couldn't do harm: the renderer shows Mermaid's SVG as an <img> data URL, so links, scripts and external resources in it are inert.
    • Not covered: the diagram preview's checked-in assets/www/diagram/mermaid.min.js is Mermaid's prebuilt bundle with KaTeX 0.16.47 compiled in, so no override or lockfile change reaches it. It's also the more exposed of the two, since diagram.js inserts the SVG with innerHTML (after Mermaid's default strict DOMPurify pass). Fixing it needs Mermaid 12, or bundling Mermaid for the preview ourselves. Scanners don't see that file.
  • Drop which (and @types/which). It was used once, in activePythonInterpreter, to resolve a bare python name from the Python extension against PATH. A small local findOnPath helper now does that, following which@3's rules: PATHEXT on Windows, quoted PATH entries, executable files only. Names with a directory part are left as they are, as before. which 7 needs Node ≥22.22, newer than VS Code 1.101's extension host, so this also removes a reason for a Dependabot ignore (build: add Dependabot for npm dependencies #1198).

Verification

  • package-lock.json diff: only which, @types/which, and katex 0.16.47 → 0.18.10 (with its CLI's commander 8 → 15, which isn't bundled). npm ls --all exits 0.
  • npm audit --omit=dev: 2 low → 0.
  • npm run build -- --force: 9/9. The notebook renderer's out/markdownit/katex-*.js chunk is 0.18.10.
  • npm run lint -- --continue: 17/17, 0 errors, 17 warnings (unchanged). npm run test-packages: 13/13.
  • Headless Chromium, with Mermaid 11.17.2 bundled the way our renderer bundles it (from mermaid.core.mjs, so it uses our KaTeX): a flowchart with $$x^2 + \frac{a}{b}$$ and $$\sqrt{\alpha}$$ labels and a sequence diagram with $$\sum_{i=1}^n i$$ render with <math> elements, no syntax error, and no console errors or warnings.
  • findOnPath gives the same result as command -v for python3, python (absent), node, git and a missing name, on macOS. Not checked on Windows.

🤖 Generated with Claude Code

nealrichardson and others added 2 commits October 14, 2026 17:32
Mermaid 11.17.2 asks for katex ^0.16.47, which has GHSA-238p-pmpm-9mq7
(fixed in 0.18.2). Mermaid 12.2 moved to ^0.18.0 with no change to how
it calls katex, so the override is safe. Drop it once mermaid is >=12.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its only use was resolving a bare Python command name against PATH, which
a small local helper now does. which 7 needs Node >=22.22, newer than our
oldest supported extension host, so this also removes a Dependabot ignore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@posit-snyk-bot

posit-snyk-bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Snyk checks are incomplete.

Status Scan Engine Critical High Medium Low Total (0)
⚠️ Open Source Security 0 0 0 0 See details
⚠️ Licenses 0 0 0 0 See details

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@juliasilge juliasilge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

@juliasilge
juliasilge merged commit 8208645 into quarto-dev:main Oct 14, 2026
6 of 8 checks passed
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.

3 participants