feat(security): security controls — rate limits, headers, ZK canary, fuzz scaffold, KAT manifest (task 1.10 slice B/C) #70

Merged
amiryahaya merged 3 commits from feat/1.10-security-controls into main 2026-11-06 08:14:16 +01:00
Owner

Closes #25 — completes task 1.10 on top of #69 (authz matrix, SEC-03/04). Together the two PRs fulfill the Phase 1 exit gate: matrix 100% coverage incl. enforced H-1 dimensions, headers asserted, abuse paths rate-limited.

SEC-09 — security headers: SecurityHeadersMiddleware on every response (nosniff, X-Frame-Options DENY, Referrer-Policy strict-origin-when-cross-origin, CSP frame-ancestors 'none', COOP same-origin); HSTS only over forwarded-HTTPS. Full SPA CSP + COEP land with the web client (WEB-03/04, Phase 5). CI asserts headers on 200s AND 401s.

SEC-08/M-5 — tiered rate limiting: three new account-keyed partitions — email-velocity (invitation sends to arbitrary addresses, 10/h), wrap-fetch (KEY-13, 30/min), recovery-initiate (KEY-17, 5/h) — alongside the existing IP/DID partitions. Every rejection: 429 + Retry-After + a security.ratelimited audit row (Category=security, partition + path) via the rate limiter's OnRejected — brute-force campaigns are now visible in the admin audit log, best-effort so a tripped limiter can never 500.

Audit category: AuditLog.Category column (+ migration), surfaced in the admin audit-log endpoint with a ?category= filter and in each row's payload.

SEC-06 — ZK canary scan: key-material canary planted in a wrap upload; asserted absent from audit/activity/notification/user stores. Plaintext name canaries deliberately excluded as FIL-09 debt (documented in the class doc — never falsely red).

SEC-11 — fuzz scaffold: malformed JSON + hostile queries across 12 public protocol surfaces must yield 4xx/410, never 5xx. First-run findings, fixed here: POST /api/auth/ssdid/authenticate and POST /api/invitations/token/{token}/accept-with-wallet returned 500 on absent credential — now 400. security-nightly.yml runs the extended harness nightly.

SEC-05 — KAT/tamper manifest: one consolidated harness across all four enabled families (Ed25519/Ecdsa/MlDsa/KazSign): roundtrip + bit-flip tamper must fail closed.

Suite 837/0/39 Release ×3; coverage gate 84.50% ≥ 80. H-1 dimensions whose enforcement arrives with Phases 2/5/7 (view-only share, download kill-switch, web-disabled, step-up) remain declared-in-matrix (see #69).

Closes #25 — completes task 1.10 on top of #69 (authz matrix, SEC-03/04). Together the two PRs fulfill the Phase 1 exit gate: matrix 100% coverage incl. enforced H-1 dimensions, headers asserted, abuse paths rate-limited. **SEC-09 — security headers**: SecurityHeadersMiddleware on every response (nosniff, X-Frame-Options DENY, Referrer-Policy strict-origin-when-cross-origin, CSP `frame-ancestors 'none'`, COOP same-origin); HSTS only over forwarded-HTTPS. Full SPA CSP + COEP land with the web client (WEB-03/04, Phase 5). CI asserts headers on 200s AND 401s. **SEC-08/M-5 — tiered rate limiting**: three new account-keyed partitions — `email-velocity` (invitation sends to arbitrary addresses, 10/h), `wrap-fetch` (KEY-13, 30/min), `recovery-initiate` (KEY-17, 5/h) — alongside the existing IP/DID partitions. Every rejection: **429 + Retry-After** + a `security.ratelimited` audit row (**Category=security**, partition + path) via the rate limiter's OnRejected — brute-force campaigns are now visible in the admin audit log, best-effort so a tripped limiter can never 500. **Audit category**: `AuditLog.Category` column (+ migration), surfaced in the admin audit-log endpoint with a `?category=` filter and in each row's payload. **SEC-06 — ZK canary scan**: key-material canary planted in a wrap upload; asserted absent from audit/activity/notification/user stores. Plaintext name canaries deliberately excluded as FIL-09 debt (documented in the class doc — never falsely red). **SEC-11 — fuzz scaffold**: malformed JSON + hostile queries across 12 public protocol surfaces must yield 4xx/410, never 5xx. **First-run findings, fixed here**: POST /api/auth/ssdid/authenticate and POST /api/invitations/token/{token}/accept-with-wallet returned 500 on absent credential — now 400. `security-nightly.yml` runs the extended harness nightly. **SEC-05 — KAT/tamper manifest**: one consolidated harness across all four enabled families (Ed25519/Ecdsa/MlDsa/KazSign): roundtrip + bit-flip tamper must fail closed. Suite 837/0/39 Release ×3; coverage gate **84.50%** ≥ 80. H-1 dimensions whose enforcement arrives with Phases 2/5/7 (view-only share, download kill-switch, web-disabled, step-up) remain declared-in-matrix (see #69).
Closes #25

- SEC-09: SecurityHeadersMiddleware (nosniff, frame-deny, Referrer-Policy,
  CSP frame-ancestors, COOP; HSTS on forwarded-HTTPS only) + CI header assertions
- SEC-08/M-5: email-velocity (invitation sends, per-session), wrap-fetch
  (KEY-13) and recovery-initiate (KEY-17) partitions; 429 + Retry-After via
  OnRejected; every trip audited as security.ratelimited (Category=security)
- AuditLog.Category column (+ migration) + admin audit-log ?category= filter
  and category in the response projection
- SEC-06: ZkCanaryTests — key-material canary planted in a wrap upload must
  never surface in audit/activity/notifications/users stores (plaintext name
  canaries excluded as FIL-09 debt, documented)
- SEC-11: FuzzPropertyTests — malformed JSON/queries across 12 public protocol
  surfaces must yield 4xx/410, never 5xx; found and fixed two real 500s
  (POST /api/auth/ssdid/authenticate and accept-with-wallet with absent
  credential → now 400)
- SEC-05: CryptoKatManifestTests — consolidated sign/verify+tamper manifest
  across all four enabled families (Ed25519/Ecdsa/MlDsa/KazSign)
- security-nightly.yml: nightly extended harness (full suite + coverage gate)
chore: retrigger api-ci (SDK clone egress flake, cf. cd.yml precedent)
Some checks failed
API CI / build-and-test (pull_request) Failing after 18m14s
a9f5e38e38
fix(tests): KazSign KAT manifest skips when native lib unavailable (PlatformFacts, matches Providers/ suites)
All checks were successful
API CI / build-and-test (pull_request) Successful in 31m48s
11cc47f5b1
CI root cause from job log: runner lacks libcrypto.so.3 → libkazsign DllNotFound;
existing KazSign tests skip via PlatformFacts.SkipIfKazSignUnsupported — the
manifest now does the same instead of hard-failing.
Sign in to join this conversation.
No description provided.