ObjectStackObjectStack

Attachment access — who can read a file

Who can read, upload, rename or delete a record's attachments: the parent-derived access model, authenticated downloads, the enable.files gate and file cleanup.

The generic Attachments surface (Salesforce "Notes & Attachments" parity) separates file storage from where a file is attached:

  • sys_file — one row per uploaded blob (the bytes live in the storage backend; the row holds key, scope, owner_id, status).
  • sys_attachment — a polymorphic join row linking a sys_file to any record via parent_object + parent_id (like Salesforce ContentDocumentLink). One file can be attached to many records.

The governing principle: an attachment has no access model of its own — it inherits its parent record's. A caller who can read a record can read its attachments; a caller who may edit a record — a by-id update of it by that caller would be admitted — can attach to it, detach from it and re-point an attachment to it. Enforcement is layered, and every gate is fail-closed.

Field.file / Field.image are a separate path — those store an opaque sys_file id in the record's own column (ADR-0104 D3; the { id, name, size, mimeType, url } shape is derived at read time, never stored) and never create a sys_attachment row, so nothing on this page applies to them.

Who holds the object grant

The gates on this page decide the rows. The object grant on sys_attachment only opens the door to them, and every member holds its read and create half with no grant from the app: the storage service (@objectstack/service-storage) contributes a set of its own, storage_attachment_member, to the member baseline that every signed-in member holds through the everyone anchor. It contributes the set beside the gates, and only once all four are present: the write rule, the read-visibility gate, the download door's parent-record check and the per-object opt-in gate (enable.files, below). So a member attaches a file to a record they can edit, and sees the files of a record they can read, and security/explain names storage_attachment_member as the baseline that grants it.

The set reaches no one else:

  • an external member (org_external) resolves its own baseline instead, and an agent principal resolves no member baseline; an agent acting for a member gets no more than that member, within its own scope;
  • a deployment that declares no member baseline (fallbackPermissionSet: null) hands it to no one;
  • a host that registers sys_attachment without the storage service gets no set, and a member's attach is refused PERMISSION_DENIED (403). All four gates are the storage service's own, so wherever it runs they are present, unless its data engine cannot carry them (no hook or middleware seam) or no auth service is composed for the download check; then it contributes no set either, and the boot log names the missing gate and what to add.

A host can also narrow the set for its own deployment, through the SecurityPlugin option platformBaselineOverrides. It names a contributed set and one of its objects, and either keeps that object at read ('read') or withholds it ('decline'). A host on which members must see attachments but never create them declares:

new SecurityPlugin({
  platformBaselineOverrides: { storage_attachment_member: { sys_attachment: 'read' } },
});

Members then keep the read, and a create is refused PERMISSION_DENIED (403); security/explain and the effective-access read show the narrowed set. An override only takes bits away. A set left granting nothing joins no baseline, and an override that matched no contributed set by the end of boot is logged at warn naming it, so a renamed set or object does not pass unnoticed.

The set carries no edit and no delete (ADR-0090 D5: a set every member holds carries no delete bit). Editing or deleting attachments still needs an explicit grant on sys_attachment (see Delete below). The one removal a member makes without it is of an attachment they uploaded themselves, through the storage service's removal door (see The uploader's removal door). An app can also grant read and create explicitly, as before; the baseline set adds nothing to such a grant.

The opt-in gate — enable.files

Attachments are opt-in per object (spec default false). A sys_attachment row may only target an object that declares enable: { files: true }; the Attachments panel renders only for such objects. Any other target is rejected:

CodeStatusWhen
FILES_DISABLED403Creating a sys_attachment whose parent_object does not declare enable.files: true (an object that is not registered included), or re-pointing an existing one onto such an object

The storage service enforces it on every sys_attachment insert and re-point, wherever it runs, for every caller, the system path and an administrator included. It reads the object's current definition on each write, so an object switched to files: true is attachable at once. It is independent of the record-level checks below, and answers before them.

Create — parent-edit access & provenance

