M1-audit SHOULD batch: 16 deferred findings (token-in-query, folder access consistency, placeholder devices, ML-DSA-87 buffer, tx boundaries, …) #95

Open
opened 2026-11-07 08:41:31 +01:00 by amiryahaya · 2 comments
Owner

Batched SHOULD-fix findings from the M1 closure audit (#84 umbrella). Triage: fix opportunistically at M1.5, re-rank at the #66 audit. Each entry: finding / smallest fix.

  1. OIDC session token in redirect QUERY string (OidcCallback.cs:159-179) — tokens persist in browser history + proxy logs. Fix: URL fragment or one-time exchange code.
  2. CreateFolder skips parent write-access check (CreateFolder.cs:41-44) — any member can create an owned subfolder inside someone's private folder. Fix: same access rule as UploadFile (owner/write-share/tenant-root).
  3. Read paths lack the B-7 tenant-root policy (ListFiles.cs:28, DownloadFile.cs:34, GetFolder.cs:28) — members can upload to the org root but 403 listing it. Fix: shared HasFolderAccessAsync (owner ∨ share ∨ IsTenantRootShared) on all folder surfaces.
  4. Placeholder device fingerprints never bound (AuthorizePairing.cs:190, RekeyRecovery.cs:117) — paired/recovered devices can never resolve themselves (wrap replace, approve, GetCurrentDevice all fail). Fix: bind on first session resolution or drop the placeholder pattern.
  5. WrapSignature 4096-byte buffer rejects ML-DSA-87 (WrapSignature.cs:77) — 4627-byte signatures never verify; strongest registered PQC algorithm silently locked out. Fix: algorithm-sized buffer (8192 flat is fine). Add MlDsa case to WrapTestSigning.
  6. Pairing approve + rekey lack transaction boundaries (AuthorizePairing.cs:175-213, RekeyRecovery.cs:109-145) — DB failure between consume/delete and insert burns the challenge / leaves zero wraps. Fix: BeginTransactionAsync like CompleteRecovery.
  7. Recovery approve/expire flips use stale tracked entities (ApproveRecoveryRequest.cs:76-93, 31-37) — concurrent trustees can overwrite Completed→Approved (re-completable recovery). Fix: guarded ExecuteUpdate WHERE Status=Pending.
  8. kdf_salt invalid base64 → 500 (KeyFeature.cs:203 ParseOptionalBase64 on 3 endpoints; outside the signed payload) — Fix: TryDecodeBase64 → 400.
  9. Unlink email doesn't stop email+TOTP login (UnlinkLogin.cs:26 counts Logins; EmailLogin/TotpVerify authenticate by Users.Email) — guard and login path consult different tables. Fix: treat email+TOTP as a login method in the unlink guard.
  10. Wallet Authenticate skips suspended check (Authenticate.cs:46-59) — suspended wallet users "log in successfully" then 403 everywhere. Fix: one status check.
  11. Legacy multipart upload writes blob before DB commit (UploadFile.cs:77-97) + no pending-upload sweep — orphan blobs + permanently-pending rows. Fix: daily BackgroundService deleting pending >24h + their blobs.
  12. Share revoke requires SharedById; write-holders can re-share (RevokeShare.cs:24, CreateShare.cs:63) — owner can't revoke a re-share. Also CreateShare skips recipient tenant check. Fix: allow resource owner; require recipient.TenantId == user.TenantId.
  13. ListFiles ignores page/pageSize/search params (ListFiles.cs:12-14, 38-41) — full materialization on the hottest endpoint. Fix: Skip/Take + filter.
  14. Share/folder listings materialize full sets to filter expiry client-side (ListReceivedShares.cs:24-44, ListCreatedShares.cs:21-39, ListFolders.cs:41-49, GetFolderChildren.cs:27-33) — push filters into the query on Postgres.
  15. ENABLE_AUTO_MIGRATE=true baked into the root Dockerfile (Dockerfile:31) — defeats compose.yml's "migrations NOT automatic in Production" runbook; two replicas starting together race MigrateAsync. Fix: remove the ENV line; set per-deployment.
  16. compose.yml: NullEmailService silently active + server identity key plaintext — no Email__ApiKey → OTPs log to console, invitations/approvals never mail; no Ssdid__SecretPath → signing key plaintext on a volume (compose.local.yml shows the pattern). Fix: required Email__ApiKey + secrets block.
  17. FileHelper.BuildFileDto leaks StoragePath (server disk layout) to every client + divergent legacy/chunked upload validation (UploadFile vs CreateUploadUrl) — the divergence behind several M1-audit findings. Fix: drop StoragePath from DTO; gate legacy UploadFile behind a flag.
  18. Test gaps (each maps to a live bug class): upload-url→blob→update→list flow; auth-partition rate limit; approve slug-collision; wrong-length token proof (currently 500); provisioning concurrent-unique branch; MlDsa signature case; paired-device self-resolution; approve→complete→approve interleave.
Batched SHOULD-fix findings from the M1 closure audit (#84 umbrella). Triage: fix opportunistically at M1.5, re-rank at the #66 audit. Each entry: finding / smallest fix. 1. **OIDC session token in redirect QUERY string** (OidcCallback.cs:159-179) — tokens persist in browser history + proxy logs. Fix: URL fragment or one-time exchange code. 2. **CreateFolder skips parent write-access check** (CreateFolder.cs:41-44) — any member can create an owned subfolder inside someone's private folder. Fix: same access rule as UploadFile (owner/write-share/tenant-root). 3. **Read paths lack the B-7 tenant-root policy** (ListFiles.cs:28, DownloadFile.cs:34, GetFolder.cs:28) — members can upload to the org root but 403 listing it. Fix: shared HasFolderAccessAsync (owner ∨ share ∨ IsTenantRootShared) on all folder surfaces. 4. **Placeholder device fingerprints never bound** (AuthorizePairing.cs:190, RekeyRecovery.cs:117) — paired/recovered devices can never resolve themselves (wrap replace, approve, GetCurrentDevice all fail). Fix: bind on first session resolution or drop the placeholder pattern. 5. **WrapSignature 4096-byte buffer rejects ML-DSA-87** (WrapSignature.cs:77) — 4627-byte signatures never verify; strongest registered PQC algorithm silently locked out. Fix: algorithm-sized buffer (8192 flat is fine). Add MlDsa case to WrapTestSigning. 6. **Pairing approve + rekey lack transaction boundaries** (AuthorizePairing.cs:175-213, RekeyRecovery.cs:109-145) — DB failure between consume/delete and insert burns the challenge / leaves zero wraps. Fix: BeginTransactionAsync like CompleteRecovery. 7. **Recovery approve/expire flips use stale tracked entities** (ApproveRecoveryRequest.cs:76-93, 31-37) — concurrent trustees can overwrite Completed→Approved (re-completable recovery). Fix: guarded ExecuteUpdate WHERE Status=Pending. 8. **kdf_salt invalid base64 → 500** (KeyFeature.cs:203 ParseOptionalBase64 on 3 endpoints; outside the signed payload) — Fix: TryDecodeBase64 → 400. 9. **Unlink email doesn't stop email+TOTP login** (UnlinkLogin.cs:26 counts Logins; EmailLogin/TotpVerify authenticate by Users.Email) — guard and login path consult different tables. Fix: treat email+TOTP as a login method in the unlink guard. 10. **Wallet Authenticate skips suspended check** (Authenticate.cs:46-59) — suspended wallet users "log in successfully" then 403 everywhere. Fix: one status check. 11. **Legacy multipart upload writes blob before DB commit** (UploadFile.cs:77-97) + no pending-upload sweep — orphan blobs + permanently-pending rows. Fix: daily BackgroundService deleting pending >24h + their blobs. 12. **Share revoke requires SharedById; write-holders can re-share** (RevokeShare.cs:24, CreateShare.cs:63) — owner can't revoke a re-share. Also CreateShare skips recipient tenant check. Fix: allow resource owner; require recipient.TenantId == user.TenantId. 13. **ListFiles ignores page/pageSize/search params** (ListFiles.cs:12-14, 38-41) — full materialization on the hottest endpoint. Fix: Skip/Take + filter. 14. **Share/folder listings materialize full sets to filter expiry client-side** (ListReceivedShares.cs:24-44, ListCreatedShares.cs:21-39, ListFolders.cs:41-49, GetFolderChildren.cs:27-33) — push filters into the query on Postgres. 15. **ENABLE_AUTO_MIGRATE=true baked into the root Dockerfile** (Dockerfile:31) — defeats compose.yml's "migrations NOT automatic in Production" runbook; two replicas starting together race MigrateAsync. Fix: remove the ENV line; set per-deployment. 16. **compose.yml: NullEmailService silently active + server identity key plaintext** — no Email__ApiKey → OTPs log to console, invitations/approvals never mail; no Ssdid__SecretPath → signing key plaintext on a volume (compose.local.yml shows the pattern). Fix: required Email__ApiKey + secrets block. 17. **FileHelper.BuildFileDto leaks StoragePath** (server disk layout) to every client + divergent legacy/chunked upload validation (UploadFile vs CreateUploadUrl) — the divergence behind several M1-audit findings. Fix: drop StoragePath from DTO; gate legacy UploadFile behind a flag. 18. **Test gaps** (each maps to a live bug class): upload-url→blob→update→list flow; auth-partition rate limit; approve slug-collision; wrong-length token proof (currently 500); provisioning concurrent-unique branch; MlDsa signature case; paired-device self-resolution; approve→complete→approve interleave.
Author
Owner

Re-verified all 18 items against main @ 7f853c8 (2026-11-11, 4 parallel code sweeps + spot-checks). Line refs below are stale from Nov 7; item numbers follow the issue body.

FIXED since filing (2):

  • Item 10 (wallet suspended bypass): #104 landed — Authenticate.cs rejects non-Active before minting (403), plus MFA gate for TOTP admins; global session cap in PostgresSessionStore (MaxSessions 10000). Test: M15P0FixTests.SuspendedWallet_Authenticate_Returns403.
  • Item 15 (ENABLE_AUTO_MIGRATE in root Dockerfile): root Dockerfile deleted in PR #128; remaining Containerfiles carry no ENABLE_AUTO_MIGRATE; compose.yml documents migrations-not-automatic-in-prod and Program.cs honors env-only-true. Runbook respected.

PARTIAL (2):

  • Item 16 (compose): Docker secret ssdid-identity + Ssdid__SecretPath fixed in compose.local.yml; PROD compose.yml still mounts no secret (identity plaintext in named volume) and Email__ApiKey is absent — NullEmailService silently active in prod, OTPs log to console.
  • Item 18 (test gaps): exists — (a) chunked full-flow M1P0FixTests.ChunkedUpload_AppearsInListing, (f) MlDsaProviderTests + CryptoKatManifestTests, (g) DeviceKeyWrapTests pairing flow (surface trimmed, no self-resolution step). Partial — (d) wrong-CONTENT proof 403 tested, wrong-LENGTH not; (e) concurrent tests exist on other surfaces, wallet-provisioning race is sequential by design. Missing — (b) auth-partition 429 (declared config-only at Testing permit levels), (c) approve slug-collision suffixing, (h) approve-complete-approve interleave.

STILL LIVE (13): items 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 17 (plus prod half of 16 and gaps c/h of 18). Notable: PR #80 added IsTenantRootSharedAsync to the WRITE paths only — ListFiles/DownloadFile/GetFolder still 403 org members reading the org root they can write to; WrapSignature.cs still decodes signatures into a 4096-byte buffer (ML-DSA-87 ~4627B silently rejected, no MlDsa case in WrapTestSigning); ParseOptionalBase64 still throws FormatException on bad kdf_salt (500, while TryDecodeBase64 sits unused next to it); AuthorizePairing challenge consume is now atomic but the wrap insert is a separate SaveChanges (burned challenge on mid-failure); approve/reject/cancel still flip via stale tracked entities.

DISPOSITION: items 5 + 8 (small, security-adjacent) + several #96 siblings land in the hygiene batch PR today. The rest re-ranks into milestone M3 backlog: folder access policy unification (2+3), placeholder fingerprint binding (4), pairing/rekey tx boundaries + guarded flips (6+7), legacy OIDC token-in-query (1 — decide retire-legacy-flow vs fragment), blob-before-commit + pending sweep (11), share ownership/tenant checks (12), paging + query-push (13+14), StoragePath DTO leak + legacy-upload flag (17), unlink email+TOTP guard (9), prod compose secret + email fail-fast (16), test gaps c/h (18).

Re-verified all 18 items against main @ 7f853c8 (2026-11-11, 4 parallel code sweeps + spot-checks). Line refs below are stale from Nov 7; item numbers follow the issue body. FIXED since filing (2): - Item 10 (wallet suspended bypass): #104 landed — Authenticate.cs rejects non-Active before minting (403), plus MFA gate for TOTP admins; global session cap in PostgresSessionStore (MaxSessions 10000). Test: M15P0FixTests.SuspendedWallet_Authenticate_Returns403. - Item 15 (ENABLE_AUTO_MIGRATE in root Dockerfile): root Dockerfile deleted in PR #128; remaining Containerfiles carry no ENABLE_AUTO_MIGRATE; compose.yml documents migrations-not-automatic-in-prod and Program.cs honors env-only-true. Runbook respected. PARTIAL (2): - Item 16 (compose): Docker secret ssdid-identity + Ssdid__SecretPath fixed in compose.local.yml; PROD compose.yml still mounts no secret (identity plaintext in named volume) and Email__ApiKey is absent — NullEmailService silently active in prod, OTPs log to console. - Item 18 (test gaps): exists — (a) chunked full-flow M1P0FixTests.ChunkedUpload_AppearsInListing, (f) MlDsaProviderTests + CryptoKatManifestTests, (g) DeviceKeyWrapTests pairing flow (surface trimmed, no self-resolution step). Partial — (d) wrong-CONTENT proof 403 tested, wrong-LENGTH not; (e) concurrent tests exist on other surfaces, wallet-provisioning race is sequential by design. Missing — (b) auth-partition 429 (declared config-only at Testing permit levels), (c) approve slug-collision suffixing, (h) approve-complete-approve interleave. STILL LIVE (13): items 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 17 (plus prod half of 16 and gaps c/h of 18). Notable: PR #80 added IsTenantRootSharedAsync to the WRITE paths only — ListFiles/DownloadFile/GetFolder still 403 org members reading the org root they can write to; WrapSignature.cs still decodes signatures into a 4096-byte buffer (ML-DSA-87 ~4627B silently rejected, no MlDsa case in WrapTestSigning); ParseOptionalBase64 still throws FormatException on bad kdf_salt (500, while TryDecodeBase64 sits unused next to it); AuthorizePairing challenge consume is now atomic but the wrap insert is a separate SaveChanges (burned challenge on mid-failure); approve/reject/cancel still flip via stale tracked entities. DISPOSITION: items 5 + 8 (small, security-adjacent) + several #96 siblings land in the hygiene batch PR today. The rest re-ranks into milestone M3 backlog: folder access policy unification (2+3), placeholder fingerprint binding (4), pairing/rekey tx boundaries + guarded flips (6+7), legacy OIDC token-in-query (1 — decide retire-legacy-flow vs fragment), blob-before-commit + pending sweep (11), share ownership/tenant checks (12), paging + query-push (13+14), StoragePath DTO leak + legacy-upload flag (17), unlink email+TOTP guard (9), prod compose secret + email fail-fast (16), test gaps c/h (18).
Author
Owner

PR #145 MERGED (squash 4c87be7 on main; PR runs build-and-test 38253 + security-scan 38254 green, polled before merge). Items 5 (ML-DSA-87 wrap-signature buffer 8192 + MlDsa87 test identity) and 8 (KeyFeature.ParseKdfSalt -> 400 on wrap upload / pairing approve / recovery rekey) are FIXED — strike from this batch. Suite 987/0/39 Release, coverage gate 87.20%. Remainder stays M3 per the triage comment above.

PR #145 MERGED (squash 4c87be7 on main; PR runs build-and-test 38253 + security-scan 38254 green, polled before merge). Items 5 (ML-DSA-87 wrap-signature buffer 8192 + MlDsa87 test identity) and 8 (KeyFeature.ParseKdfSalt -> 400 on wrap upload / pairing approve / recovery rekey) are FIXED — strike from this batch. Suite 987/0/39 Release, coverage gate 87.20%. Remainder stays M3 per the triage comment above.
Sign in to join this conversation.
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
primatekuntech/failsulit#95
No description provided.