ADR-0043: Pictures are static files the build checks, not scripts#

  • Status: accepted. Applies principle 10 (ADR-0042), and answers ADR-0007's question about diagram rendering without a dependency.
  • Date: 2026-12-01

Context#

The docs had three Mermaid diagrams. GitHub rendered them; the site showed their source, because rendering Mermaid takes a JavaScript library of over a megabyte, which would be the largest code the site runs and the first that is not its own. The owner wants diagrams and pictures on the site.

The site already allows images from its own origin. The CSP grants img-src 'self', and the Markdown renderer writes <img>. A browser draws an image, SVG included, without running script or fetching anything else. Two risks remain. An SVG opened on its own is a document in the site's origin, where any script in it would run if the CSP allowed it. And an exported picture can carry what its author did not mean to publish: an editor's user name and file paths, a camera's location, or an account ID in a screenshot.

Decision#

  1. A picture is a file in docs/images/, referenced with Markdown image syntax and alt text, served from the site's origin and drawn by <img>. GitHub renders the same reference. Diagrams are SVG, drawn by hand; other pictures are PNG.
  2. The build refuses any picture outside an allowlist (site/images.py). An SVG may hold only shape and text elements with presentation attributes: no script, event handler, style, foreignObject, link, embedded image, use, animation, editor metadata, DOCTYPE, entity or processing instruction, and no reference except url(#id). A PNG may hold only the chunks that draw it, with nothing after its end. Each is at most 256 KiB, and its content must match its suffix, which sets the type it is served with. Other formats are refused until a picture needs one.
  3. The build also refuses a picture from another site, a picture no page uses, and a Mermaid block on a published page. The three diagrams are redrawn as SVG, and the renderer's Mermaid case is removed.
  4. The CSP does not change.

Alternatives considered#

Mermaid in the browser, vendored. It inserts the diagram as markup through innerHTML, which Trusted Types refuses, and styles it with an inline <style>, which style-src 'self' refuses. Both would have to be weakened, for the largest third-party code the site would run.

Mermaid at build time (mermaid-cli). It puts Node, an npm dependency tree and a headless Chromium into a build that has no dependencies. Its SVG carries <style> and, by default, foreignObject, so it would fail this check anyway.

A rendering service, such as Kroki or mermaid.ink. A third party sees every diagram, or every visitor (principle 9).

Graphviz, pinned in tools.lock. Small, mature and checksum-pinnable, so the best of the generators. It would still put a C parser into a build that has none, and GitHub does not render DOT, so the SVG would be committed anyway. It is the answer if drawing by hand becomes the bottleneck.

SVG inline in the Markdown. It could follow the page's colours, but GitHub strips it, and every page would carry markup that no check reads.

Text diagrams in code blocks. They add nothing and are already allowed, but they are not pictures, and they read poorly with a screen reader.

Consequences#

Positive: diagrams render on the site and on GitHub alike, with no change to the CSP and no dependency. What a picture may contain is an allowlist a machine enforces, so a script or metadata in an exported file fails the build instead of shipping. The renderer loses its Mermaid case.

Negative: an SVG drawn by hand is slower to change than Mermaid, and its layout is manual. A diagram keeps its own light background in dark mode, because an image cannot read the page's stylesheet and the check refuses <style>. Nothing checks what a picture shows: make secrets reads an SVG's text but not a PNG's pixels, so a screenshot must be read by eye for account IDs (ADR-0011). Diagrams can still go stale.

Neutral: an SVG exported from a drawing tool usually needs cleaning before it passes.

Revisit when#

  • Keeping the diagrams up to date by hand costs more than a pinned Graphviz would. Its output would pass through the same allowlist.
  • A picture needs another format, such as JPEG for a photograph. It comes with a check of the same kind: no EXIF, XMP or comment segments.

Built 2026-12-01 from commit 5f3eb2c4b04f9d8367364b6f4598a05a364e2263. This page was generated from the same source that provisions the infrastructure it describes.