Commit 6613b98
committed
fix(auth): send Origin+Referer + full cookie set to defeat 403 on UserByRestId
Live test on macOS hit a hard 403 from UserByRestId even with a valid
session pinned via --profile. Two missing pieces vs what a real Chrome
sends, both fixed:
1. Origin and Referer headers were never set.
x-cli already declared `sec-fetch-site: same-origin` but didn't send
the actual Origin header. X's gateway uses Origin as its same-origin
CSRF check on top of x-csrf-token, and rejects the request when it
can't validate where it came from. Real browsers add Origin/Referer
automatically; Go's net/http does not.
api/client.go applyHeaders now sets:
Origin: https://x.com
Referer: https://x.com/
on every request. Authenticated and unauthenticated alike — every
request x-cli makes is to x.com, so this is unconditionally correct.
2. We were filtering the imported cookie set down to 6 names.
The browser-import path used a cookieNamesWanted allowlist
(auth_token, ct0, twid, kdt, att, guest_id). Real browsers send the
ENTIRE cookie set on every request — typically 25-50 cookies for
x.com. Dropping personalization_id, gt, _twitter_sess, lang, etc.
lets X's anti-abuse model fingerprint us as "non-browser" because
no real Chrome would ever omit them.
cmd/auth.go now imports every cookie kooky returns for x.com (no
filter), and only enforces that auth_token + ct0 are present
(the cookieNamesRequired set, renamed from Wanted).
Verbose output prints the imported cookie names (not values) so
the user can see what we have to work with.
summarizeCookieNames + a tiny sortStrings helper for that.
Net result: same hosting overhead, ~1KB more in the keychain blob,
but the wire matches what Chrome sends and the same-origin check
should now pass.
If the 403 persists after this, the next layer is TLS fingerprinting
(JA3/JA4 from Go stdlib != Chrome) which needs `refraction-networking
/utls`. That was on the v0.1 plan; this commit does not yet wire it.1 parent 39091ff commit 6613b98
2 files changed
Lines changed: 38 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
216 | 223 | | |
217 | 224 | | |
218 | 225 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| |||
258 | 259 | | |
259 | 260 | | |
260 | 261 | | |
261 | | - | |
262 | | - | |
263 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
264 | 269 | | |
265 | 270 | | |
266 | 271 | | |
| 272 | + | |
267 | 273 | | |
268 | 274 | | |
269 | 275 | | |
| |||
274 | 280 | | |
275 | 281 | | |
276 | 282 | | |
277 | | - | |
278 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
279 | 292 | | |
280 | 293 | | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
288 | 298 | | |
289 | 299 | | |
290 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
291 | 304 | | |
292 | 305 | | |
293 | 306 | | |
| |||
0 commit comments