Repository navigation
Conversation
When ClientTransaction fails to initialise, _build_headers() silently omits the x-client-transaction-id header and every GraphQL POST goes out as a bare API client. X answers those with a misleading `344 "You have reached your daily limit"` even on accounts that have never posted, and accounts whose writes do get through are suspended shortly afterwards. Fail closed instead: if no transaction id could be produced, refuse POST requests with an explicit error, and make the init failure loud in the log. GET requests are unaffected (they do not require the header). Escape hatch for deliberate unsigned writes: TWITTER_ALLOW_UNSIGNED=1. The media-upload test fixture now supplies a transaction id, since INIT/APPEND /FINALIZE are POSTs too.
axsddlr
added a commit
to axsddlr/twitter-cli
that referenced
this pull request
Oct 31, 2026
Two advisory fixes for issues that cannot be resolved by code alone. jackwener#28 / jackwener#66 / jackwener#46 — Windows cookie extraction `Unable to get key for cookie decryption` on Windows is almost always Chrome/Edge 127+ **App-Bound Encryption**, which browser_cookie3 cannot unwrap. The old hint listed DPAPI causes and suggested running as admin, which sends people down the wrong path. Detect the decrypt diagnostic and give the real options: use Firefox (still readable), or export auth_token/ct0 from DevTools or a cookie extension and set them as env vars. The existing DPAPI/VSS-copy advice is retained as a secondary cause, since it is still valid when the failure is not ABC. Not a full fix: decrypting ABC would require a Windows-only key extractor. That is out of scope here; the issue becomes actionable instead of cryptic. jackwener#72 — account flagged as a bot X treats an unsigned write as automation. Writes now log a prominent warning when x-client-transaction-id is unavailable. Deliberately a warning, not a refusal: the change may still land, and hard-failing writes (as proposed in upstream jackwener#101) turns a transient bootstrap failure into a broken command. Reads stay silent — they usually just 404, so a warning there is noise. Tests cover both branches, including that a signed write and an unsigned read do not warn, and that the write still returns headers rather than raising.
axsddlr
added a commit
to axsddlr/twitter-cli
that referenced
this pull request
Oct 31, 2026
Two advisory fixes for issues that cannot be resolved by code alone. jackwener#28 / jackwener#66 / jackwener#46 — Windows cookie extraction `Unable to get key for cookie decryption` on Windows is almost always Chrome/Edge 127+ **App-Bound Encryption**, which browser_cookie3 cannot unwrap. The old hint listed DPAPI causes and suggested running as admin, which sends people down the wrong path. Detect the decrypt diagnostic and give the real options: use Firefox (still readable), or export auth_token/ct0 from DevTools or a cookie extension and set them as env vars. The existing DPAPI/VSS-copy advice is retained as a secondary cause, since it is still valid when the failure is not ABC. Not a full fix: decrypting ABC would require a Windows-only key extractor. That is out of scope here; the issue becomes actionable instead of cryptic. jackwener#72 — account flagged as a bot X treats an unsigned write as automation. Writes now log a prominent warning when x-client-transaction-id is unavailable. Deliberately a warning, not a refusal: the change may still land, and hard-failing writes (as proposed in upstream jackwener#101) turns a transient bootstrap failure into a broken command. Reads stay silent — they usually just 404, so a warning there is noise. Tests cover both branches, including that a signed write and an unsigned read do not warn, and that the write still returns headers rather than raising.
This branch has not been deployed
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
When the
ClientTransactionbootstrap fails (the cases in #73 / #78 / #88: thehomepage fetch,
ondemand.sno longer being in the page, the escaped-quote hashregex),
_build_headers()silently omitsX-Client-Transaction-Idand everyGraphQL POST goes out as a bare API client.
The failure mode is not a clean error, and that is the dangerous part:
344 "You have reached your daily limit"even on accountsthat have never posted that day — it is not a quota, it is X's
anti-automation response;
or two later (
64 Your account is suspended...on the next attempt).We hit this in production running a daily posting loop on 0.8.5: the
Failed to init ClientTransactionwarning was logged on every command, everyother call kept working, so nothing looked broken — and the accounts doing the
posting were suspended. The library gave us no way to notice that a write had
gone out unsigned.
Change
Fail closed in
_build_headers():TwitterAPIErrorwith an explicit message instead of sending an unsigned write;
GETis unaffected — those endpoints do not need the header;TWITTER_ALLOW_UNSIGNED=1keeps the old behaviour for anyone who wants it;writes will be refused.
This is deliberately independent of the bootstrap fixes (#98, #99, #89, ...):
whichever of those lands, a future regression in the bootstrap will surface as a
loud error instead of a silent ban.
Tests
New
TestUnsignedWriteGuard:TwitterAPIErrorTWITTER_ALLOW_UNSIGNED=1→ allowed, no headerThe media-upload fixture now supplies a transaction id, since INIT / APPEND /
FINALIZE are POSTs too.
uv run --extra dev pytest→ 247 passed, 6 deselected.