Creating a sys_attachment requires that the caller may edit the parent record — Salesforce edit-on-parent parity — and "may edit" has one meaning here: a by-id update of that parent record, by the same caller, would be admitted. The gate asks exactly that question, of the security service: the record-grained verdict security.explain reports for update on the parent record (allowed and record.visible both). That verdict is the write path's own composition — the parent object's grant, its row-level security, its record sharing at the caller's write depth, the master of a controlled_by_parent parent, and both legs of an on-behalf-of (agent) request — so a caller who can update the parent record by id can also attach files to it, and a caller who cannot, still cannot. A caller whose write depth on the parent object is unit, unit_and_below or org attaches wherever that depth lets them update.

The same rule governs every check that asks about the parent: attaching, detaching or editing another user's attachment, re-pointing an attachment to another record (judged on the new parent), and the file-attachments service's caller-scoped assertMayAttach.

When no sharing service is wired, a caller-scoped read of the parent (a findOne) is asked first. A security service that judges no by-id update (it serves no explain, or there is none) leaves the gate on the composition it had before: record sharing (ISharingService.checkEdit) at the narrowest edit depth, then, for a controlled_by_parent parent, the master-detail check (ISecurityService.checkControlledByParentWrite). A store fault keeps its own status (a 503 stays a 503); it is never reported as a refusal. uploaded_by is server-stamped from the session; a client-supplied value is ignored, and a create whose session names no signed-in user is refused. A row's uploader is read-only after creation, like a comment's author: an update drops a non-system caller's uploaded_by and reports it in droppedFields, and the rest of the write lands. System-context writes keep the value they supply.

Attaching an upload from the browser

The Attachments panel attaches a file in the call that completes its upload: the presigned upload's POST /api/v1/storage/upload/complete carries attachTo: { parentObject, parentId }, and the server commits the file and writes its sys_attachment row as one unit, as the signed-in user. Every check above judges that user: the permission to create an attachment, edit access to the record, the record object's enable.files, and the file reference itself. The answer carries the new attachmentId. A refused attach leaves the upload pending and attached to nothing, and the pending-upload retention reclaims it.

The file must be the caller's own upload, still pending, in the attachments scope, attached to nothing and owned by no record field, with its bytes stored. Any other file id — another user's upload, an id that names no file — is refused before anything is written:

CodeStatusWhen
PERMISSION_DENIED403The file is another user's upload (the commit door's uploader rule)
FILE_NOT_FOUND404The id names no file
RESOURCE_CONFLICT409The upload is already completed, already attached or owned by a field, or its bytes are not stored
INVALID_REQUEST400attachTo is malformed, or the upload was not started in the attachments scope
NOT_IMPLEMENTED501The deployment composes no auth service or no data engine, so there is no caller to attach as

This is how a member who may attach files but holds no read on sys_file attaches one: a sys_attachment create through the generic data API (POST /api/v1/data/sys_attachment) names its file_id as any other lookup value, which the caller must be able to read, and a file they cannot read is refused 400 VALIDATION_FAILED (reference_not_found on file_id). The attach on completion vouches for that one file, in that one call, and grants no read of sys_file or of anything else.

CodeStatusWhen
RECORD_NOT_ACCESSIBLE403The session names no signed-in user to record as the uploader
ATTACHMENT_PARENT_ACCESS403The parent record does not exist, or a by-id update of it by the caller would not be admitted (on a re-point, the new parent)
OBJECT_NOT_FOUND404The parent_object names an object the registry does not hold — the answer a by-id update of it gets

Read / list — inherited parent visibility

