Skip to content

fix: a lapsed session is refreshed instead of reported as expired - #37

Merged
gridoe merged 1 commit into
gridoe:mainfrom
TZANTOU:fix/false-expired-session
Nov 17, 2026
Merged

gridoe merged 1 commit into
gridoe:mainfrom
TZANTOU:fix/false-expired-session

Conversation

@TZANTOU

@TZANTOU TZANTOU commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Problem

On Windows, from an EU country, refryt keeps saying the sign-in has expired and asks for the cookie again. The log at each prompt:

WARN refryt::api: YouTube Music refused the session status=200 landed=https://music.youtube.com/ title="YouTube Music" client_version=true sapisid=true refusal=Other
WARN refryt::backend: could not check the saved session error=the saved cookie is invalid or expired; sign in again: Error parsing header.

Cause

SOCS=CAI is set as a default Cookie header, but reqwest only applies a default header when the request has none, and every signed-in request (and BrowserToken::from_str) sends the session's own cookie. So signed-in requests never carry consent.

While the session is good, YouTube doesn't ask. Once it lapses, an EU request without consent gets 302 consent.youtube.com. Then from_str fails with "Error parsing header", and ensure_browser returns that error before verify_session can call refresh_from_source. A sign-in-window session that only needed a quiet refresh asks to sign in again instead.

Checked against a lapsed session: without consent, 302 to consent.youtube.com. With SOCS=CAI added, 200 with INNERTUBE_CLIENT_VERSION":" present and LOGGED_IN:false, which the existing refresh path handles.

The diagnostic line above looked like a good page being refused because refused_page follows the redirect, and reqwest drops the Cookie on the cross-host hop, so it lands on the anonymous music page.

Fix

signed_in_cookie() adds the consent cookie to the session cookie when it has no SOCS/CONSENT of its own. It's used for both from_str calls and the refusal probe. Unit test included.

Not covered: a pasted cookie still can't be renewed once the browser it came from rotates its cookies; the sign-in window is the path that refreshes itself.

just check passes (fmt, clippy -D warnings for both resolver feature sets, tests).

🤖 Generated with Claude Code

Signed-in requests never carried the EU consent cookie. `SOCS=CAI` is a default `Cookie` header,
and reqwest only applies a default when the request has none, while every signed-in request
(and `BrowserToken::from_str`) sends the session's own. While a session is good YouTube does not
ask; once it lapses, an EU request without consent is sent to `consent.youtube.com`, `from_str`
fails with "Error parsing header", and `ensure_browser` returns that before `verify_session` can
renew the session from its source. A sign-in window session that only needed a quiet refresh
asked to sign in again, with "the saved cookie is invalid or expired".

The session cookie now carries the consent cookie when it has none of its own, so a lapsed
session reaches the real page, reads as signed out and takes the existing refresh path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gridoe
gridoe merged commit 39fa3c3 into gridoe:main Nov 17, 2026
3 checks passed
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.

2 participants