You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d7f83cc
Browse filesBrowse the repository at this point in the historyBrowse files
feat: handle WebAuthn step-up (SUF-02) on sensitive operations (#75) (#89)
* feat: handle WebAuthn step-up (SUF-02) on sensitive operations (#75)
Adds the client handling and E2E coverage for the framework's opt-in WebAuthn
step-up primitive (library 5.3.3, #365). Off unless user.security.stepUp.enabled
is true, so existing demo flows are unchanged.
Sensitive operations on passkey-only accounts return 401 until a recent passkey
assertion exists: POST /user/setPassword (JSONResponse code 6) and passkey
delete/rename (GenericResponse error "step-up-required"). On either shape the new
static/js/user/step-up.js prompts with a modal, re-runs the existing passkey
login ceremony (authenticateWithPasskey), and retries once. Re-running
/login/webauthn mid-session rotates the CSRF token (default session repository)
and changes the session id; since step-up stays on the page instead of
navigating, step-up.js refreshes the token from the new GET /csrf endpoint before
retrying. Wired into update-password.js (setPassword) and webauthn-manage.js
(delete, rename), reading the CSRF token live so the retry uses the fresh value.
E2E: new application-step-up.yml profile and chromium-step-up Playwright project
(@step-up-enabled, excluded from the default and mfa projects). step-up-flow.spec
covers the enabled path (ceremony then retry succeeds, for setPassword and
rename) and the negative path (absent WEBAUTHN factor returns 401 and runs no
ceremony). application-playwright-test.yml now also pins user.webauthn.rpId to
localhost and allowedOrigins to http://localhost:8080 so the virtual-authenticator
ceremonies work even when a developer's application-local.yml points WebAuthn at
an ngrok host; this also hardens the existing mfa E2E under local,playwright-test.
Docs: AUTHENTICATION.md gains a step-up section; CONFIGURATION.md and TESTING.md
document the profile and the new Playwright project.
Verified: chromium-step-up 3/3 pass; change-password + auth-methods 16/16 pass on
a non-step-up server (no regression); ./gradlew test green against 5.3.3.
Claude-Session: https://claude.ai/code/session_016iMnES4LsPse9LvJvyRpdN
* fix: apply step-up review findings — enrollment 403, CSRF, mail template, E2E (#75)
Addresses valid findings from the ticket-grounded review of #75, and closes gaps
found by actually exercising the expanded acceptance criteria in a browser.
Client:
- Enrollment step-up (SUF-02) now has its own handling. POST /webauthn/register is
gated by an authorization rule that returns a bare 403, not a step-up-required
401, and no passkey ceremony can satisfy a first-passkey enrollment. registerPasskey
throws PasskeyEnrollmentStepUpError on 403 and the profile page shows an actionable
"sign in again" message instead of the generic failure.
- webauthn-manage.js now reads the CSRF header/token live in the remove-password and
credential-list requests too, not just delete/rename. An in-page step-up ceremony
rotates the CSRF token, so the previously captured module-level values were stale and
the next state-changing request would 403 until reload.
Demo:
- Add the mail/webauthn-credential-registered.html template. 5.3.3 (#367) notifies the
owner on every passkey registration via this template; the demo shipped without it, so
enrollment logged a TemplateInputException.
E2E (chromium-step-up):
- Serial execution: concurrent passwordless registrations deadlock on the user_account
insert (a framework-side concurrency limit), which surfaced as intermittent 500s.
- Delete now has a ceremony-then-success case (deleting the last passkey on a passwordless
account is blocked for lockout safety, so it enrolls a second passkey on a roaming
authenticator first).
- The setPassword case now asserts the browser-only behavior the ticket exists to verify:
the page did not navigate, the session id is preserved (factor merging reuses the
session rather than running fixation; the principal is unchanged so no fixation vector),
the CSRF token rotated (which is why the /csrf refresh is load-bearing), and authorities
survive (a protected page stays reachable).
- Enrollment shortly after login is asserted explicitly.
Verified: chromium-step-up 4/4; chromium-mfa 1/1; change-password + auth-methods +
passwordless-registration 24/24 on a non-step-up server.
Still outstanding from the expanded AC, deferred deliberately (see PR notes): TTL-expiry
and stale-session-enrollment E2E (need a short-TTL profile or an aged session), social-login
(OIDC) setPassword fallback (needs the Keycloak stack), the notification email/audit
assertions (need Mailpit querying), and first-passkey-from-verification-link.
Claude-Session: https://claude.ai/code/session_016iMnES4LsPse9LvJvyRpdN
* test: cover TTL-expiry, stale-session enrollment 403, and verification-link enrollment (#75)
Adds the deterministic E2E acceptance cases from the expanded #75 criteria, via a
test-only override profile (application-step-up-e2e.yml) layered under the
chromium-step-up run:
- ttlSeconds shrunk to 2 so a WEBAUTHN factor can be aged past the window in a few
seconds. New test: assert a passkey login, wait it out, and setPassword is then
refused 401 code 6 before any mutation (E2E AC "factor aged past ttlSeconds").
- dev.auto-login-enabled turned on so /dev/login-as reaches a factorless session
deterministically. New test: enrollment from that session returns 403 and the UI
shows the actionable "sign in again" message, no passkey added (E2E AC "stale
session -> 403, UI explains"; exercises the new PasskeyEnrollmentStepUpError path).
- New test: register-then-confirm via the emailed link auto-logs-in with FACTOR_OTT,
and a first passkey enrolls successfully from that session (E2E AC "first-passkey
enrollment from a verification-link session").
The realistic demo profile (application-step-up.yml, ttlSeconds 120) is unchanged; the
short window lives only in the E2E override. Run:
APP_PROFILES=local,playwright-test,step-up,step-up-e2e npx playwright test --project=chromium-step-up
Verified: chromium-step-up 7/7.
Claude-Session: https://claude.ai/code/session_016iMnES4LsPse9LvJvyRpdN
* test: assert passkey-registration notification email via Mailpit (#75)
Adds the notification acceptance case (#367): registering a passkey emails the owner.
Mail is redirected to a Mailpit catcher and the E2E asserts the message arrives.
- compose.dev.yaml: add Mailpit (SMTP 1025, REST/web 8025). bootRun starts it
automatically alongside MariaDB; nothing sends to it unless a profile points
spring.mail there.
- application-step-up-e2e.yml: point spring.mail at localhost:1025 so enrollment
notifications (notifyOnRegistration on by default) land in Mailpit.
- step-up-flow.spec.ts: new test polls Mailpit's REST API for the "New passkey added
to your account" message to the enrolling user.
- Docs: TESTING.md and CONFIGURATION.md document the step-up-e2e override and Mailpit.
The notifyOnRegistration=false suppression and the PasskeyRegistration audit event are
covered library-side (#367); the audit event is not observable from the browser harness.
Social-login (OIDC) setPassword fallback is deferred to #90 (needs the Keycloak stack).
Verified: chromium-step-up 8/8.
Claude-Session: https://claude.ai/code/session_016iMnES4LsPse9LvJvyRpdN
* ci: run the chromium-step-up E2E project (#75)
Adds a third Playwright E2E step covering the step-up suite, with a Mailpit service
container for the notification assertion. Uses APP_PROFILES=local,playwright-test,step-up,step-up-e2e:
local activates the dev-login controller (@Profile("local")) the factorless-session case
needs, application-local.yml is absent in CI so it contributes no overrides, and
playwright-test pins rpId=localhost for the virtual authenticator.
Claude-Session: https://claude.ai/code/session_016iMnES4LsPse9LvJvyRpdN
Copy file name to clipboardExpand all lines: docs/CONFIGURATION.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ values for one scenario (local dev, production, tests, and so on). For the full
16
16
`local`, `dev`, `prd`, and `docker-keycloak` are base profiles you choose directly, one at a time, the
17
17
way the command above chooses `local`. `test` is not chosen by hand: `./gradlew test` applies it
18
18
automatically. `playwright-test` is meant to be combined with a base profile rather than run alone
19
-
(see its row below). `mfa` and `registration-guard` are opt-in add-ons with no base settings of their
19
+
(see its row below). `mfa`, `step-up`, and `registration-guard` are opt-in add-ons with no base settings of their
20
20
own; combine one with a base profile by listing both, comma-separated, in `--spring.profiles.active`
21
21
(Spring Boot applies later profiles' properties over earlier ones when the same key is set in both).
22
22
If you omit `--args` entirely, `bootRun` still defaults to `local`: `build.gradle:118-123` sets
@@ -32,11 +32,14 @@ If you omit `--args` entirely, `bootRun` still defaults to `local`: `build.gradl
32
32
|`playwright-test`|[`application-playwright-test.yml`](../src/main/resources/application-playwright-test.yml)| Playwright E2E runs; enables the Test API (`TestDataController`, `TestApiSecurityConfig`, localhost-only) | Disables verification/reset emails, points `spring.datasource.*` at the same local MariaDB the `local` profile uses, pins `appUrl` to `http://localhost:8080`, `allowInitialPasswordSetWithoutStepUp: true`, MFA off, and restates `user.security.unprotectedURIs` in full (a list property is replaced wholesale, not merged, so this copy has to match the base list in `application.yml:160`) | Combine with a base profile, e.g. `local,playwright-test` (see [TESTING.md](TESTING.md)) |
33
33
|`docker-keycloak`|[`application-docker-keycloak.yml`](../src/main/resources/application-docker-keycloak.yml) (tracked; holds only `${...}` placeholders, nothing to copy) | OIDC login against the bundled Keycloak stack; see [`keycloak/README.md`](../keycloak/README.md) and [AUTHENTICATION.md#keycloak](AUTHENTICATION.md#keycloak) for the full walkthrough | Adds the Keycloak OAuth2 client/provider from `DS_SPRING_USER_KEYCLOAK_*` env vars (deliberately no `issuer-uri`), insecure session cookie |`--spring.profiles.active=docker-keycloak`, normally set for you as `SPRING_PROFILES_ACTIVE` inside `docker-compose-keycloak.yml`|
34
34
|`mfa`|[`application-mfa.yml`](../src/main/resources/application-mfa.yml)| Add-on: require PASSWORD + WEBAUTHN |`user.mfa.enabled: true` (base `application.yml:126` has it `false`); once enabled, the framework auto-unprotects the configured MFA entry-point URIs at runtime, including the challenge page, so a partially-authenticated user can reach them; the profile's yml additionally adds the passkey enrollment endpoints `/webauthn/register/options` and `/webauthn/register` to `unprotectedURIs` (line 25) so that user can register their first passkey; `allowInitialPasswordSetWithoutStepUp: true`| Combine with a base profile, e.g. `local,mfa`|
35
+
|`step-up`|[`application-step-up.yml`](../src/main/resources/application-step-up.yml)| Add-on: require a recent passkey assertion for credential-altering operations on passkey-only accounts (SUF-02) |`user.security.stepUp.enabled: true` (base default is `false`), `ttlSeconds: 120`, `factors: [WEBAUTHN]`; this registers the framework's built-in `StepUpService`, so `POST /user/setPassword` and passkey delete/rename return `401` until a fresh `WEBAUTHN` factor exists, and passkey enrollment is gated on a recent authentication. See [AUTHENTICATION.md#webauthn-step-up-suf-02](AUTHENTICATION.md#webauthn-step-up-suf-02)| Combine with a base profile, e.g. `local,step-up`|
36
+
|`step-up-e2e`|[`application-step-up-e2e.yml`](../src/main/resources/application-step-up-e2e.yml)|**Test-only** override for the `chromium-step-up` Playwright run; never use outside E2E | Shrinks `stepUp.ttlSeconds` to `2` (deterministic factor aging), enables `user.dev.auto-login-enabled` (factorless session via `/dev/login-as`), and points `spring.mail` at the Mailpit catcher in `compose.dev.yaml` (notification assertion). Layer it last, after `step-up`|`local,playwright-test,step-up,step-up-e2e` (see [TESTING.md](TESTING.md)) |
35
37
|`registration-guard`| none (no yml; `@Profile("registration-guard")` on [`DomainRegistrationGuard`](../src/main/java/com/digitalsanctuary/spring/demo/registration/DomainRegistrationGuard.java)) | Add-on: domain-restricted registration demo | Activates a `RegistrationGuard` bean that restricts form/passwordless registration to one email domain (`registration.guard.allowed-domain`, default `@example.com`); OAuth2/OIDC registration is unaffected | Combine with a base profile, e.g. `local,registration-guard`|
36
38
37
39
See [AUTHENTICATION.md](AUTHENTICATION.md) for the mechanics behind `mfa`
0 commit comments