Repository navigation
fix: a lapsed session is refreshed instead of reported as expired - #37
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Cause
SOCS=CAIis set as a defaultCookieheader, but reqwest only applies a default header when the request has none, and every signed-in request (andBrowserToken::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. Thenfrom_strfails with "Error parsing header", andensure_browserreturns that error beforeverify_sessioncan callrefresh_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,
302toconsent.youtube.com. WithSOCS=CAIadded,200withINNERTUBE_CLIENT_VERSION":"present andLOGGED_IN:false, which the existing refresh path handles.The diagnostic line above looked like a good page being refused because
refused_pagefollows the redirect, and reqwest drops theCookieon 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 noSOCS/CONSENTof its own. It's used for bothfrom_strcalls 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 checkpasses (fmt, clippy-D warningsfor both resolver feature sets, tests).🤖 Generated with Claude Code