fix(files/recovery): M1-audit MUSTs — blob window, size cap, probe evidence (#73 #74 #75) #77

Merged
amiryahaya merged 1 commit from fix/m1-audit-musts-73-75 into main 2026-11-06 16:31:59 +01:00
Owner

Closes #73, #74, #75 (M1-close ponytail-audit MUSTs, issue #65 — gated into early M2)

#73 — UpdateFile status whitelist

Only legal transition is pending → uploaded (creator-driven). Flipping back to pending re-armed the unauthenticated blob window; arbitrary strings corrupted the state machine — both now 400 with state unchanged. Test proves the blob PUT stays closed after a rejected flip.

#75 — UploadBlob enforces declared size

Content-Length pre-check + SizeLimitedStream aborting the storage copy mid-stream (the sink never writes past the cap). BlobSize <= 0 legacy rows fall back to the CreateUploadUrl 5 GB cap. Rejects 413 PayloadTooLarge (new AppError.PayloadTooLarge). Interim containment until UPL-02 signed upload tokens (Phase 7). Counts toward the Phase 7 quota work.

#74 — anonymous probes leave evidence

FileActivity.ActorId → nullable (entity + service + migration); GetRecoveryShare's failed branch logs a NULL actor instead of Guid.Empty (FK-fail silently swallowed by the fire-and-forget = zero probe evidence — same class as the #32 audit-sink bug). Probes for unknown DIDs now land in file_activities with actor_id IS NULL + the probed DID in details.

Also fixed (exposed by this branch)

RateLimitSecurityTests.EmailVelocity asserted an unordered FirstOrDefault over security.ratelimited rows — sibling limiter tests in the same fixture also write those rows → intermittent Debug-order gate failure (not reproducible on clean main). Assertion now scoped to the email-velocity partition.

Verification

TDD: 6 tests first, RED ×5, then implemented. Suite 853 / 0 failed / 39 skipped (Release ×2 + Debug ×2) · coverage gate 85.07% ≥ 80

Closes #73, #74, #75 (M1-close ponytail-audit MUSTs, issue #65 — gated into early M2) ## #73 — UpdateFile status whitelist Only legal transition is **pending → uploaded** (creator-driven). Flipping back to pending re-armed the unauthenticated blob window; arbitrary strings corrupted the state machine — both now **400** with state unchanged. Test proves the blob PUT stays closed after a rejected flip. ## #75 — UploadBlob enforces declared size **Content-Length pre-check + `SizeLimitedStream`** aborting the storage copy mid-stream (the sink never writes past the cap). `BlobSize <= 0` legacy rows fall back to the CreateUploadUrl 5 GB cap. Rejects **413 PayloadTooLarge** (new `AppError.PayloadTooLarge`). Interim containment until UPL-02 signed upload tokens (Phase 7). Counts toward the Phase 7 quota work. ## #74 — anonymous probes leave evidence `FileActivity.ActorId` → **nullable** (entity + service + migration); `GetRecoveryShare`'s failed branch logs a NULL actor instead of `Guid.Empty` (FK-fail silently swallowed by the fire-and-forget = zero probe evidence — same class as the #32 audit-sink bug). Probes for unknown DIDs now land in `file_activities` with `actor_id IS NULL` + the probed DID in details. ## Also fixed (exposed by this branch) `RateLimitSecurityTests.EmailVelocity` asserted an **unordered** `FirstOrDefault` over `security.ratelimited` rows — sibling limiter tests in the same fixture also write those rows → intermittent Debug-order gate failure (not reproducible on clean main). Assertion now scoped to the email-velocity partition. ## Verification TDD: 6 tests first, **RED ×5**, then implemented. Suite **853 / 0 failed / 39 skipped** (Release ×2 + Debug ×2) · coverage gate **85.07% ≥ 80**
fix(files/recovery): M1-audit MUSTs — status whitelist, blob size cap, probe evidence (#73 #74 #75)
All checks were successful
API CI / build-and-test (pull_request) Successful in 36m5s
4e6e5a71b9
#73 — UpdateFile status whitelist (UpdateFile.cs):
- only legal transition is pending -> uploaded (creator-driven, after the
  blob lands); flipping back to pending re-armed the unauthenticated blob
  window, arbitrary strings corrupted the state machine — both now 400
  with the state unchanged (test proves blob PUT stays closed)

#75 — UploadBlob enforces the DECLARED size (UploadBlob.cs):
- Content-Length pre-check + SizeLimitedStream aborting the storage copy
  mid-stream (the sink never writes past the cap); BlobSize<=0 legacy rows
  fall back to the CreateUploadUrl 5 GB hard cap; rejects 413
  PayloadTooLarge (new AppError factory); interim containment until UPL-02
  signed upload tokens (Phase 7)

#74 — anonymous recovery-share probes leave evidence:
- FileActivity.ActorId is now nullable (entity + service + migration
  FileActivityActorNullable); GetRecoveryShare failed branch logs with a
  NULL actor instead of Guid.Empty (FK-fail swallowed by fire-and-forget =
  zero probe evidence, same class as the #32 audit-sink bug)

Also fixes the Debug-order flake this branch exposed:
RateLimitSecurityTests.EmailVelocity asserted an unordered
FirstOrDefault over security.ratelimited rows — sibling limiter tests in
the same fixture also write those rows; assertion now scoped to the
email-velocity partition (root cause of the gate's intermittent Debug
failure, not reproducible on clean main).

TDD: 6 tests first, RED x5 (happy path already green), then implemented.
Suite 853 / 0 failed / 39 skipped (Release x2 + Debug x2); gate 85.07%.
Sign in to join this conversation.
No description provided.