Commit f3f2b61
feat(auth): add CSRF tokens, styled 403, login rate-limit, mr user CLI, per-role E2E
Implements the remaining deferred hardening/completeness groups for the opt-in
user-accounts/RBAC feature. All of it is auth-gated, so the auth-off default
deployment is byte-for-byte unchanged (verified by the green auth-off E2E run).
Group B — hardening
- Synchronizer-token CSRF (defense-in-depth atop SameSite=Lax). Each session
carries a random Session.CsrfToken, published via a <meta> tag, /v1/auth/me,
and the template chokepoint. withCSRFProtection (authn -> CSRF -> authz)
rejects state-changing cookie-authenticated requests whose token is missing or
wrong. The token is read from the X-CSRF-Token header, the csrf_token query
param (native multipart upload forms), or an urlencoded body field — never
from a multipart/JSON body, so per-upload size limits are preserved. Bearer,
auth-off, safe methods, the login/logout flow, and read-via-POST are exempt.
JS wraps fetch + native form submits to attach the token automatically.
- Styled 403 page (RenderForbidden, mirroring RenderNotFound); denyAccess and
denyCSRF render it for browser navigations, JSON stays machine-readable.
- Per-IP login rate-limit (in-memory sliding window) via -login-max-attempts /
-login-attempt-window (default off / no-op).
Group C — mr user admin CLI
- user list|get|create|update|delete (update is a client-side partial update,
since the API is a full replace). Registered, CLI docs regenerated.
Group D — test matrix
- Auth-enabled ephemeral E2E server + auth.fixture.ts (seeds the four roles and
in/out-of-scope groups) + dedicated `auth` Playwright project with per-role
access, scope-confinement, and login-page a11y specs.
- Fixed a real WCAG bug surfaced by the new a11y specs: login button contrast
(bg-amber-600, 3.4:1) -> bg-amber-700 (AA), matching the standard submit button.
Tests: full Go unit suite (sqlite + postgres) green; new csrf/forbidden/
rate-limit Go tests; full browser+CLI E2E green (1537 passed, 2 known flakes);
auth E2E (12) green on both sqlite and postgres; staticcheck clean; mr docs lint OK.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent b09efd6 commit f3f2b61
44 files changed
Lines changed: 1838 additions & 101 deletions
File tree
- application_context
- auth
- cmd/mr
- commands
- docs-site/docs/cli
- user
- e2e
- fixtures
- tests
- auth
- cli
- models
- public/dist
- server
- api_tests
- template_handlers
- template_context_providers
- src
- templates
- layouts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
| |||
158 | 160 | | |
159 | 161 | | |
160 | 162 | | |
161 | | - | |
| 163 | + | |
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
127 | 134 | | |
128 | 135 | | |
129 | 136 | | |
| |||
211 | 218 | | |
212 | 219 | | |
213 | 220 | | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
214 | 226 | | |
215 | 227 | | |
216 | 228 | | |
| |||
905 | 917 | | |
906 | 918 | | |
907 | 919 | | |
| 920 | + | |
| 921 | + | |
908 | 922 | | |
909 | 923 | | |
910 | 924 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
0 commit comments