Batch A4: #2 scopes + subject template, #6 token revocation, #14 session hardening, #15 status exposure #52

Merged
amiryahaya merged 2 commits from fix/a4-authz-sessions into main 2026-11-15 07:12:26 +01:00
Owner

Batch A4: closes #2 (scopes + fixed subject template; identity proofing deferred), #6, #14, #15.

Changes

  • #2 Per-client scopes (enroll, renew, revoke, status, status_full, admin) stored on the client record, read on every request and enforced per route (403 otherwise). Certificates now carry only CN, serialNumber and C; CSR O/OU/email/locality and all extensions (SAN) are ignored. Clients are treated as trusted RAs: no per-IC binding and no out-of-band identity proofing here.
  • #6 Tokens are valid only with an active stored row (indexed jti). New admin endpoints revoke a token or suspend/reactivate a client. An admin cannot suspend itself.
  • #14 Encrypted, secure, http-only session cookie; session renewed on login; POST /logout with CSRF (GET removed); 8h session TTL.
  • #15 /status omits x509Cert without status_full; per-client throttle (60/60s) returns 429.

Behaviour changes / deploy notes

  • Existing clients are migrated (transform_table) to the default cert scopes: they lose the certificate in /status until granted status_full, and have no admin.
  • Prod has no API to create clients or change scopes; an operator creates an admin client in iex (see AGENTS.md).
  • GET /logout is gone. The session cookie is secure at compile time, so a release is HTTPS-only (dev config disables it).
  • Not updated: OpenAPI spec, shell scripts. Cookie sessions are not server-revocable (documented).

Tests and coverage

mix test: 256/258 pass. The 2 failures (TrustgateLifecycleTest) also fail on main.
Coverage of changed modules: Scopes 100%, RequestThrottle 100%, RequireScope 100%, RequireSessionAuth 100%, AdminController 82%, Token 91%, PageController 91%. Project total 72.1% (no project minimum stated; changed code above 80% except the jti/client Mnesia data-store modules at 74%/73%, whose untested lines are pre-existing code paths).

Review

Pass 1 (complexity) clean. Pass 2 (security review): no critical issues; fixed the per-call index check and recreate_client scope loss; documented the rest.

🤖 Generated with Claude Code

Batch A4: closes #2 (scopes + fixed subject template; identity proofing deferred), #6, #14, #15. ## Changes - **#2** Per-client scopes (`enroll`, `renew`, `revoke`, `status`, `status_full`, `admin`) stored on the client record, read on every request and enforced per route (403 otherwise). Certificates now carry only CN, serialNumber and C; CSR O/OU/email/locality and all extensions (SAN) are ignored. Clients are treated as trusted RAs: no per-IC binding and no out-of-band identity proofing here. - **#6** Tokens are valid only with an `active` stored row (indexed `jti`). New admin endpoints revoke a token or suspend/reactivate a client. An admin cannot suspend itself. - **#14** Encrypted, secure, http-only session cookie; session renewed on login; `POST /logout` with CSRF (GET removed); 8h session TTL. - **#15** `/status` omits `x509Cert` without `status_full`; per-client throttle (60/60s) returns 429. ## Behaviour changes / deploy notes - Existing clients are migrated (transform_table) to the default cert scopes: they lose the certificate in `/status` until granted `status_full`, and have no `admin`. - Prod has no API to create clients or change scopes; an operator creates an admin client in iex (see AGENTS.md). - `GET /logout` is gone. The session cookie is `secure` at compile time, so a release is HTTPS-only (dev config disables it). - Not updated: OpenAPI spec, shell scripts. Cookie sessions are not server-revocable (documented). ## Tests and coverage `mix test`: 256/258 pass. The 2 failures (`TrustgateLifecycleTest`) also fail on main. Coverage of changed modules: Scopes 100%, RequestThrottle 100%, RequireScope 100%, RequireSessionAuth 100%, AdminController 82%, Token 91%, PageController 91%. Project total 72.1% (no project minimum stated; changed code above 80% except the jti/client Mnesia data-store modules at 74%/73%, whose untested lines are pre-existing code paths). ## Review Pass 1 (complexity) clean. Pass 2 (security review): no critical issues; fixed the per-call index check and `recreate_client` scope loss; documented the rest. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
#2: per-client scopes (enroll/renew/revoke/status/status_full/admin) enforced per route,
    fixed CN/serialNumber/C subject template, CSR SANs/O/OU/email ignored.
#6: tokens verified against their stored row by indexed jti; admin endpoints to
    revoke tokens and suspend/reactivate clients.
#14: encrypted+secure session cookie, renew on login, POST logout with CSRF, session TTL.
#15: /status omits the certificate without status_full; per-client throttle.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix(security): guard jti index check, keep scopes on client recreate, document A4
All checks were successful
Lint / lint (pull_request) Successful in 2m28s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 21s
Security / Secret scan (gitleaks) (pull_request) Successful in 12s
Unit tests / test (pull_request) Successful in 3m38s
ffda04c5cb
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.