Skip to content

fix: keep the session cookies when a refresh fails transiently - #39

Merged
Bccorb merged 2 commits into
mainfrom
fix/refresh-failures-keep-session
Nov 5, 2026
Merged

Bccorb merged 2 commits into
mainfrom
fix/refresh-failures-keep-session

Conversation

@Bccorb

@Bccorb Bccorb commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Parity with fells-code/seamless-auth-go#22, fells-code/seamless-auth-server#273 and fells-code/seamless-auth-python#37 for cookie transport. Today every cookie refresh failure collapses into SilentRefreshError::Failed and a 401 that clears the cookies, so an auth API outage or a 5xx during a deploy signs browsers out.

Cookies are now cleared only when the auth API answers 401 or the refresh cookie cannot be read (today's Refresh failed / invalid_refresh_token answers).

Case Silent refresh and cookie POST /refresh Cookies
Transport error, 200 with no session, a non-200 2xx, a rotated session that fails verification, a rotation that times out or whose task panics 502 upstream_unavailable kept
Any other non-2xx status, body and Retry-After pass through kept
401 from the API, unreadable cookie unchanged cleared

SilentRefreshError is now NoRefreshCookie, Rejected (cookies cleared) and Transient(Box<Reply>) (the answer to send, cookies kept); refresh_route and credential_for return the transient reply. Bearer refresh, in-flight sharing and the cookie-only 5 second window (successful rotations only) are unchanged. A failure to sign the internal service token now answers 500 internal_error with cookies kept, matching the bearer path.

8daf82a adds the tests alone; 8 fail on main (closed port, 503 with Retry-After, no session, 201, unknown key, timeout on a paused clock, panic, failure not kept). The paused clock adds tokio's test-util dev-dependency feature; Cargo.lock is unchanged.

fmt, clippy -D warnings on all three feature sets, cargo test and cargo +1.88 test (136 + 1 doctest), check-manifest.sh pass.

…nswers 401

Reproduces cookie-transport refreshes (the silent refresh on an auth route and
POST /refresh) that sign a browser out when the auth API is unreachable,
answers another error, returns no usable session, or the rotation times out or
its task panics. Only a 401 or an unreadable refresh cookie should clear the
session cookies. Turns on tokio's test-util for a paused clock in tests.
In cookie transport, the silent refresh on an auth route and POST /refresh now
clear the session cookies only when the auth API answers the refresh with 401
or the refresh cookie cannot be read. An unreachable API, a rotation that
times out or whose task panics, a 2xx other than a 200 with a verifiable
session, all answer 502 upstream_unavailable; any other error from the API
passes through with its status, body and Retry-After. The cookies are kept in
every one of these cases so the next request tries again, matching the Go,
Node and Python adapters. Bearer refresh is unchanged.
@Bccorb
Bccorb merged commit d49b751 into main Nov 5, 2026
4 checks passed
@Bccorb
Bccorb deleted the fix/refresh-failures-keep-session branch November 5, 2026 01:15
@github-actions github-actions Bot mentioned this pull request Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant