Skip to content

fix: authenticate transaction bootstrap and update parser dependency - #99

Closed
DavidLiuXh wants to merge 1 commit into
jackwener:mainfrom
DavidLiuXh:fix/authenticated-transaction-bootstrap
Closed

DavidLiuXh wants to merge 1 commit into
jackwener:mainfrom
DavidLiuXh:fix/authenticated-transaction-bootstrap

Conversation

@DavidLiuXh

Copy link
Copy Markdown
Contributor

Transaction initialization fetches the X homepage without the user's session cookies. When X serves the logged-out page, the required ondemand script is absent and transaction-ID initialization fails, which can accompany SearchTimeline HTTP 404 errors.

Send the full browser cookie string (or the auth_token/ct0 fallback) when fetching the x.com homepage, while keeping those credentials out of the CDN script request. Check both bootstrap responses for HTTP errors before parsing. Require xclienttransaction >=1.0.3 and update the lockfile so the development environment uses the newer script URL parser as well.

Regression coverage checks both cookie sources, verifies that cookies are not forwarded to the CDN, and confirms successful initialization is cached.

Validation:

  • uv run pytest -q: 244 passed, 6 smoke tests deselected
  • uv run ruff check .: passed
  • uv run mypy twitter_cli: passed
  • git diff --check: passed
  • Installed the patched local package and ran twitter search "AI agent" -t Latest --max 5 --json on macOS: returned 5 tweets successfully, with no ClientTransaction warning or HTTP 404.

Related to #78.

@xiaohanzhu

Copy link
Copy Markdown

Independent confirmation on WSL/Linux: the authenticated-homepage change in this PR addresses a reproducible bootstrap failure, rather than an expired-cookie problem.

Using the same host, network, curl_cffi session and generated headers, I alternated homepage fetches without/with the existing auth_token and ct0 cookies twice:

  • Without cookies: HTTP 200, zero responsive-web application script tags, and get_ondemand_file_url raised AttributeError: 'NoneType' object has no attribute 'group'.
  • With cookies: HTTP 200, three responsive-web application script tags, and ondemand script URL extraction succeeded.
  • Both repetitions produced the same outcome. Cookie-authenticated account/profile reads already worked before the repair.

I independently applied the equivalent change locally, sending cookies only to the X homepage request and not to the static asset CDN request. After updating xclienttransaction to 1.0.3, transaction initialization succeeded and the warning disappeared. Updating dependencies alone, before applying the homepage-authentication change, did not remove the warning in this environment.

Validation of my independent local implementation (not a checkout of this PR):

  • Non-smoke test suite: 243 passed, 6 deselected, including a regression test for homepage-cookie inclusion and no explicit Cookie header on the CDN fetch.
  • Live CLI search returned a result successfully after the repair.
  • One account-owner-authorized repost succeeded and was subsequently read back as a repost by the authenticated account. For that write I explicitly resolved the current CreateRetweet query ID through the client's existing community-source resolver and disabled rate-limit retries. This therefore does not isolate which change accounts for the earlier write-side 404; the bootstrap A/B reproduction above is the direct evidence for this fix.

No tokens or cookie values are included here. I found this PR while preparing to upstream the same fix, so adding confirmation here rather than opening a duplicate.

@OMSociety

Copy link
Copy Markdown

Independent reproduction on Windows, confirming the diagnosis in this PR (and #93 / #78). Stack: twitter-cli 0.8.5, xclienttransaction 1.0.3, curl_cffi 0.17.0, Python 3.13, driven through curl_cffi with a Chrome UA, same as _ensure_client_transaction() does.

GET https://x.com status bytes get_ondemand_file_url()
no cookie 200 45,262 raises AttributeError: 'NoneType' object has no attribute 'group'
Cookie: auth_token=…; ct0=… 200 314,359 https://abs.twimg.com/responsive-web/client-web/ondemand.s.f9135ed640e71051a.js

Two data points that may help pick between the approaches currently in flight:

  1. The switch to /home is not required once the cookie is sent. Plain https://x.com returns the full ~314 KB app, ondemand.s included, as soon as the session cookie is attached. The cookie — not the path — is what makes X stop serving the stripped logged-out shell. This is consistent with the approach taken here.
  2. End-to-end effect. With only this change applied locally (no URL change), SearchTimeline stops 404ing: twitter search "OpenAI" returned tweets and logged no Failed to init ClientTransaction warning. The xclienttransaction >= 1.0.3 floor was already satisfied on this machine, so I cannot speak to 1.0.1 behaviour.

Also agree with keeping the cookie out of the abs.twimg.com bundle request. My first pass reused the same header dict for both requests, which sent auth_token/ct0 to the CDN for no reason — unnecessary credential exposure, and worth covering in the regression tests you added.

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.

3 participants