fix(auth): logout clears cookies unconditionally, even when access_token is stale #319
No reviewers
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
psa-systems/bunyip!319
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/BUNYIP-323-logout-clears-cookies-unconditionally"
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?
David tried to sign out and re-register with a corrected (lowercase) email but the logout did not clear his session; he stayed signed in. Root cause: bunyip-api's POST /v1/auth/logout required a valid
AuthenticatedUserextractor. Once the access_token expired (up to 15 minutes after last refresh) the extractor 401'd BEFORE the handler ran, so no clearingSet-Cookieheaders were emitted. bunyip-web's own /logout handler forwarded whatever bunyip-api returned via.unwrap_or_default(); a 401 body yielded an empty Set-Cookie vec, and only thebunyip_2fachallenge cookie was cleared. The browser kept access_token + refresh_token + bunyip_op_session intact, and the next request re-authenticated via the refresh cycle - the user was still signed in from every visible surface.Fix at both layers so the failure mode cannot recur through either path:
bunyip-api
POST /v1/auth/logoutnow takesOptionalUserinstead ofAuthenticatedUser. With a valid user the pre-existing DB revoke + OIDC op-session fan-out still run (best-effort; a DB error inside the revoke logs a warn but does not block cookie clearing). Without a valid user those DB writes are skipped and the residual state ages out on its own schedule. Cookies are cleared viaAuthCookies::clearon every response - the whole point of the endpoint from the browser's perspective is to emit clearingSet-Cookieheaders, and that must happen whether or not the caller can prove who they are.bunyip-web adds a defensive
bunyip_auth_cookie_clears(cfg)helper that produces host-only + domain-scoped clears for the three auth cookie names (access_token, refresh_token, bunyip_op_session), mirroringAuthCookies::clear's two-axis pattern incrates/bunyip-domain/src/middleware/auth.rs. The /logout handler always merges these into the response, so an unreachable / errored bunyip-api still ends with the browser losing its cookies. The existingunwrap_or_default()on the API call now degrades to the API's clears when present and the defensive clears when absent - either way the browser purges cookies.Three unit tests in
logout_clear_testspin the shape:Secureand noDomain=.Secureand matchingDomain=<app_domain>.AuthCookies::seton the api side surfaces here.Existing 232 domain-tests + 9 api-tests + 14 oidc-tests + 26 web-tests (three new) pass under
just check-container. No change to the /oauth2/logout SSO surface,logout_all, orlogout_redirect.#BUNYIP-323