Repository navigation
Mermaid: harden version pin (single home, floating-version warning, canary) - #2711
Merged
chalin merged 14 commits intoAug 9, 2026
Merged
Conversation
…anary) - **Single home for the version**: moves the pin to `theme/hugo.yaml` `params.mermaid.version`; the partial and diagrams doc page both render it live, killing the 4-copy hand-sync - **Fail-closed on missing config**: an unset `params.mermaid.version` now `errorf`s instead of silently falling back to a duplicated default - **`warnidf` on floating versions**: a non-`X.Y.Z` version (e.g. `latest`) emits a suppressible `mermaid-floating-version` warning - **Exact-version canary test**: `tests/mermaid-version.test.mjs` fails the build if the pin regresses to a floating version; wired into `ci:post` - **Maintainer notes**: bump note shrinks to the one yaml line; documents the emergency security-bump path (manual edit, bypasses the future Renovate age gate, ships via the patch-release flow) Follow-up to docsy#2704.
- Changelog entry shrinks to a ToC-style pointer instead of restating the errorf/warnidf/canary mechanism, which already lives at maintainer-notes.md § Default Mermaid version - Adds a `test:mermaid-version` row to the Test suites table (previously undocumented) and cross-links it from § Default Mermaid version, matching the § Hugo versions pattern
Adds an evergreen line to the bump procedure (npm registry + OSV lookup) rather than a version-specific comment in theme/hugo.yaml that would go stale on the next bump.
- Guards mermaid.html so an unset-version errorf short-circuits the rest of the partial instead of falling through to build a garbled CDN URL and trigger a second, confusing GetRemote error - Coerces params.mermaid.version to a trimmed string right after the unset-check, so a YAML-typed value (bool, float) stringifies sanely (`true`, `11.16`) instead of leaking Go's `%!s(bool=true)`-style fmt verbs into the CDN URL, and a trailing-whitespace typo doesn't break the URL either - Tightens tests/mermaid-version.test.mjs's regex: scopes the version match inside the params: block (a decoy top-level mermaid: key could otherwise mask a floating params.mermaid.version and pass the canary) and strips optional quotes (a quoted "11.16.1" previously failed the semver check) - Swaps the maintainer-notes npm link from the bot-walled npmjs.com/package page (docsy.dev's own lychee.toml already excludes this URL pattern) to the machine-readable registry.npmjs.org/mermaid API - Softens the maintainer-notes Renovate-gate wording so it can't be misread as describing an already-active mechanism (no renovate.json exists yet) - Makes the diagrams page's ignoreLogs suppression mention format-neutral instead of YAML-only Found by an independent adversarial review (Grok 4.5, high effort); full report kept locally, not part of this commit.
- The CDN existence check (`with try (resources.GetRemote)`) only checked `.Err`, never `.Value`. A 404 (a version that doesn't exist on the CDN) returns Err=nil with an empty Value; Go's template `with` treats the returned struct as always-truthy regardless of its fields, so neither error branch ever fired and a broken script tag shipped silently (reproduced with 99.99.99: built green before, hard-fails after). Fixed by mirroring katex.html's three-way `with .Err / else with .Value / else` chain, which already handles this correctly. - Restructures the partial around a positive top-level version check (`if $version`): the main logic reads first and an unset version's errorf no longer falls through to build a garbled CDN URL.
- Two adversarial rounds each produced decoy key shapes that fooled the regex extraction while Hugo resolved a different value (latest round: a nested `params.ui.mermaid.version` above the real key); parsing closes the class instead of the instance, and also accepts every legitimate YAML shape the regex mis-rejected (quoted scalars, comments between keys, inline maps, CRLF) -- verified against a 9-case matrix - Declares `yaml` as a devDependency: it was already in the lockfile as a transitive dev dep at the same version, so node_modules content is unchanged - Qualifies the mermaid.html CDN-check comment: GetRemote results are cached (default maxAge -1), so the existence check runs on a cold cache, not every build
- De-duplicates the floating-version rationale: the warnidf message now points at the diagrams page (the rationale's home) instead of restating it, following dark-mode-config.html's message-plus-docs-URL idiom -- this PR kills a 4-copy hand-sync, so it shouldn't add a 2-copy one - Prose tightening: diagrams-page suppression sentence, maintainer-notes emergency-bump tail, test header comment, changelog cross-reference phrasing, dash constructs in the partial comment and the fixture-site test-suites table row
Also reverts the changelog cross-ref to the file's short "See [X][]" idiom.
- A reintroduced template-level `default` fallback or a hardcoded `mermaid@<version>` CDN URL in the partial would ship a version the YAML assertion never sees; a second test now pins the partial to reading params.mermaid.version and interpolating it (`mermaid@%s`), proven red-first against both regression shapes - Notes in the maintainer docs that the partial's unset/floating guards are layout-conditional until the scripts-caching fix lands (previously stated only in the PR body, which isn't a durable home) - Comments the deliberate rejection of prerelease pins for the theme default, so future reviews don't re-litigate it
Round-6 follow-up: a post-read reassignment of $version to a literal would evade the canary's source assertions (they pin the read and the URL interpolation, not the middle); a structural guard isn't regex-tractable, so the comment carries the intent at the edit site.
Hoists the string coercion + trim to the read line (the round-4 agreement was "convert to string first"; it sat inside the if-branch only to dodge printf's nil rendering, now handled by nil-normalizing with `or ... ""`). Whitespace-only versions get the clean unset-or-empty error instead of a confusing double-error path, and non-string values (bool, float) flow through the same normalized checks -- a bool now correctly hard-fails at the CDN existence check rather than warn-only. The canary's read-shape assertion went red on the reshape and was updated with it.
Hugo's cast.ToString alias handles nil natively (empty string), so the `or ... ""` nil-guard the printf form needed goes away; behavior matrix (unset, whitespace-only, bool, trailing-space, happy) verified identical. Also names the canary test file in the read-pinning comment.
…eview) - Round 6's re-review found the read-pin regex relaxation (made for the TrimSpace wrapper) re-admitted `default` as a function call -- the exact false-clean the assertion exists to kill, resurrected via call syntax. The read now uses the repo's pipe idiom (`.Site.Params.mermaid.version | string | strings.TrimSpace`), putting the param first in the pipeline so the canary anchors on the expression front; nothing can wrap the read without going red. Negative assertion tightened to catch both pipe- and call-form `default` (argument-shaped, so the partial's own comment stays out of scope). All three injection shapes (pipe, call wrapping the read, trailing pipe) proven red-first.
chalin
force-pushed
the
chalin-m24-mermaid-hardening-2026-0809
branch
from
August 9, 2026 22:14
4765a7d to
1b70b78
Compare
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.
@latest#2703theme/hugo.yamlparams.mermaid.version; the partial and diagrams doc page both render it live, killing the 4-copy hand-syncparams.mermaid.versionnowerrorfs instead of silently falling back to a duplicated defaultwarnidfon floating versions: a non-X.Y.Zversion (e.g.latest) emits a suppressiblemermaid-floating-versionwarningtests/mermaid-version.test.mjsfails the build if the pin regresses to a floating version, in the config or the partial; wired intotest:fullbaseof.htmlrendersscripts.htmlthrough an unkeyedpartialCached, which can skip the Mermaid partial for pages on that layout; theerrorf/warnidfguards above are therefore only guaranteed on the docs, blog, and swagger layouts for now. That caching behavior predates this PR and will be addressed separately.Follow-up to #2704.