M1.5-audit SHOULD batch: 15 deferred findings (SA race, budget sweep, LastUsedAt, issuer fail-open, M2M denial audit, …) #110

Closed
opened 2026-11-07 19:23:26 +01:00 by amiryahaya · 1 comment
Owner

Batched SHOULD-fix findings from the M1.5 close audit (#66 umbrella #101). Re-rank at the next audit. Each entry: finding / smallest fix.

  1. JIT SA provisioning race → 500 (UserProvisioningService.cs:196-220): parallel first calls with the same sub hit the unique Did index; wrap SaveChanges in the IsUniqueConstraintViolation catch → refetch.
  2. M2M auth failure budget never sweeps (M2mAuthMiddleware.cs:27,121-141): static per-IP dictionary grows forever; sweep expired windows in RecordAuthFailure.
  3. LastUsedAt UPDATE on the auth hot path (ApiKeyAuthentication.cs:43-44): write only when stale (>1 min) to stop row-lock contention scaling with traffic.
  4. M2m:Issuer unset → issuer validation silently skipped (OidcTokenValidator.cs:131): add a Production startup warning/fail in the Program warnings block.
  5. M2M denials leave no audit trail (M2mAuthMiddleware.cs:54-108): 403 insufficient_scope and 401s are response-only; audit m2m.scope.denied/m2m.auth.failed like the rate-limit rejections.
  6. SA scopes: files:write in the default set + frozen at provisioning (M2mAuthMiddleware.cs:64, UserProvisioningService.cs:198-202): drop write from the default; refresh from config on validation or add an admin surface.
  7. TOTP verify enumeration (TotpVerify.cs:40/43/84): three distinct outcomes census accounts + TOTP enrollment; uniform 401 body. Secondary: TotpRecovery.cs:52 send-failure branch, EmailRegister.cs:57 invite-gated 409.
  8. EmailRegisterVerify: no rate limiter + OTP consumed before invitation validation (EmailRegisterVerify.cs:17-19, 38): add auth-otp partition; validate invitation first (stops free OTP-burn on onboarding).
  9. TOTP decrypt/JSON exceptions → 500 lockout (TotpVerify.cs:63,70; TotpSetupConfirm.cs:39): catch → 401 + security.totp_decrypt_failed audit (key rotation becomes a silent TOTP-population lockout today).
  10. HMAC replay cache process-local (HmacAuthMiddleware.cs:44-70,149): replays survive restart within the ±5 min window; persist last-seen signature on ExtensionServices.
  11. Unscoped ApiKeys bulk update in M2mAccessTests (M2mAccessTests.cs:70-73): add Where(k => k.Id == mintedId) like ApiKeysTests does (order-dependent flake risk).
  12. Cross-tenant M2M test gap (M2mFeature.cs WHERE clauses are the only tenant guard): tenant-B key reading tenant-A folders/activity test.
  13. AuthzMatrix constants drift (AuthzMatrixTests.cs:49-52,287-305): import TenantScopedPrefixes/AllowedMfaPaths from the middleware instead of re-declaring; justification check is length-only.
  14. KAZSIGN_VERSION + SDK clone duplicated between api-ci/cd (api-ci.yml:21,33-41 vs cd.yml:15,29-38): extract a composite action so CI and CD test the same native crypto version.
  15. Root Dockerfile unreferenced drift (wrong port, LD_LIBRARY_PATH pointing at an empty dir, contradictory auto-migrate flag): delete or collapse into the Containerfile.
Batched SHOULD-fix findings from the M1.5 close audit (#66 umbrella #101). Re-rank at the next audit. Each entry: finding / smallest fix. 1. **JIT SA provisioning race → 500** (UserProvisioningService.cs:196-220): parallel first calls with the same sub hit the unique Did index; wrap SaveChanges in the IsUniqueConstraintViolation catch → refetch. 2. **M2M auth failure budget never sweeps** (M2mAuthMiddleware.cs:27,121-141): static per-IP dictionary grows forever; sweep expired windows in RecordAuthFailure. 3. **LastUsedAt UPDATE on the auth hot path** (ApiKeyAuthentication.cs:43-44): write only when stale (>1 min) to stop row-lock contention scaling with traffic. 4. **M2m:Issuer unset → issuer validation silently skipped** (OidcTokenValidator.cs:131): add a Production startup warning/fail in the Program warnings block. 5. **M2M denials leave no audit trail** (M2mAuthMiddleware.cs:54-108): 403 insufficient_scope and 401s are response-only; audit `m2m.scope.denied`/`m2m.auth.failed` like the rate-limit rejections. 6. **SA scopes: files:write in the default set + frozen at provisioning** (M2mAuthMiddleware.cs:64, UserProvisioningService.cs:198-202): drop write from the default; refresh from config on validation or add an admin surface. 7. **TOTP verify enumeration** (TotpVerify.cs:40/43/84): three distinct outcomes census accounts + TOTP enrollment; uniform 401 body. Secondary: TotpRecovery.cs:52 send-failure branch, EmailRegister.cs:57 invite-gated 409. 8. **EmailRegisterVerify: no rate limiter + OTP consumed before invitation validation** (EmailRegisterVerify.cs:17-19, 38): add auth-otp partition; validate invitation first (stops free OTP-burn on onboarding). 9. **TOTP decrypt/JSON exceptions → 500 lockout** (TotpVerify.cs:63,70; TotpSetupConfirm.cs:39): catch → 401 + security.totp_decrypt_failed audit (key rotation becomes a silent TOTP-population lockout today). 10. **HMAC replay cache process-local** (HmacAuthMiddleware.cs:44-70,149): replays survive restart within the ±5 min window; persist last-seen signature on ExtensionServices. 11. **Unscoped ApiKeys bulk update in M2mAccessTests** (M2mAccessTests.cs:70-73): add Where(k => k.Id == mintedId) like ApiKeysTests does (order-dependent flake risk). 12. **Cross-tenant M2M test gap** (M2mFeature.cs WHERE clauses are the only tenant guard): tenant-B key reading tenant-A folders/activity test. 13. **AuthzMatrix constants drift** (AuthzMatrixTests.cs:49-52,287-305): import TenantScopedPrefixes/AllowedMfaPaths from the middleware instead of re-declaring; justification check is length-only. 14. **KAZSIGN_VERSION + SDK clone duplicated between api-ci/cd** (api-ci.yml:21,33-41 vs cd.yml:15,29-38): extract a composite action so CI and CD test the same native crypto version. 15. **Root Dockerfile unreferenced drift** (wrong port, LD_LIBRARY_PATH pointing at an empty dir, contradictory auto-migrate flag): delete or collapse into the Containerfile.
Author
Owner

ALL ITEMS RESOLVED — closing. Landed across: PR #114 (items 4/5/7/8 identity batch), #120 slice 3 (item 2 budget sweep — rows + sweep), and two batch PRs today: #127 (212ca00) items 1 (SA race refetch), 3 (LastUsedAt >1min throttle), 4 (Production M2m:Issuer warning), 5 (m2m.auth.failed / m2m.scope.denied security audits), 6 (default SA scopes drop files:write — DefaultServiceAccountScopes const), 9b (TotpSetupConfirm decrypt → 401 + audit), 10 (HMAC dual-layer replay: LastSignature/LastSignatureAt on ExtensionService, restart-surviving); #128 items 11 (minted-key scoping), 12 (cross-tenant M2M pin), 13 (authz constants imported from middleware + justification check upgraded beyond length-only — caught a real stub), 14 (kaz-setup composite action — api-ci/cd share one SDK+libkazsign source), 15 (root Dockerfile deleted). Reviewed no-fix: #7-secondary (TotpRecovery send-failure 503 + EmailRegister invite-gated 409 — both only reachable by legitimate holders, documented in PR #127). Final: suite 946/0/39, coverage 87.77%.

ALL ITEMS RESOLVED — closing. Landed across: PR #114 (items 4/5/7/8 identity batch), #120 slice 3 (item 2 budget sweep — rows + sweep), and two batch PRs today: **#127 (212ca00)** items 1 (SA race refetch), 3 (LastUsedAt >1min throttle), 4 (Production M2m:Issuer warning), 5 (m2m.auth.failed / m2m.scope.denied security audits), 6 (default SA scopes drop files:write — DefaultServiceAccountScopes const), 9b (TotpSetupConfirm decrypt → 401 + audit), 10 (HMAC dual-layer replay: LastSignature/LastSignatureAt on ExtensionService, restart-surviving); **#128** items 11 (minted-key scoping), 12 (cross-tenant M2M pin), 13 (authz constants imported from middleware + justification check upgraded beyond length-only — caught a real stub), 14 (kaz-setup composite action — api-ci/cd share one SDK+libkazsign source), 15 (root Dockerfile deleted). Reviewed no-fix: #7-secondary (TotpRecovery send-failure 503 + EmailRegister invite-gated 409 — both only reachable by legitimate holders, documented in PR #127). Final: suite 946/0/39, coverage 87.77%.
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#110
No description provided.