fix(upload): enforce upload-session ownership (ISSUE-013) #869

Merged
chris merged 1 commit from fix/s1-upload-session-ownership into main 2026-09-25 20:58:19 +02:00
Owner

Lands the pre-existing SEC-4 fix (branch fix/s1-upload-session-ownership, originally d1599f94) rebased onto latest main.

What this does

  • get/receive/commit on /api/upload-sessions/{id} now verify session ownership before any read, staging write, or commit (ISSUE-013 / SEC-4).
  • UploadSessionService.requireOwnership: user principal must match created_by_user_id; API credential principal must match api_credential_id and hold media:upload scope (matches BearerTokenAuthenticationFilter's ApiCredentialPrincipal). No cross-access; Super Admin not exempt.
  • receive()/commit() call requireOwnership() as their first statement; get() is guarded in UploadFileController before returning session state.
  • Unknown session ids still surface as 404 (EmptyResultDataAccessException) before 403, per ADR 0097.

Tests

  • New UploadSessionOwnershipVerificationTest (10 cases, Testcontainers PostgreSQL): attacker user/credential denials, deny-before-staging (no bytes on disk, no DB row), scope gate, owner user + owner credential success paths, unknown-session 404.
  • UploadCommitServiceTest updated for the new commit(...) actor parameters.
  • Ran: rtk ./gradlew :apps:api:test --tests 'Upload' — BUILD SUCCESSFUL (UploadSessionOwnershipVerificationTest 10/10, UploadCommitServiceTest 5/5, UploadBatchCompletionServiceTest 4/4, UploadBatchNotificationMigrationTest 2/2, MultipartUploadLimitConfigurationTest 1/1).

Rebase resolutions

  • gradle.properties: kept main's 1.21.52 (branch's 1.21.25 patch bump dropped; version bumps happen separately per release policy).
  • UploadCommitServiceTest: merged main's notified_at schema column with the fix's api_credential_id column; updated main's new duplicate-only test call sites to the new commit(...) signature.
  • UploadSessionOwnershipVerificationTest: adapted to main's UploadBatchCompletionService wiring + notified_at column.
  • ADR renumbered 0095 -> 0097 (0095 taken on main by the per-face crops ADR).

Notes

  • Do NOT merge; orchestrator reviews.
  • Residual (reported, not fixed here): scope gate lives in the controller only, and UploadSessionService.get() stays unguarded for future callers.
Lands the pre-existing SEC-4 fix (branch fix/s1-upload-session-ownership, originally d1599f94) rebased onto latest main. ## What this does - get/receive/commit on /api/upload-sessions/{id} now verify session ownership before any read, staging write, or commit (ISSUE-013 / SEC-4). - UploadSessionService.requireOwnership: user principal must match created_by_user_id; API credential principal must match api_credential_id and hold media:upload scope (matches BearerTokenAuthenticationFilter's ApiCredentialPrincipal). No cross-access; Super Admin not exempt. - receive()/commit() call requireOwnership() as their first statement; get() is guarded in UploadFileController before returning session state. - Unknown session ids still surface as 404 (EmptyResultDataAccessException) before 403, per ADR 0097. ## Tests - New UploadSessionOwnershipVerificationTest (10 cases, Testcontainers PostgreSQL): attacker user/credential denials, deny-before-staging (no bytes on disk, no DB row), scope gate, owner user + owner credential success paths, unknown-session 404. - UploadCommitServiceTest updated for the new commit(...) actor parameters. - Ran: rtk ./gradlew :apps:api:test --tests '*Upload*' — BUILD SUCCESSFUL (UploadSessionOwnershipVerificationTest 10/10, UploadCommitServiceTest 5/5, UploadBatchCompletionServiceTest 4/4, UploadBatchNotificationMigrationTest 2/2, MultipartUploadLimitConfigurationTest 1/1). ## Rebase resolutions - gradle.properties: kept main's 1.21.52 (branch's 1.21.25 patch bump dropped; version bumps happen separately per release policy). - UploadCommitServiceTest: merged main's notified_at schema column with the fix's api_credential_id column; updated main's new duplicate-only test call sites to the new commit(...) signature. - UploadSessionOwnershipVerificationTest: adapted to main's UploadBatchCompletionService wiring + notified_at column. - ADR renumbered 0095 -> 0097 (0095 taken on main by the per-face crops ADR). ## Notes - Do NOT merge; orchestrator reviews. - Residual (reported, not fixed here): scope gate lives in the controller only, and UploadSessionService.get() stays unguarded for future callers.
fix(upload): enforce upload-session ownership (ISSUE-013)
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 6s
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 1m43s
b0210e8290
Lands the pre-existing SEC-4 fix (originally d1599f94) rebound onto latest
main: get/receive/commit on /api/upload-sessions/{id} now verify session
ownership before any read, staging write, or commit.

- UploadSessionService.requireOwnership: user principal must match
  created_by_user_id; API credential principal must match api_credential_id
  and hold media:upload; no cross-access; Super Admin not exempt.
- UploadFileController guards get(), and receive()/commit() call
  requireOwnership() as their first statement.
- Rebase resolutions: merge main's upload_sessions.notified_at test schema
  and UploadBatchCompletionService wiring; keep main's gradle version.
- ADR renumbered 0095 -> 0097 (0095 taken on main).
- KNOWN_ISSUES: ISSUE-013 moved to Archived (resolved).

Tests: :apps:api:test --tests '*Upload*' green.
chris merged commit af0a3bb423 into main 2026-09-25 20:58:19 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!869
No description provided.