Commit c4f1046
committed
fix(auth): stop importing yandex.com cookies as "x.com" — the real 403 cause
User reported auto-import reading 40 cookies including yandexuid, ymex,
yp, yuidss, __gads, __gpi, Hm_lvt_*, _pk_id, _pk_ref, POSMEDIAID,
__cf_bm, cf_clearance, FCCDCF, FCNEC — almost none of which belong to
X/Twitter. They were getting stuffed into the `Cookie:` header of every
UserByRestId request and X's gateway was (correctly) 403'ing the
jumbled request.
Root cause: `kooky.DomainHasSuffix("x.com")` does a literal string
suffix match against `cookie.Domain`. `yandex.com` ends in the three
characters "x.com", so does `unix.com`, `pix.com`, `nhx.com`, etc. The
filter was matching every tracker / ad / analytics cookie from every
site whose domain happens to end in those letters. That's how all the
garbage got imported.
XActions works because users paste cookies from DevTools →
Application → Cookies → https://x.com, which the browser has already
scoped to the x.com registrable domain. No browser-side bug, just a
manual filter. x-cli was trying to be clever with auto-read and hit
the substring-matching footgun.
Fix in internal/browsercookies:
isDomainMatch(want, cookieDomain) — proper registrable-domain check.
isDomainMatch("x.com", "x.com") → true
isDomainMatch("x.com", ".x.com") → true
isDomainMatch("x.com", "api.x.com") → true
isDomainMatch("x.com", ".help.x.com") → true
isDomainMatch("x.com", "yandex.com") → false ← the bug fix
isDomainMatch("x.com", "unix.com") → false
isDomainMatch("x.com", "pix.com") → false
Both Load and List now drop kooky.DomainHasSuffix and apply this
check in their own traversal loop.
TestIsDomainMatch pins the rule with 16 cases covering exact match,
subdomain match, leading-dot match, case insensitivity, and the
critical yandex.com / unix.com / pix.com negative cases that caused
the original bug.
Bonus cleanup in api/client.go (the header minimization from the prior
commit stays in place): x-cli now sends the XActions-minimal header
profile (bearer + UA + accept + content-type + x-twitter-* + cookie
+ csrf) and NOT the browser-fingerprint set (no sec-ch-ua, no
sec-fetch-*, no Origin, no Referer). XActions and twikit both work
with this minimal profile against today's x.com; adding browser-
fingerprint headers without matching TLS fingerprint only made x.com
fingerprint us as "lying about being a browser" and 403 harder.
api/client_test.go — TestApplyHeadersUnauthenticated updated to assert
that the browser-fingerprint headers are NOT sent (the correct
behaviour).
Expected result after this: `x auth import` reads ~8-12 real x.com
cookies (auth_token, ct0, twid, kdt, att, lang, _twitter_sess,
personalization_id, etc.), the verify call lands with a proper
cookie set, UserByRestId returns 200, and the user sees their handle.
No TLS impersonation needed.1 parent dfa629c commit c4f1046
4 files changed
Lines changed: 115 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
207 | 222 | | |
208 | 223 | | |
209 | 224 | | |
210 | 225 | | |
211 | 226 | | |
212 | 227 | | |
| 228 | + | |
213 | 229 | | |
214 | 230 | | |
215 | 231 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | 232 | | |
232 | 233 | | |
233 | 234 | | |
| |||
241 | 242 | | |
242 | 243 | | |
243 | 244 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | 245 | | |
249 | 246 | | |
250 | 247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
59 | | - | |
| 58 | + | |
| 59 | + | |
60 | 60 | | |
61 | | - | |
62 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
63 | 70 | | |
64 | 71 | | |
65 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
100 | 110 | | |
101 | 111 | | |
102 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
103 | 116 | | |
104 | 117 | | |
105 | 118 | | |
| |||
162 | 175 | | |
163 | 176 | | |
164 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
165 | 182 | | |
166 | 183 | | |
167 | 184 | | |
| |||
171 | 188 | | |
172 | 189 | | |
173 | 190 | | |
174 | | - | |
| 191 | + | |
175 | 192 | | |
176 | 193 | | |
177 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
178 | 198 | | |
179 | 199 | | |
180 | 200 | | |
| |||
197 | 217 | | |
198 | 218 | | |
199 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
200 | 248 | | |
201 | 249 | | |
202 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
87 | 125 | | |
88 | 126 | | |
89 | 127 | | |
| |||
0 commit comments