fix(oidc): clear stale host-only op_session on silent-SSO set path (BUNYIP-146) #177
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/bunyip-146-op-session-cookie-domain"
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?
What
Fix
/oauth2/authorizebouncing an authenticated user to/loginwhen a stale host-onlybunyip_op_sessioncookie shadows the correctly domain-scoped one after aCOOKIE_DOMAINchange (BUNYIP-146, surfaced by the a8n -> mokosh rebrand + env-domain-injection refactor).Root cause
When
COOKIE_DOMAINis set, the livebunyip_op_sessionis domain-scoped. A cookie issued before the domain was configured is host-only, and browsers send the more-specific host-only cookie first. So a dead host-only sid wins atload_op_session, resolves toNone, and authorize falls through to/login.The login path (
bunyip-apiauth handlers) and the refresh-rotation path (try_silent_ssoPath 2) already neutralize this viaclear_stale, which dual-emits a no-domain Max-Age 0 clear alongside the domain-scoped set. The silent-SSO access-token path (try_silent_ssoPath 1) did not: it set the domain-scoped op_session cookie with no accompanying clear, leaving the host-only straggler to win on the next authorize.Change
AuthCookies::op_session_set(sid, secure, cookie_domain)mirrors the dual-emit shape ofclear_op_session_onlyon the set path. With acookie_domain, it pairs the domain-scoped set with a no-domain Max-Age 0 clear so the browser deletes the host-only sibling; with no domain it returns just the host-only set cookie. Only the OP session cookie is touched, so hub access/refresh cookies stay intact.try_silent_ssoPath 1 (crates/bunyip-oidc/src/handlers/oidc.rs).Scope note
This PR covers the in-repo code hardening (AC3). The remaining acceptance criteria are deployment-side: set
COOKIE_DOMAINon staging/prod to the registrable parent (e.g..mokosh.systems) sobunyip_op_sessionis shared across theapi.*host and the apex, then verify mokosh-server'se2e/tests/oidc.spec.ts(authorize -> token -> userinfo -> refresh) against staging.compose.yml/compose.dev.ymlalready readCOOKIE_DOMAINfrom env (${COOKIE_DOMAIN:-}), so no compose change is needed; the value is an ops/env setting, not a hardcoded default.Verification
just check-containergreen: fmt + clippy (-D warnings) + workspace lib tests (202 domain incl. 2 new, 9 oci, 9 oidc).🤖 Generated with Claude Code