8000 Fix authenticated X request signing and ondemand script parsing by jaypopat · Pull Request #1 · blacktop/twit · GitHub
[go: up one dir, main page]

Skip to content

Fix authenticated X request signing and ondemand script parsing - #1

Open
jaypopat wants to merge 1 commit into
blacktop:mainfrom
jaypopat:fix/x-session-signing
Open

jaypopat wants to merge 1 commit into
blacktop:mainfrom
jaypopat:fix/x-session-signing

Conversation

@jaypopat
@jaypopat jaypopat commented Sep 16, 2026 •
Copy link
Copy Markdown

Problem

twit auth fails before it ever checks the cookies:

Validating credentials...
✗ Authentication failed: Failed to create ClientTransaction: Parse error: Couldn't find ondemand file

Please check your cookie values and try again.
Error: Failed to create ClientTransaction

Caused by:
    Parse error: Couldn't find ondemand file

The cookies are fine — request signing never got off the ground, and the wizard
blamed the wrong thing.

Cause

Two independent problems:

  1. generate_transaction_id built a fresh blocking client with no session, so it
    fetched x.com logged out. Logged-out pages no longer embed the ondemand.s
    script that ClientTransaction::new looks for.
  2. Even with the script in hand, the published x-client-transaction 0.1.0 can't
    parse X's current numeric ondemand chunk map.

Fix

  • Sign with the session: cookies now live in a reqwest cookie jar shared by the
    async and blocking clients, so the signing page is fetched authenticated.
  • Scope the jar to https://x.com (Secure, Path=/). Previously the cookies
    were a static COOKIE default header, sent to whatever host that client was
    pointed at; the jar limits them to x.com over HTTPS.
  • Pin x-client-transaction to 2b785eb. That is the crate's own repository
    (crates.io 0.1.0 lists it as repository) at HEAD, which carries the parser
    fix. Glad to switch back to a version requirement if the author publishes it.
  • Add a 30s timeout to the blocking signing client, which could previously hang.
  • Reword the auth wizard error so signing and network failures aren't reported as
    bad cookies.

Tests

  • session_cookies_are_scoped_to_secure_x_requests — cookies are sent to
    https://x.com, and not to abs.twimg.com, other hosts, or plain HTTP.
  • session_cookies_reject_empty_or_injected_values — empty values and ;/CRLF
    injection are rejected.
  • live_home_timeline — #[ignore]d, hits the real API with the local config:
    cargo test live_home_timeline -- --ignored --nocapture. Say the word if you'd
    rather not carry a test that reads a local config.

Verification

twit auth completes and the timeline loads against a real account on Linux; the
ignored live test passes. The failure above is reproducible on main with valid
cookies.

Signing setup fetched x.com without the session, and logged-out pages no
longer embed the ondemand script, so ClientTransaction::new failed with
"Couldn't find ondemand file" before any credential was checked.

- Fetch the signing page with the session cookies, via a scoped cookie jar
  so they are only sent to x.com over HTTPS and never to the script CDN.
- Pin x-client-transaction to its repository HEAD: the published 0.1.0 cannot
  parse X's current numeric ondemand chunk map.
- Give the blocking signing client a timeout, and reword the auth wizard error
  that blamed cookies for what are signing or network failures.
@jaypopat
jaypopat force-pushed the fix/x-session-signing branch from 9f1dea7 to 5644d43 Compare September 16, 2026 00:28
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.

1 participant

0