Blob: references/security-and-trust.md
Security and trust
Reason about a concrete permission: who may do what, to which resource, for how long, and what information the operation reveals. Place each check where that decision can be made with the required freshness.
Separate authentication from application authority
anvil runs repository-defined CI pipelines and lets users administer their own projects. It moved from local invitations and passwords to login through tessera, an identity provider with its own invite-only admission. Rachel made the division explicit:
tessera only manages identities, authorization is still handled by anvil
Accepting a verified tessera login could automatically create an anvil account without granting access to another user's projects. anvil still checked local account disabling and project ownership. Removing anvil's invitation step therefore relied on the provider's existing admission boundary while retaining application permissions.
The migration also had to preserve ownership for people who already had anvil accounts. The provider's stable subject identifier bound to one local user. A later email change could update that user's profile, but could not transfer the binding to another account with that email. Verified email could link a previously unbound legacy account; uniqueness constraints prevented competing attempts from establishing incompatible bindings. That email rule served the migration, while the stable subject carried the identity afterward. The design assumed one configured provider; multiple issuers would require identifying a subject together with its issuer.
Specter exposes services through a distributed tunnel network. When a client asks to publish a tunnel under a public hostname, its verified client certificate establishes who is calling. A separate check establishes whether the hostname belongs to that identity's registered prefix. Otherwise a valid client could claim another client's address. Successful transport authentication supplies the identity for that permission decision.
Let the current surface choose the principal
In bland, a collaborative document workspace, a person can open a page through ordinary member navigation or through a shared link. The same browser may carry both the link token and a signed-in member session. Opening the shared route evaluates the link's grant even when the member account has stronger rights. The route's context selects the principal:
if (surface === "shared" && shareToken) {
return { principal: { type: "link", token: shareToken }, workspaceRole: null };
}The token still has to resolve to valid page access. Selecting it as the principal prevents the shared view from silently acquiring member powers and presenting capabilities the link does not grant. Possessing another credential in the same browser does not change which permission the person is exercising through that surface.
Consider which credentials are relevant to this operation, rather than automatically choosing the strongest credential present.
Treat revocation timing as part of the contract
Vaskel is a messaging application with private file attachments, including media that browsers fetch through repeated byte-range requests for playback and seeking. A server is a group of chat channels whose messages and permissions belong to a ServerDO actor; a direct conversation belongs to a ConversationDO actor. That same message owner holds attachment metadata, while the bytes live separately in private R2 object storage. Consulting the actor for every range repeated the same authorization work throughout playback.
The adopted design asks the owner to authorize a file once, then mints a signed grant valid for one hour. Creating a fresh grant requires current channel access, an attachment claimed by a live message, and no deletion or quarantine. It also checks the attachment's owner_generation: the persisted generation created when that server or direct conversation was initialized and copied into the file's reservation. Matching it to the current owner's generation ties the attachment to the same incarnation of message state that admitted it. This is a durable message-owner lifecycle, independent of a process restart or voice/video device transfer.
The grant binds the object key, ETag, version, and size. The byte route verifies its signature, audience, expiry, and claim shape locally, then checks the object identity before serving. A replaced object cannot satisfy the old grant merely by occupying the same key. No R2 credential needs to reach the browser, and individual grants do not need a tracking or revocation table.
The price of avoiding current owner reads is explicit: an issued URL remains bearer access until expiry, including after logout, permission removal, or quarantine. Deleting a message prevents new grants but can leave already-authorized bytes available until expiry or physical object deletion. Rachel accepted this delay to reduce repeated actor I/O. The one-hour duration bounds that accepted exposure; it does not make access disappear at the moment permission changes.
The signature carries an earlier authorization decision; it does not learn about later revocation. For a product promising that no new read may succeed after removal is acknowledged, this design is insufficient. New requests must pass a gate that observes the removal, including requests carrying old links. Byte delivery can still use object storage or a cache after admission, and already-admitted streams can finish if that is the promise.
Compare the cost and the permitted delay together. Shortening a token's lifetime narrows a revocation window; it does not make revocation immediate. Deleting an object and recalling permission are also distinct operations, and neither recalls bytes already downloaded.
Include metadata in the permission decision
A document in bland can mention another page by storing its identifier. The containing document may be readable even when the referenced page is restricted. The mention resolver therefore checks the current viewer's access to the target before returning its title and icon; inaccessible references receive null metadata. Otherwise a harmless-looking link preview could reveal the name of a private page even though opening it was forbidden.
Failure responses can disclose information too. bland's Sites feature publishes selected workspace pages as public websites. During its simplification, Rachel asked for not_found rather than sites_disabled, so a failed request would not reveal whether the feature was disabled. Both responses can use HTTP 404, but a machine-readable sites_disabled field still reveals the distinction. Concealing that status requires the response body to follow the same disclosure policy as the status code.
Identify the information the current operation is allowed to reveal, then apply that boundary to content, metadata, and errors.
Validate each assumption where it enters
Parsing establishes the input shape. Authentication establishes a principal. Authorization establishes permitted use. Object-integrity checks establish that the bytes match the object admitted for that use.
In Vaskel, the HTTP Worker parses external input and sends a typed operation to the actor that owns the affected messages and permissions. The actor checks current access in its transaction, where the decision can remain valid through the local mutation. Parsing once at the public boundary avoids duplicating the same shape check in every helper; retaining actor authorization prevents a well-typed request from bypassing a permission change. The attachment flow follows this division: owner admission establishes permission to mint a grant, and object checks establish that later byte delivery matches the admitted file.
Keep checks attached to the assumption they establish. Internal corruption or a programming error can deserve a different failure contract from malformed public input without requiring every runtime hop to repeat the whole admission process.
Fit the mechanism to the product
Composer lets an operator configure live media inputs, compose scenes, and publish outputs. For its personal prototype, the agent proposed named operator identities through OIDC and database-backed sessions. Rachel chose “a password defined in worker secret for now.” The smaller login mechanism matched that stage of the product; adding independent operators or individual revocation would change the comparison.
Other boundaries still mattered. A signed browser cookie represented an operator session, a separately configured bearer token admitted machine clients, and media-provider credentials let the backend connect to external services. Browser mutations required the same origin. Provider credentials remained write-only through the public API and encrypted in storage, so simplifying operator login did not turn the studio into a way to retrieve those secrets or make the native media engine responsible for user authentication.
A smaller admission mechanism can preserve the resource and secret boundaries the product needs. Reuse established protocol implementations while keeping application policy explicit: an OIDC library handles protocol machinery, while the application owns binding, admission, and resource access.
For state freshness, continue with authority and state. For the behavior of accepted operations during interruption, use failure and recovery.