Appearance
API Reference
Eleven routes under /api/v1/files. Each answers JSON — metadata, a URL or a problem — and none of them accepts or returns the content of a file (RN-GF-06). The contract of every field is §15–§17 of the specification; the reasons are in ADR 0010. A module in the same process does not use these routes: it registers as a consumer and uses its ports.
Permissions
Six tenant permissions, in the framework's action:resource spelling (D1), plus three platform permissions for product files:
| Permission | Opens |
|---|---|
upload:files | Reserving, confirming, adding and releasing references |
read:files | The record, the scan history, download URLs and the scanner status |
retain:files | Changing retention and putting a legal hold on |
purge:files | Purging a file by hand |
release-hold:files | On top of retain:files, never instead of it: releasing a legal hold. On no role template |
purge-permanent:files | On top of purge:files, never instead of it: purging a Permanent file. On no role template |
Those six are tenant permissions, over the files of the session's tenant. A product file (no tenant) is an entity of the platform (ADR 0011, D10): reserving, confirming and referencing one, changing its retention (legal hold included) and purging it need the platform permissions upload:product-files, retain:product-files and purge:product-files of a platform role (the platform_permission claim) — no tenant permission reaches it. In a session with no tenant the routes accept those platform permissions; in a tenant's session they answer to the tenant permission alone, and the product file then also demands the platform one. A session with no tenant reaches no tenant's file: it is answered 404 FILE_NOT_FOUND. Reading a product file needs only read:files. There is no wildcard permission: the admin:system override was removed by ADR 0011.
Routes
| Method | Route | Permission | Success |
|---|---|---|---|
POST | /files | upload:files | 201 reservation: fileId, uploadUrl, uploadExpiresAt, requiredHeaders |
POST | /files/{id}/complete | upload:files | 200 the record, now Scanning |
GET | /files/{id} | read:files | 200 the record, in any state — a tombstone included |
GET | /files/{id}/download-url?purpose= | read:files | 200 { url, expiresAt } |
GET | /files/{id}/scan-attempts?page= | read:files | 200 one page of the attempts — PagedResult with items, totalCount, pageNumber, pageSize — by attemptNumber descending, 20 per page; page is 1-based and defaults to 1, and a page past the end is empty with the real totalCount |
POST | /files/{id}/references | upload:files | 201 the reference; the same row again for a pair that already holds the file. Only for an ownerScope its consumer declared managed by this surface (RN-GF-23) |
DELETE | /files/{id}/references/{referenceId} | upload:files | 204; releasing twice is releasing once. Only a reference of a scope the surface manages (RN-GF-23) |
PUT | /files/{id}/retention | retain:files | 200 the record, with legalHold and the legalHolders that hold it — see Legal holds |
POST | /files/{id}/purge | purge:files | 200 the tombstone. Ordinary, or — with erasure: true — the act of erasure |
POST | /files/{id}/rescan | upload:files | 200 the record — Scanning for a file that was Failed, Available for a released one |
GET | /files/scanner-status | read:files | 200 the engine, its database and the queue |
Reference routes and owner scopes
The two reference routes take (POST) or read from the stored row (DELETE) an ownerScope, and the caller chooses it. They act only on a scope whose consumer declared it managed by the HTTP surface when it registered (o.ManagedThroughHttpSurface()); the surface manages no scope by default. Any other scope — a module that consumes the files in process (gryd.report-execution, gryd.notification-attachment, the GrydAudit scopes), a product scope such as nexio.attachment, or a text nobody registered — is refused with 403 FILE_OWNER_SCOPE_FORBIDDEN, on creation and on release, whatever the permission the session holds. Without it, anyone with upload:files could pin a file forever with an invented owner, or release another module's reference and hand its file to the purge. A refused creation leaves no reference and a refused release leaves the reference active. The scope is checked before the file is read, so the refusal does not tell whether the file exists; on a managed scope the creation still obeys the ownership of RN-GF-22 (only the caller that reserved the file, or one naming an active reference of the same scope, may add one → 409 FILE_REFERENCE_NOT_ALLOWED_CONFLICT).
No consumer in this repository declares ManagedThroughHttpSurface() — not GrydReports, GrydNotifications, nor the two GrydAudit packages — so today the two routes refuse every scope. They exist for a product whose own owners are people using these generic screens, and who says so in its own registration. A module that works in process keeps its references through its own port (IFileStore<TScope>.AddReferenceAsync / ReleaseReferenceAsync), which is not this route and is not limited by this rule. See Registered consumers.
What is deliberately absent:
- There is no
DELETE /files/{id}. Destroying content is a purge, with a reason, an author and a permission of its own. objectKeyandbucketNamenever appear in a request, a response, a DTO or a log line (RN-GF-07). The upload and download URLs are the only place a location travels, signed and short-lived.- There is no route that changes a verdict. No state goes back to
AvailablefromInfected, and nothing reachesAvailablewithout a scan.
PUT /files/{id}/retention and POST /files/{id}/purge
Two routes that change custody. Their rules are on Legal holds and Erasure; what matters to a caller:
- Retention is a floor (RN-GF-25). A purge without
erasure: trueof a file whoseretainUntilis still ahead, or that isPermanent, is409 FILE_RETENTION_NOT_EXPIRED_CONFLICT— the message carries the date — and nothing changes.purge-permanent:fileson top ofpurge:filesdoes not move it: only the marked act does. - The erasure (
erasure: true) also reachesInfectedandFailedfiles, always takes the name off the tombstone, goes to the trail with its author and reason, and is503 FILE_AUDIT_TRAIL_UNAVAILABLEwhen the registeredIAuditStoreis not durable. APermanentfile additionally needspurge-permanent:files. Over the route the author is the authenticated user and one author is enough; the two-author dual custody is the in-process act. - A hold is only placed on content under a verdict.
legalHold: trueon aPending,ScanningorFailedfile is409 FILE_NOT_AVAILABLE_CONFLICT. OnAvailableandInfectedit adds the platform's hold beside any consumer's. - A product file (no tenant) is purged, or has its hold lifted, only when the Core outbox takes a message without a tenant: until then both answer
503 FILE_AUDIT_TRAIL_UNAVAILABLE(why). - Status of the purge route.
503is part of its contract, as the specification says.422is not produced by the route: the 422 of the erasure (FILE_ERASURE_AUTHOR_INVALID_UNPROCESSABLE) belongs to the authors a consumer declares in process, and the route's only author is the authenticated user. The OpenAPI document lists503only where the scanner is down (D6), so a generated client will not see it here.
POST /files/{id}/rescan (RN-GF-17)
A new reading of the content, by state:
| State | What the route does |
|---|---|
Failed | Back to Scanning and into the queue — whatever is left of the automatic budget: this is the operator's way out of a file the three retries gave up on. The queue itself no longer restarts a Failed file past its budget |
Scanning | Idempotent: the record, and nothing queued |
Available | The manual re-scan of the archive. The record stays Available — referenceable and downloadable — while it is read again; a clean answer, an engine error, a timeout or a read cut by an I/O error only add a FileScanAttempt. Idempotent: the request is recorded as an open FileScanAttempt with engine requested (taken over by the worker that reads), so the same request again — or the archive job — queues nothing while it is pending or going |
Pending, Infected, Purged | 409 FILE_RESCAN_NOT_APPLICABLE_CONFLICT: not uploaded yet, terminal, no content left |
Two things move a released file, both to Infected and never to Purged (RN-GF-17, RN-GF-18): the engine finding a signature the base learned since, and a confirmed size divergence — the read went past sizeBytes, or ended before it and storage reports another size too. In one transaction the object goes to quarantine, every active reference is released, retainUntil and the legal holds are left as they were (RN-GF-24), and each owner that held a reference gets a verdict (Infected) after the commit. A divergence carries rejectionCode = FILE_OBJECT_CHANGED_UNPROCESSABLE. Both go to the trail as one line of their own, in the same transaction: stored_file.rescan_condemned, an Updated with no purge reason and the Cause (signature or object-changed) — see the audit trail.
The same reading runs without a request after a signature base update: the archive job (gryd-files.archive-rescan, every 15 minutes) requests, and queues, up to RescanBatchSize released files of the last RescanLookbackDays that the current base has not read (only a reading that answered — clean or detection — counts as read), newest first. See Configuration.
Errors by route
| Route | Refusals |
|---|---|
POST /files | 400 FILE_PROFILE_UNKNOWN · 422 FILE_TOO_LARGE_UNPROCESSABLE (the ceiling is in the message) · 422 FILE_CONTENT_TYPE_NOT_ALLOWED_UNPROCESSABLE · 403 for a product file without upload:product-files |
POST /files/{id}/complete | 404 FILE_NOT_FOUND · 409 FILE_NOT_UPLOADED_CONFLICT · 409 FILE_UPLOAD_EXPIRED_CONFLICT · 422 FILE_SIZE_MISMATCH_UNPROCESSABLE (the object is deleted and the record becomes a tombstone) |
GET /files/{id} | 404 FILE_NOT_FOUND |
GET /files/{id}/scan-attempts | 400 for a page below 1 (no code) · 404 FILE_NOT_FOUND |
GET /files/{id}/download-url | 404 FILE_NOT_FOUND · 409 FILE_NOT_AVAILABLE_CONFLICT (Pending, Scanning, Failed) · 409 FILE_INFECTED_CONFLICT · 409 FILE_PURGED_CONFLICT (with when and why) |
POST /files/{id}/references | 403 FILE_OWNER_SCOPE_FORBIDDEN for a scope the surface does not manage (RN-GF-23) · 409 FILE_REFERENCE_NOT_ALLOWED_CONFLICT · 404 FILE_NOT_FOUND · 409 FILE_NOT_AVAILABLE_CONFLICT · 409 FILE_INFECTED_CONFLICT · 409 FILE_PURGED_CONFLICT |
DELETE /files/{id}/references/{referenceId} | 404 FILE_NOT_FOUND, for the file or for a reference that is not on it · 403 FILE_OWNER_SCOPE_FORBIDDEN when the reference's scope is not managed by the surface (RN-GF-23); the reference stays active |
PUT /files/{id}/retention | 400 incoherent body (no code) · 400 a hold placed or lifted without a reason (no code) · 404 FILE_NOT_FOUND · 409 FILE_PURGED_CONFLICT · 409 FILE_NOT_AVAILABLE_CONFLICT placing a hold on Pending, Scanning or Failed · 422 FILE_RETENTION_SHORTENED_UNPROCESSABLE · 403 lifting a hold without release-hold:files, or touching a product file without retain:product-files · 403 FILE_OWNER_SCOPE_FORBIDDEN lifting where only consumers hold (their scopes in errors) · 503 FILE_AUDIT_TRAIL_UNAVAILABLE lifting with no durable trail, or on a product file |
POST /files/{id}/purge | 400 without a reason, or with a job: reason (D16) · 404 FILE_NOT_FOUND · 409 FILE_RETENTION_NOT_EXPIRED_CONFLICT without erasure, before retainUntil or for Permanent (the date in the message) · 409 FILE_STILL_REFERENCED_CONFLICT (the holding scopes in errors) · 409 FILE_LEGAL_HOLD_CONFLICT (the holders in errors) · 409 for a state it does not reach, with that state's code (FILE_NOT_AVAILABLE_CONFLICT, FILE_INFECTED_CONFLICT, FILE_PURGED_CONFLICT) — the erasure reaches Infected and Failed too · 403 for a Permanent file without purge-permanent:files, or a product file without purge:product-files · 503 FILE_AUDIT_TRAIL_UNAVAILABLE for an erasure with no durable trail, or any purge of a product file |
POST /files/{id}/rescan | 404 FILE_NOT_FOUND · 409 FILE_RESCAN_NOT_APPLICABLE_CONFLICT for Pending, Infected or Purged (the message names the state and why) · 403 for a product file without upload:product-files |
GET /files/scanner-status | 503 FILE_SCAN_UNAVAILABLE |
A file of another tenant is answered exactly as a file that does not exist: 404 FILE_NOT_FOUND with the same body and the same headers, on every route that names a file, whatever the state of the file — never a 409 or a 422 first. The lookup decides before anything else is looked at.
The error contract (§16)
Every refusal is a problem document with the code in code and, where the answer is a list, the list in errors. The status follows from the suffix, the same rule the whole framework uses:
| Suffix | Status |
|---|---|
_NOT_FOUND | 404 |
_CONFLICT, _ALREADY_EXISTS, _ALREADY_ASSIGNED | 409 |
_FORBIDDEN, _ACCESS_DENIED, _BLOCKED | 403 |
_UNAUTHORIZED | 401 |
_UNPROCESSABLE | 422 |
_UNAVAILABLE | 503 |
| no suffix | 400 |
The platform's list of explicit codes is tested first, so an exact code beats a suffix.
The codes
Twenty-three, in FileErrorCodes; the status is the suffix's (the explicit list of the platform comes first and none of these is in it):
| Code | Status | When |
|---|---|---|
FILE_NOT_FOUND | 404 | No such file in this tenant — another tenant's answers the same |
FILE_CALLER_UNAUTHORIZED | 401 | An act the trail names, in process, with no user and no declared author, or with a declared author who is not the user in the context. Never from a route |
FILE_OWNER_SCOPE_FORBIDDEN | 403 | A reference route on a scope the surface does not manage; a scope with no registered consumer, or a port called from code that does not reference its marker; lifting a hold that only consumers hold; an erasure naming a pair of another scope |
FILE_PROFILE_UNKNOWN | 400 | The profile is not in the configuration |
FILE_CONTENT_TYPE_NOT_ALLOWED_UNPROCESSABLE | 422 | Type outside the profile's list — declared, or verified by the scan |
FILE_TOO_LARGE_UNPROCESSABLE | 422 | Above the profile's ceiling (the ceiling is in the message) |
FILE_SIZE_MISMATCH_UNPROCESSABLE | 422 | The real size is not the declared one; the object is deleted |
FILE_UPLOAD_EXPIRED_CONFLICT | 409 | Confirmation after uploadExpiresAt |
FILE_NOT_UPLOADED_CONFLICT | 409 | Confirmation with no object in the bucket |
FILE_NOT_AVAILABLE_CONFLICT | 409 | Use of a file in Pending, Scanning or Failed; a new hold on one of them |
FILE_INFECTED_CONFLICT | 409 | The file is quarantined |
FILE_PURGED_CONFLICT | 409 | A tombstone; carries purgedAt, the reason and the rejectionCode |
FILE_STILL_REFERENCED_CONFLICT | 409 | Purge with an active reference; the scopes are listed |
FILE_LEGAL_HOLD_CONFLICT | 409 | Purge or erasure with a hold of any holder; the holders are listed. Placing a hold never gets it |
FILE_ERASURE_DUAL_CUSTODY_CONFLICT | 409 | An erasure that needs two authors has one, or the same twice |
FILE_REFERENCE_NOT_ALLOWED_CONFLICT | 409 | A reference or expected owner by someone who did not reserve the file, on a file not Pending, already expected by another owner, or with no origin to propagate from; reading in process by an owner with no active reference |
FILE_RETENTION_NOT_EXPIRED_CONFLICT | 409 | Ordinary purge before retainUntil, or of a Permanent file |
FILE_RESCAN_NOT_APPLICABLE_CONFLICT | 409 | Re-scan of Pending, Infected or Purged; carries the state |
FILE_OBJECT_CHANGED_UNPROCESSABLE | 422 | Only as a rejectionCode: the object changed after the confirmation |
FILE_RETENTION_SHORTENED_UNPROCESSABLE | 422 | A retainUntil that does not move forward |
FILE_ERASURE_AUTHOR_INVALID_UNPROCESSABLE | 422 | An author of an erasure that is not an existing, active user of the tenant checked (in process) |
FILE_SCAN_UNAVAILABLE | 503 | Only GET /files/scanner-status |
FILE_AUDIT_TRAIL_UNAVAILABLE | 503 | An erasure or the lifting of a hold with no durable trail; a purge of a product file |
FILE_SCAN_UNAVAILABLE is answered by GET /files/scanner-status, and only by it (D6). With the engine down, every other route answers as it always does — reservations are accepted and queue up, files wait in Scanning.
rejectionCode — why a file was refused after the upload
The content type is checked twice. At the reservation the declared type is checked against the profile, and a type outside the list is 422 FILE_CONTENT_TYPE_NOT_ALLOWED_UNPROCESSABLE before any URL is issued. After the upload, the scan job reads the real type from the content — by signature, by the OOXML package's [Content_Types].xml, or as text with no NUL byte.
That second refusal does not answer 422 (D4): the confirmation already answered 200 before anybody looked at the bytes. The record goes Scanning → Purged, the object is deleted, and the code goes onto the record as rejectionCode, which GET /files/{id} and the FILE_PURGED_CONFLICT of the other routes carry back. The tombstone keeps the sha256 of what was read, and its purgeReason is job:tipo-reprovado. rejectionCode holds a code of the §16 catalogue, never a vocabulary of its own.
The same happens when the object changed after the confirmation (RN-GF-18): the transit object no longer has the confirmed size, the provider refused to copy it on the version the scan described, or the scan read past sizeBytes or reached the end before it. The record goes Scanning → Purged with rejectionCode = FILE_OBJECT_CHANGED_UNPROCESSABLE, purgeReason = job:objeto-alterado and no originalFileName and no sha256, and the trail records a stored_file.integrity_incident. A confirmed object is rewritten only through a leaked URL or by a malicious client.
Download headers (D5)
The URL is followed straight to the bucket, which answers with the two headers the module signed into it:
Content-Disposition: attachment; filename*=UTF-8''<original name>— the browser saves, never renders;Content-Type: application/octet-stream— never the detected type, which a browser would display.
X-Content-Type-Options: nosniff is not part of the contract: a presigned URL cannot carry it on any of the three providers. It is a bucket or CDN setting — see Download.
Scanner status
GET /files/scanner-status answers the one reading the health check and the alerts also use:
| Field | Meaning |
|---|---|
engine | The engine and its version, from the daemon's VERSION reply |
databaseVersion | The signature database version |
databaseAgeHours | Age of the database, or null when unknown |
databaseStale | true above 48 hours, or when the age is unknown |
queueDepth | Files waiting for a verdict |
queueOldestItemAgeSeconds | Age of the oldest waiting file, or null when the queue is empty |
See Watching the scan for the alerts built on it.