feat(auth): support WebAuthn passkeys #14
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/passkeys"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
/accountenrollment and removal for multiple credentials; keep password+TOTP login as a fallback.Verification
make test— passed.go vet ./...— passed.gofmt— clean;sqlc diff— clean.go test -race ./...could not run on this host: ThreadSanitizer exits before tests withunsupported VMA range (Found 47 - Supported 48). Forgejo Actions run 34 passed the CI test job, includinggo test -race ./...on Linux/amd64; the Docker publish job was skipped for this pull request.Limits and follow-up
@ada @fara
Ada security audit (source-only, read-only)
Initiating source: comment, ID 721, authored by exler (bare audit request on this pull request).
Reviewed head SHA:
510e32269b(baseffbc2896c5).Scope: all 18 changed files (+1869/-54) for WebAuthn passkey sign-in and enrollment. Covered: internal/server/passkeys.go; the login, account and session wiring in handlers.go, auth.go, server.go and http.go; internal/db/queries.sql and migrations 0009/0010; internal/db/open.go (foreign keys enabled in the DSN); the login and account templates and app.js; CSRF coverage of the new routes; and the go-webauthn v0.18.2 login flag and counter checks from the local module cache. Source fetched pinned to the head SHA through the API.
Verdict: No blocking security findings in reviewed scope
Findings (none blocking):
Low. Passkey sign-in start can be saturated by unauthenticated clients (availability only).
Location: internal/server/passkeys.go:127-135 (per-client limiter refuses new keys once 10000 are live) and 386-406 (global pending-login cap); internal/db/queries.sql:243-246 (AdmitLoginChallenge counts all pending login rows).
Prerequisite: a few distinct client addresses. Arithmetic from the source constants, not measured: about 10 sources at 20 starts per minute each fill the 1000-slot cap within the 5-minute challenge TTL.
Impact: passkey sign-in starts return 429 for other users during that window. Password plus TOTP sign-in is not affected, and no authentication bypass or data exposure was found.
Confidence: high for the mechanism, not reproduced at runtime.
Minimal remedy: accept as a documented capacity trade-off, or reserve capacity per client key so one source cannot consume the shared cap.
Low. Passkey removal revokes tokens only for sessions that are still live.
Location: internal/server/passkeys.go:291-303; compare internal/server/auth.go:266-276 (same pattern for session revocation) and internal/server/oidc.go:29 (tokenTTL = 1 hour). Logout (handlers.go:216) ends the session but does not revoke its tokens.
Impact: access tokens or unredeemed codes issued by a passkey session that has already ended are not revoked by removal, and remain valid until expiry, at most 1 hour. This matches the existing logout behaviour rather than a new regression.
Confidence: high for the source behaviour.
Minimal remedy: either document the bound, or revoke tokens by the passkey link if the stronger guarantee is required.
Hardening notes (not findings):
Checks verified from source:
Tests and limits:
Engineering review
@fara)ffbc2896c5->510e32269b(clean detached worktree, one commit ahead of base)internal/server/passkeys.go,internal/server/auth.go,internal/server/handlers.go,internal/server/admin.go(recovery paths, unchanged but affected), migrations 0009/0010,queries.sql,passkeys_test.go, README, template/JS. Excluded: generatedqueries.sql.go(checked withsqlc diff, clean) andgo.sum(module downloads succeeded).Findings
[P1] Admin 2FA reset leaves attacker-enrolled passkeys valid
internal/server/admin.go:246-256(reset-totp, callsendSessionsat 252),internal/server/admin.go:59-64(endSessionsdeletes sessions and access tokens only),internal/server/admin.go:48-56(setAdminPassword, same helper). Thepasskeystable is never touched by admin recovery./account/passkeys/*. The admin then runs "Reset 2FA" (templates/admin_user.html:62), whose confirm text promises "Signs this user out everywhere and cancels their access tokens. They enroll a new authenticator at next sign-in." Afterwards the attacker's passkey still produces afullsession through/login/passkey/finish, and that session can enroll further passkeys (/account/passkeys/beginonly needs a recent reauth, which a passkey ceremony provides viareauth_at). The recovery therefore leaves persistent access that the admin believes was removed. The README (line 53) tells users to recover by "sign in with password and TOTP, then remove" the passkey, which an attacker-held passkey session can also do.go test -overlay=<scratch>/overlay.json -count=1 -v -run TestReviewAttackerPasskey ./internal/server/givesREPRO A: after admin reset-totp, the attacker's passkey still signs in with a full session and can enroll a new passkey(FAIL, exit 1).MustChangePassword(302 to/account/password), so enrollment is refused with 403. The passkey itself still authenticates, so the credential survives the reset. A second probe (victim's own password change) hit a 403 on my harness and is unverified; I do not rely on it.endSessions/recovery, not a parallel policy. Add a regression test inpasskey_test.gothat enrolls a passkey, runsreset-totpand the password reset, and asserts the passkey no longer signs in.Architecture and technical debt
DELETE ... RETURNING; the login counter is a compare-and-set (UpdatePasskeyUse) that matches the pinned library'sUpdateCountersemantics; the cookie-bound login challenge avoids account enumeration;manageGuardblocks impersonation and requiresreauth_atwithin 5 minutes;passkeyDeleteends the sessions and codes tied to the removed credential. Passkey deletion and session cascade run in one transaction.passkeyLoginBegin(passkeys.go:382) builds the WebAuthn assertion before the admission check (:387). A throttled client can still trigger a cheap signing call, but nothing is stored, so this is only wasted CPU.reset-totpand password-reset flows are the place where new credential types must be added. The PR adds a credential type but does not register it with the existing recovery helper. This is the root cause of the P1 above and the most likely place for drift on the next change.Verification and limitations
git statusclean at510e322; generated code matches (sqlc diffexit 0).go vet ./...exit 0.gofmt -l .exit 0 (no output).go test ./...exit 0:internal/dbok,internal/serverok (61.95s),internal/totpok.go test -run 'Passkey|PasswordChangeDoesNotRenew' -v ./internal/server/: all 13 passkey tests PASS.go test -race ./...failed locally on every package withThreadSanitizer: unsupported VMA range (Found 47 - Supported 48)before running tests. This is environmental, and the PR body notes it. Forgejo CI run 34 (pull_request, statusPush Docker Image / test (pull_request): success, 2m8s), which runsgo test -race ./..., passed for head510e322. I did not independently reproduce the race run.TestReviewAttackerPasskeyPersistsAfterAdminTOTPResetfails (REPRO A). The checkout still has no changes after the run (git statusclean; overlay file lives under scratch).