Fix: Parse xsrf_token and gemini_bl from cookie file (400 Bad Request) - #65
Closed
01MASTERS wants to merge 1 commit into
Closed
Fix: Parse xsrf_token and gemini_bl from cookie file (400 Bad Request)#6501MASTERS wants to merge 1 commit into
01MASTERS wants to merge 1 commit into
Conversation
…ate docs and gitignore
There was a problem hiding this comment.
Pull request overview
This PR aims to restore Gemini “cookie_file” authentication by loading xsrf_token and gemini_bl from the cookie JSON export and ensuring those values are applied before constructing the request payload/URL.
Changes:
- Parse
xsrf_tokenandgemini_blfrom JSON cookie files in both the modular and monolithic implementations. - Adjust request sequencing so cookies/tokens are loaded before building request payloads/URLs (first-request correctness).
- Add internal planning notes/questions and update
.gitignoreto ignore.agents/and.planning/.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| gemini_web2api/gemini.py | Load xsrf_token/gemini_bl from cookie JSON and call load_cookie() before building payload/URL; adds debug logging. |
| gemini_web2api.py | Load xsrf_token/gemini_bl from cookie JSON and call load_cookie() earlier in request flow. |
| .planning/research/questions.md | Adds a research question related to auth robustness. |
| .planning/notes/auth-flow-cookie-sync.md | Adds documentation describing the cookie-sync authentication flow. |
| .gitignore | Ignores .agents/ and .planning/. |
Suppressed comments (1)
gemini_web2api/gemini.py:245
- This logs the raw
xsrf_tokenwhenlog_requestsis enabled. Even in debug mode, avoid emitting session/XSRF material to logs; it can leak via process supervisors, container logs, or support bundles.
log(f"DEBUG URL: {url}")
log(f"DEBUG XSRF: {CONFIG.get('xsrf_token')}")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+63
to
+66
| if "xsrf_token" in data: | ||
| CONFIG["xsrf_token"] = data["xsrf_token"] | ||
| if "gemini_bl" in data: | ||
| CONFIG["gemini_bl"] = data["gemini_bl"] |
Comment on lines
+124
to
+127
| if "xsrf_token" in data: | ||
| CONFIG["xsrf_token"] = data["xsrf_token"] | ||
| if "gemini_bl" in data: | ||
| CONFIG["gemini_bl"] = data["gemini_bl"] |
Comment on lines
+205
to
+206
| log(f"DEBUG URL: {url}") | ||
| log(f"DEBUG XSRF: {CONFIG.get('xsrf_token')}") |
Owner
|
The core idea is good (reading xsrf_token and gemini_bl from the cookie JSON file), but this PR needs cleanup before it can be merged:
Feel free to resubmit with these fixes. The xsrf_token/gemini_bl extraction from the JSON cookie file is a welcome addition. |
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.
Description
This PR fixes a critical bug where the server throws a 400 Bad Request from the Gemini upstream when using the cookie authentication method.
Root Cause:
Google's Gemini backend recently tightened its security checks, requiring a valid xsrf_token and the correct gemini_bl payload version for all requests. While the gemini-cookie-sync-extension correctly exports these fields into the cookie_file JSON, the server was ignoring them and falling back to hardcoded, outdated defaults (from July 2026).
Fixes Included:
This brings the server logic into sync with the latest extension updates and completely restores cookie authentication functionality.