ADR-0133 — A gated document is stored where the ungated mount does not answer
Status: Accepted · Date: 2026-08-30 · Track: 010 phase 05
Context
ADR-0132 shut the bundle half of /uploads/*: an expansion has an address of
its own behind the resource's gate, so the mount refuses bundles/ outright.
The document half stayed open, and it was the harder one.
A file link's document and a static page's HTML, Markdown, SVG or archive are
gated — by the password and sensitive-content interstitials (007), the display
rules, the schedule, the click limit and 009's lifecycle predicate. A genuinely
ungated upload — an avatar, an image an author dropped into the editor — is not
gated by anything and has no other address. Both were written by SaveFile to
<date>/<random>.<ext>. They were minted alike, so the mount could serve a
document to a visitor the gate had just refused, and no test at the mount could
have known.
Nothing about the request distinguishes them. Two requests for two files written the same way by the same function are the same request. What distinguishes them is the purpose of the write, and that is known at write time and nowhere else.
Decision
The write records the purpose by choosing where the bytes go, and the mount reads that back.
services.DocumentPrefixRoot (documents) is a constant of the product's, in
the same shape and for the same reason as BundlePrefixRoot. SaveDocument is
SaveFile under that root, on both backends, so a deployment's stored paths
mean the same thing whichever holds them. The four call sites that store a
document a resource gates — file link create and update, static page create and
update — take it; the generic upload handler keeps SaveFile, because what it
writes is meant to be reachable there.
GuardUngatedUploads refuses both roots. The list is []string{BundlePrefixRoot, DocumentPrefixRoot} — the constants themselves, asserted against the constants
in a test, so a root added to the storage layer and not here is a build failure
rather than a second address. The comparison still runs on the cleaned path,
which is what a file server opens.
Rejected: a path→row lookup at serve time. It would close the rows already written as well, which is a real advantage — but it puts a database query in front of every avatar, makes the mount's answer depend on a mutable row (delete the row and its orphaned bytes are ungated again), and re-opens the normalisation question the cleaned-path check exists to close, because the lookup key would be a string the caller supplied. Where the product put the bytes is a fact; what a row currently says is not the same kind of fact.
Consequences
- A gated document written from here on has exactly one address: its resource's. The mount 404s its storage path whether or not the gate would have.
- The extension is preserved. The serving path reads it for a download's name and for the pre-existing static rows ADR-0123 kept, so this slice moves the directory and nothing else. It remains true that nothing inside the artifact decides anything: the root is the product's, the leaf is minted, and the kind is still the stored fact ADR-0123 made it.
- Documents stored before this commit keep their second address. They are at the shared paths and are indistinguishable there by construction — that indistinguishability is the defect this fixes going forward. Moving their bytes is an act on live data across two backends, so it is the charter's Blocker 4, with options and a recommendation, and is answered by nobody here.
- A new kind of gated write adds its root to
gatedStoreRootsin the commit that mints it. The test that holds the list to the constants is what makes that a failure rather than an omission.
Watched failing
Six ways: the document root dropped from the mount's list (six addresses served
on a 200); the list spelled by hand instead of from the constants; SaveDocument
writing under no root of its own; the static create path and the file create path
each pointed back at the ungated write, the stored path landing beside the
avatars in both. Evidence:
.station/jobs/010-artifact-hosting/evidence/phase-05-document-paths-watched-failing-2026-08-30.md.
Source: docs/decisions/0133-a-gated-document-is-stored-where-the-ungated-mount-does-not-answer.md