1 ADR 0097 upload session operations bind to creator (user or api credential)
Forgejo Actions edited this page 2026-09-25 18:58:32 +00:00

ADR 0097: Upload session operations bind to creator (user or API credential)

Status: accepted Date: 2026-09-05

Context

SEC-4 (audit 2026-09-04, docs/dev/investigations/2026-09-04-full-audit.md): get/receive/commit on /api/upload-sessions/{id} never verified session ownership. Any authenticated principal holding a victim's session UUID could read session state, stage attacker bytes under the victim's session directory, and commit them — creating original_assets/media_items with the VICTIM's owner_id (media injected into victim's library). createForUser/createForApiCredential DID enforce ownership — asymmetry proved the check was forgotten, not undesigned.

Options Considered

Option Summary Benefits Costs / Risks
A Bind operations to upload_sessions.owner_id (media owner profile) Coarse, matches media ownership Wrong actor model: several user accounts may manage one owner profile; owner_id alone does not identify creator
B Bind to created_by_user_id for user principals; api_credential_id + media:upload scope for credential principals (chosen) Most restrictive; matches create-side symmetry; no cross-access A user cannot operate sessions created via their own API credential and vice versa
C Owner_id OR creator binding (either passes) Flexible Widest surface; defeats purpose of fix

Decision

Option B (user-approved, most restrictive). Every session operation (get, receive, commit) calls UploadSessionService.requireOwnership(uploadSessionId, actorUserId, apiCredentialId) as its FIRST statement, before any read/write/IO — in particular before receive() stages bytes to disk and before commit() writes markCommitStarted.

Rules:

  • User principal: require created_by_user_id == actorUserId.
  • API credential principal: require api_credential_id == credentialId AND credential.hasScope("media:upload") (mirrors createForApiCredential).
  • No cross-access between user principal and own credential's sessions (reversible decision; revisit if CLI/browser handoff needs it).
  • Super Admin NOT exempt.
  • Unknown session id: EmptyResultDataAccessException (404) surfaces before 403 — unchanged semantics, documented behavior.

Consequences

  • Foreign user / foreign credential / scope-less credential on any session op → AccessDeniedException → 403.
  • Cross-access limitation: user's browser sessions and credential's sessions are disjoint namespaces. Acceptable; handoff would need explicit transfer design.
  • Frontend/CLI unchanged: session id stays in URL, ownership enforced via authentication.