ADR-0102 — A stored document is served by the product, as data
Status: Accepted · Date: 2026-08-30 · Track: 008-card-view, phase 03
Context
A file link is a document its author uploaded. Until this slice, visiting one
took default:'s h.redirectTo — which reads links.location_url, a column
the file write path never sets. So a file link either 404'd, or, where a row
carried a destination from some other life, 302'd the visitor away. The only
address the document actually had was settings.file_url, the storage URL the
write path composes for the author's own editor: /uploads/<date>/<random>.<ext>
locally, a bucket or CDN URL on S3.
Handing a visitor that URL would end the product's involvement at the moment the document is delivered. Everything track 007 put in front of a link — display rules, the schedule, the click limit, the password gate, the content warning, the splash — is evaluated on the redirect path, above the type switch. A storage URL answers to none of it: it is world-readable to anyone who has the string, it survives the link being disabled, deleted or gated, and it records no view. A gate that can be walked around by copying a URL out of one response is the shape this whole track exists to remove (ADR-0098).
The second question is what a document may do once the product serves it. Serving bytes from the API's own origin is not neutral: that origin is where sessions live (ADR-0096), and an author's HTML or SVG rendered inline there is the author's script running as the product (ADR-0094).
Decision
A file link's bytes are served by the product, and the storage location appears in no response.
- The redirect path serves the document itself.
case models.LinkTypeFilestreams the stored bytes rather than redirecting. Nothing in the response — body,Location, or any header — names the storage path, the storage origin, or the filesystem. The gates, the schedule, the limit and the click record all ran above the type switch, so the document inherits every one of them by being served here rather than there. - Storage grows a read side.
FileStoragegainsOpen(storagePath) (io.ReadCloser, int64, error): local disk opens the file under a root guard, and S3 issues a signed GET, so the bucket needs no public policy for a file link to work. A backend that cannot state a size returns-1and the server omitsContent-Lengthrather than declaring a guess. A path that escapes the storage root is an error, not a file: the path comes out of a database row and is treated as untrusted input. - A file link with no readable document answers 404 — no storage backend
wired, no
file_pathon the row, or bytes that are gone. It never falls back to the redirect this branch replaces, because the fallback is the defect. - The document is served as data. Every response carries
X-Content-Type-Options: nosniff,Content-Security-Policy: default-src 'none'; sandboxandX-Frame-Options: DENY— the same posture the/uploadsmount already takes. The declared type is derived from the stored file's own extension,application/octet-streamwhen unrecognised, and is never sniffed from the bytes. - Inline rendering is an allowlist of four raster image types
(
image/jpeg,image/png,image/gif,image/webp). Everything else downloads, and the author'sforce_download_is_enableddownloads anything. The list is what this codebase can state cannot execute — not what a browser can display. SVG is absent for the reason it is absent from the upload allowlist: it is XML that can carry script. PDF is absent because it opens in a viewer on this origin. - The download is named with the author's filename, encoded per RFC 5987 so a space or a non-ASCII character survives the header. A stored name that is a path rather than a name falls back to the link's slug: it is not reduced to its last component, because a row this code does not understand is not a row to guess at.
Consequences
- A file link is gated, scheduled, limited and counted like every other link, because it is now served by the path that does all four.
- The storage URL stops being a second, ungated address for the document —
through this branch.
settings.file_urlis still composed for the author's own editor, and/uploads/*still serves what is under it: closing that mount to direct access is a separate change with its own blast radius (every image the app draws from an upload), named as an open item rather than done quietly here. - Bytes now flow through the API process. They are streamed, never buffered, so the cost is a held connection rather than memory; range requests are not supported yet, which a large-media deployment would want and this one does not have.
- Rule 5 is deliberately narrow, and widening it is a decision with a reason, not a convenience: an inline PDF or an inline SVG is a new posture on the session origin, and track 010's allowlist widening will meet the same question with HTML in hand.
- The
statichalf of phase 03 is not settled by this ADR. A static page is a document that is HTML by definition, so rule 5 refuses it and rule 4 would sandbox it into uselessness; what a static page may be served as is its own decision, and its slice states it before it merges.
Source: docs/decisions/0102-a-stored-document-is-served-by-the-product-as-data.md