Listing or reading sys_attachment only returns rows whose parent record the caller can read. This is enforced by a sys_attachment-scoped engine middleware (not a hook), so it filters find, findOne, count, and aggregate identically — the list total cannot leak the count of hidden rows. Per distinct parent_object, the visible parent ids are resolved through the caller-scoped engine (the parent object's own RLS applies) and folded into the query; a caller with no visible parent gets an empty result. Failure to resolve the filter fails closed (deny-all).

Delete — uploader or parent editor

Deleting a sys_attachment is allowed when the caller is the uploader OR may edit the parent record — the parent-edit rule above: a by-id update of the parent by that caller would be admitted. The uploader keeps their own rows whatever the parent answers. A multi-delete (multi: true) matches only attachments the caller can read: an attachment whose parent is out of the caller's sight is not matched, not removed and not counted, so a predicate that reaches only such attachments answers exactly what a predicate that matches nothing answers. Every matched row must then pass.

CodeStatusWhen
ATTACHMENT_DELETE_DENIED403The caller can read the attachment, but is neither the uploader nor able to edit the parent record
RECORD_NOT_FOUND404A delete or update by id of an attachment the caller cannot read — its parent record is not readable to them. On the write doors a row the caller cannot read is a row that does not exist: the answer is exactly what an id that names no attachment gets, for every caller, so a hidden attachment and a missing one cannot be told apart. It applies even to the uploader once the parent is out of their sight, because the read door no longer returns the attachment to them either
PERMISSION_DENIED403The gate's own not-visible refusal, where the gate answers before that check. It names neither the parent nor the attachment's link to it

An update of another user's attachment follows the same rule — the uploader or a parent editor — and a by-id update of an attachment the caller cannot read gets the same not-found answer. A multi-update matches only attachments the caller can read, as a multi-delete does. Re-pointing an attachment (parent_object / parent_id) to another record is an attach there: the new parent must pass the parent-edit rule too (ATTACHMENT_PARENT_ACCESS, 403).

The comment thread's moderation gate (sys_comment, @objectstack/plugin-audit) asks the same parent-edit rule: editing or removing another person's comment requires that a by-id update of the thread's parent record would be admitted, and the author keeps their own comments. Posting a comment stays a read rule on the parent.

The platform baseline also ships a parent-blind row-level delete floor (owner_only_deletes: you may delete only the rows you created, for members holding org_member). It would refuse a parent editor before this gate is asked, so the storage service contributes a delete-only alternate match beside the floor when it installs the gate, and the gate decides. The alternate match exists only where the gate does: a deployment that registers sys_attachment without @objectstack/service-storage keeps the floor, and there only the row's creator may delete it. The floor's edit limb is not relieved: a member the floor binds still cannot edit another user's attachment row (PERMISSION_DENIED), even as a parent editor.

The member baseline (the everyone anchor: member_default and the storage service's storage_attachment_member) grants read and create on sys_attachment and no edit or delete (ADR-0090 D5 — delete is not a baseline right). Managing attachments — editing them, or deleting another user's — is therefore enabled by an ordinary, position-distributed permission set that grants edit and delete on sys_attachment. Until a member holds such a set, a delete through the data API is refused by RBAC (PERMISSION_DENIED) before the attachment-level gate above is even consulted. Withdrawing one's own upload needs no such set: it goes through the removal door below.

The uploader's removal door

DELETE /api/v1/attachments/:id removes one attachment the caller uploaded, with no delete grant on sys_attachment. The storage service mounts it beside its other routes, so wherever it serves uploads a member can withdraw them.

CodeStatusWhen
UNAUTHENTICATED401No session
VALIDATION_ERROR400The request carries query parameters, or names no id: the door removes exactly one attachment, by its id in the path
RECORD_NOT_FOUND404The caller cannot read the attachment (its parent record is out of their sight), or the id names none: the two answer alike
PERMISSION_DENIED403The attachment's uploaded_by is not the caller — another member, a parent editor and an administrator alike. The row stays

The door reads the attachment as the caller, so every read rule above applies first; it then admits only the uploader, and removes the row on their behalf, answering { id, deleted: true } (200). The file behind it is released as on any delete. It grants nothing wider: the member baseline gains no delete bit, the data API's delete (DELETE /api/v1/data/sys_attachment/:id) stays refused to a member who holds only the baseline, and removing someone else's attachment — as a parent editor or an administrator — still goes through the data API with an explicit delete grant.

The rename door

PATCH /api/v1/attachments/:id with the body { "file_name": "..." } renames one attachment by the delete rule above: the uploader, or a caller who may edit the parent record. The storage service mounts it beside the removal door, at the same path.

CodeStatusWhen
UNAUTHENTICATED401No session
VALIDATION_ERROR400The request carries query parameters, names no id, or its body is not exactly { "file_name" } with a non-blank string
RECORD_NOT_FOUND404The caller cannot read the attachment (its parent record is out of their sight), or the id names none: the two answer alike
RECORD_NOT_ACCESSIBLE403The caller reads the attachment but is neither its uploader nor able to edit the parent record. The name stays
PERMISSION_DENIED403A caller who is not the uploader holds no edit grant on sys_attachment, or is bound by the platform's owner-only edit floor. The name stays

The door reads the attachment as the caller first, so every read rule above applies. The uploader renames their own attachment with no edit grant: the door writes the new name on their behalf, as the removal door removes. Anyone else's rename is an ordinary update made as the caller, so it needs an explicit edit grant on sys_attachment and then passes the update rule above (uploader or parent editor). It answers { id, file_name } (200), with the name trimmed.

Only the name the attachment is listed under changes. The stored sys_file, its bytes and the file name a download carries stay as they were uploaded.

The console's Attachments tab offers Rename and Delete on every row the reader uploaded, through these two doors, with no grant beyond the member baseline. On another user's row it offers Rename to a holder of the edit grant on sys_attachment, and Delete, through the data API, to a holder of the delete grant.

Download — authenticated & parent-scoped

For scope: 'attachments' files (those created through the Attachments surface), the download endpoints require a session and read-access to a parent record, and issue a short-lived signed URL:

CodeStatusWhen
AUTH_REQUIRED401Anonymous download of any file not marked acl: 'public_read' (see below), or a credential the organization wall refuses
ATTACHMENT_DOWNLOAD_DENIED403The caller is neither the file's owner nor able to read any record it is attached to

The 401 is the generic "unauthenticated" answer, and it has always covered more than a missing credential — an unknown, revoked or expired API key reads the same way. Under a wall-enforcing tenancy posture two further credentials join it, refused before this door's ownership and parent-read checks are consulted:

  • an API key stamped with an organization its owner has left — refused under both group and isolated, the two postures that enforce a wall;
  • an API key carrying no organization at all — refused under isolated only. group reads across the caller's whole membership set, so a key with no organization is still admitted there.

Under single neither applies — there is no organization wall for a key to be walled out of. Both refusals deliberately tell the caller nothing more than the anonymous case does: the response is byte-identical to sending no credential at all, and the reason is written to the server log instead. The check itself lives in the shared API-key admission path, not in the attachments gate.

The parent-record check applies to files that have a parent: attachments-scope files, and files a record's file / image field owns, which are judged against that one record (FILE_DOWNLOAD_DENIED, 403, when it cannot be read). A file with neither — an upload no record has claimed, such as an avatar or an organization logo stored as a URL — has no parent to check, so its download requires only a signed-in caller (AUTH_REQUIRED, 401, otherwise). A browser's <img src> sends the session cookie set at sign-in, so a signed-in page keeps rendering these files. Only a file marked acl: 'public_read' is served to a caller with no session: mark a file that way when it must render before sign-in.

How a downloaded file is answered

A file opened from its signed URL is rendered in place only when its type is on the storage service's inline allow-list: raster images (PNG, JPEG, GIF, WebP, AVIF, BMP), PDF, plain text, and common audio and video types. Every other type, SVG and HTML included, and a file with no type, is answered as an attachment, so the browser saves it under its name instead of opening it. The local adapter's byte route sends X-Content-Type-Options: nosniff and a sandbox Content-Security-Policy that lets no script run on every answer; audio and video shown in place carry a media variant of it, so the browser's player can load the file. This was measured in Chromium. The S3 adapter's signed URL carries the same type and disposition; the other response headers are the bucket's to send, so a host that fronts the bucket with its own proxy sends them there.

The upload entry points (presigned / chunked) likewise require a session when an auth service is wired, and stamp owner_id on the new sys_file. A stored file's uploader is the user who created it, as an attachment's is: a sys_file created through the data API records the signed-in user as owner_id, whatever the request carries, and a create whose session names no signed-in user is refused (RECORD_NOT_ACCESSIBLE, 403). The file's uploader is read-only after creation: an update drops a non-system caller's owner_id (a holder of the ownership-transfer grant included) and reports it in droppedFields. Only a system-context write records a different uploader.

Storage-byte lifecycle

Deleting attachments does not immediately delete the underlying bytes (a file can be shared across records). Reclamation is handled by the platform LifecycleService via declarative reap guards:

  • sys_file — when the last sys_attachment referencing an attachments-scope file is deleted, the file is tombstoned; a reap guard re-verifies zero references at sweep time and deletes the storage bytes before the row is reaped (abandoned pending uploads are reaped too). A tombstone is recoverable state, not a delete — and every reader treats it that way. Re-attaching the file, or re-claiming it through a record field, makes it readable again immediately, with no sweep in between: the download endpoints and record file-field hydration ask the same "is anything still holding this file?" question the reap guard asks before it reclaims anything. Both reach it through that one predicate rather than each deciding for itself, which is what stops the two surfaces answering differently about one row — a file GET /storage/files/:id serves is a file a record read expands into { id, name, size, mimeType, url }. The row itself stays tombstoned until a sweep tidies it, and a file with no holder left still answers FILE_NOT_FOUND (404) and keeps its bare id in a record payload — except to a reader refused sys_file read, who gets { id, metadataRefused: true } for every file id the record being read does not own, or that the download door's field-owned verdict refuses them, held or not; a file the record owns and the door would serve them reads exactly as it does for a sys_file reader (file read forms).
  • sys_upload_session — abandoned/terminal chunked-upload sessions are reaped, and a reap guard aborts the underlying backend multipart upload (S3 AbortMultipartUpload / local parts dir) first, so already-uploaded parts don't leak.

Enforcement summary

Every operation also needs its object grant on sys_attachment, refused PERMISSION_DENIED (403) without it. Read and create come with the member baseline (storage_attachment_member, where every attachment gate is present); edit and delete need an explicit grant, except that the uploader withdraws or renames their own attachment through the storage service's doors without one.

OperationRequirementDeny code
Attach (create)parent object opts in (enable.files)FILES_DISABLED (403)
Attach on upload completion (attachTo)the caller's own pending, unattached attachments-scope upload, then every create checkPERMISSION_DENIED (403) / RESOURCE_CONFLICT (409), then the create codes
Attach (create), re-pointa by-id update of the parent record by the caller would be admittedATTACHMENT_PARENT_ACCESS (403); OBJECT_NOT_FOUND (404) when the parent object is not registered
List / readinherits parent read visibility(filtered out)
Deleteuploader or parent editor (+ an explicit delete grant)ATTACHMENT_DELETE_DENIED (403); PERMISSION_DENIED (403) when the parent is not readable or no delete grant is held
Withdraw one's own upload (DELETE /api/v1/attachments/:id)the row's uploaded_by is the caller, and the caller reads it; no delete grantUNAUTHENTICATED (401) / RECORD_NOT_FOUND (404) / PERMISSION_DENIED (403)
Rename (PATCH /api/v1/attachments/:id)the caller reads the attachment, then is its uploader (no edit grant), or holds the edit grant and may edit the parent recordUNAUTHENTICATED (401) / VALIDATION_ERROR (400) / RECORD_NOT_FOUND (404) / RECORD_NOT_ACCESSIBLE (403) / PERMISSION_DENIED (403)
Downloadsession + owner-or-parent-read (attachments scope); session only for a file with no parent; none for acl: 'public_read'AUTH_REQUIRED (401) / ATTACHMENT_DOWNLOAD_DENIED (403)

See also

On this page