Lane 8bb889338f
security: add CSRF token protection (signed double-submit cookie) (#702)
Add stateless CSRF protection using the Signed Double-Submit Cookie
pattern with HMAC-SHA256 signatures keyed on JWT_SECRET.

- New csrf.ts middleware: generates/validates signed tokens
- Token format: <nonce>.<hmac_signature>, base64url-encoded
- Header validation (X-CSRF-Token) with form body fallback (_csrf)
- Exempt: safe methods, auth routes, public forms, bearer-only requests
- Admin layout auto-attaches tokens to HTMX and fetch requests
- 40 unit tests + E2E test updates for CSRF compatibility

Fixes VULN-006

Co-authored-by: Mark McIntosh <mmcintosh@infowall.com>
2026-03-26 15:44:34 -07:00
..