ADR-0042: The least attack surface that does the job#
- Status: accepted. Adds principle 10.
- Date: 2026-12-01
Context#
The site's security rests on what it does not have: no third-party code, one script of its own, one dynamic endpoint, and a Content-Security-Policy of default-src 'none' with narrow grants. Principle 5 protects one part of that, the dependencies, and principle 9 another, the third parties that see visitors. Neither covers the rest of what a change can add: a new kind of file the origin serves, a grant in the CSP or an IAM policy, a workflow permission, an endpoint that accepts input, or the project's own code running in a visitor's browser.
Wanting diagrams on the site showed the gap. The obvious route, a JavaScript diagram renderer, would need the CSP loosened, and nothing written down said how to weigh that against a picture that needs nothing.
Decision#
- **A tenth principle, the least attack surface that does the job.** Of the ways to meet a need, the one that adds least is chosen, even when it is more work. What is added takes its narrowest form, an allowlist rather than a denylist, and a machine checks it. The pull request names the smaller option that was rejected and why it was not enough.
- It does not change the order of precedence. When it conflicts with another principle, the existing order decides.
- The pull request template asks for it.
Alternatives considered#
Widen principle 5 to cover it. Principle 5 is about dependencies and pinning them. Most attack surface is not a dependency, and a file type, a CSP grant or an endpoint would be lost in a principle about pinning.
A list of what is forbidden, such as 'unsafe-inline', new file types or new endpoints. Parts of it are already checked: make pins for workflows, a check block for the CSP. As a whole it would be a denylist, which forbids what was thought of and allows everything else, and it would block a narrow addition as readily as a broad one.
No principle. Each case is argued from scratch, and the quickest route to a feature wins by default.
Consequences#
Positive: a change that adds attack surface says what it adds and which smaller option it rejected, in the pull request, where saying no is cheapest. The pictures decision (ADR-0043) is the first to apply it.
Negative: it costs effort. The option that adds least is often slower to build, such as drawing an SVG by hand instead of writing Mermaid. "Least" is a judgement, options are not always comparable, and the principle itself is enforced by review. Only the mechanisms that implement it are checks.
Neutral: no existing control changes.
Revisit when#
- The project starts accepting user input or holding user data, and attack surface needs a threat model for each endpoint rather than a principle.
- The principle is used to block changes that would have reduced attack surface overall, or is routinely answered with an option nobody wanted.