This was a known stopgap rather than a clean cross-origin auth design: a leaked URL granted access for the full TTL, so locator URLs were kept to 5 minutes — short enough that URLs effectively only worked while a page was being rendered. Considered and rejected at the time: two scoped session cookies (third-party-cookie blocking risk), a service worker that proxies remote-server fetches with the bearer token (more upfront work but likely too much moving state for the benefit), and a same-origin asset proxy (incompatible with the "standalone frontend with no backing server" deployment shape, and poor fit for GDPR data-residency expectations).
See FDR-008 and ADR-047 for the current flow and trade-offs.
Context
At the time of this decision, attachment metadata (room ID, storage location, filename, dimensions) for a posted file lived embedded inside its owning MessageBody proto in SERVER_BODIES. The asset HTTP handler at /assets/attachments/... needed three things on every request:
- The room ID, to authorize the caller against room membership.
- A pointer to the source-of-truth proto (which body the attachment belongs to, or which projected video manifest event it came from in the case of a transcoded variant or thumbnail).
- The attachment ID, to pick the right attachment out of that source proto.
The previous design (introduced in #575) answered all three by maintaining a second copy of the Attachment proto as a standalone record at attachment.{roomId}.{attachmentId} in SERVER_BODIES. The HTTP handler took the attachment ID from the URL, did a wildcard filter lookup on the records bucket, and read everything else off the matched record.
That design solved the original problem — the prior roomID == "" → allow shortcut on the S3 fast path was a real auth bypass — but it introduced a duplication: every Attachment proto was now persisted twice (once inside its body, once standalone). Two copies is a drift surface for any future mutation, and a write-amplification cost at upload time.
The options for fixing the duplication:
- Standalone record is the source of truth. Body holds attachment IDs only; the record holds the full proto. Inverts the relationship; loses the "a message edit re-renders its attachments naturally" invariant; requires N record fetches per message render.
- Embedded copy is the source of truth, with a thin index. Body owns the proto; the standalone bucket reduces to a pointer (e.g., body key + attachment ID). HTTP handler does index → body fetch → attachment scan. Still two writes per upload (binary + index), still a second KV namespace to maintain.
- Encode the lookup pointer into the URL itself. Eliminate the index entirely. URL carries the room ID, source-of-truth pointer (body key or video-origin attachment ID), and attachment ID; signed so attackers can't craft URLs for arbitrary IDs.
Decision
Adopt the third option. Attachment URLs are self-describing signed locators. No separate index bucket; the URL itself carries everything the HTTP handler needs to authorize and serve. This decision has since been superseded by stable asset access tickets.
URL shape
Original:
/assets/attachments/{base64payload}.{hexHMAC}
Transformed (image resize):
/assets/attachments/{base64payload}.{hexHMAC}/t/{base64params}.{hexHMAC}
base64payload decodes to JSON {r, b?, v?, a}:
r— room ID (for the authz check)b— message body key{userId}.{bodyId}(set for body-embedded attachments; exactly one ofborvis set)v— video-origin attachment ID (set for variants and thumbnails; the processed video manifest is keyed by this ID)a— the attachment ID itself
hexHMAC is the first 16 bytes (32 hex chars) of HMAC-SHA256 of the base64 payload using [core.assets].signing_secret — the same secret as the transform-URL signing in ADR-023. The transform component, when present, retains its existing signing scheme with the locator string as its first resource ID.
HTTP handler flow
- Parse the path segment, verify the locator signature, decode the payload. Invalid signature → 403.
- Look up the session cookie. No session → 401.
- Resolve the room kind from
rand verifyRoomMembershipExists(kind, userID, r). Not a member → 403. - Dispatch by source:
FindBodyAttachment(b, a)for body attachments,FindVideoOriginAttachment(v, a)for variants/thumbnails. Missing → 404. - Read
Storageoff the returned proto and serve (presigned S3 redirect or NATS stream).
No standalone-record bucket is consulted.
Source-of-truth changes
- Body attachments:
AssetCreatedEventis the durable asset creation event for the asset ID, owner, storage, and media metadata. Message-owned assets use themessageowner branch. User avatars use theuser_avatarowner branch. Future room-level uploads and server media should add their own owner branches when they start emitting asset events, without introducing another asset model. Message-owned assets are also embedded as attachments inMessageBody.Attachmentsso message rendering and signed URL generation have the back-pointer at hand.PostMessageatomically commits anAssetProcessingStartedEventfor each selected video attachment; the durable asset-processing runtime consumes those facts and a compatibility scan repairs messages written before the queue contract. - Video variants and thumbnails: derivatives are first-class
AssetCreatedEvents with aderivativeowner pointing at the original asset.AssetProcessingSucceededEvent.videoreferences those derivative asset IDs (thumbnail_asset_id,AssetVideoVariant.asset_id) instead of embedding full asset metadata.
Consequences
- One source of truth per attachment. No write-amplification, no drift surface. A message-body mutation (rare today, but a possibility tomorrow) updates the only copy.
- No second KV namespace.
SERVER_BODIESreverts to holding just bodies. Existingattachment.*records are historical dead weight; current boot no longer reads them as a migration source. - Authorization surface changed by the ticket update. For the 2026-05-24 ticket-bearing locator flow, the signed URL was a short-lived capability: a leaked URL could be used until it expired or the signed user lost room membership. Stable
/assets/files/...URLs use the same ticket capability model directly in browser media URLs. - Forgery prevention. The previous URL shape (
/assets/attachments/{id}) let attackers probe arbitrary attachment IDs to enumerate the space. The locator URL requires a valid HMAC; only IDs the server has issued URLs for can be tested. - Longer URLs. ~150 chars vs ~30. Irrelevant for our use case (URLs aren't human-typed and aren't shared as bare share-links outside the app).
- URLs weren't individually revocable. Rotating
[core.assets].signing_secretinvalidated all URLs at once. Ticketed URL leaks were bounded by expiry and the signed user's current room membership. If we ever want share links with single-use semantics, we'd extend the payload or add server-side revocation state; none of that is needed today. - Expiry became signed into issued browser URLs. The original design did not include an expiry claim, but the 2026-05-24 update added one because signed browser asset URLs became standalone capabilities. Stable
/assets/files/...tickets use the same bounded capability model. - Operational: secret rotation invalidates in-flight URLs. Currently-loaded pages reload their asset URLs through projected timeline/attachment responses after a signing-secret rotation, so the impact is bounded to "until next refresh."
- Cleaner internal API.
GetAttachmentReader(*Attachment)andDeleteAttachmentFromStorage(*Attachment)take the proto directly; the previous(spaceID, attachmentID)shape and the multi-layout S3 key probing are gone. ReadsStorage.S3.Keystraight off the proto.