Skip to content

Commit d034ff6

Browse files
committed
fix: support user agent for Turnstile Challenge
1 parent fe318e3 commit d034ff6

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,14 @@ that the target page expects in `cf-turnstile-response`.
330330
| `action` | no | Value of the widget's `data-action` attribute, if set. |
331331
| `data` | no | Custom payload from the widget's `data-cdata` attribute, if set. |
332332
| `pagedata` | no | Value of the `chlPageData` parameter, needed for some Cloudflare challenge pages beyond the basic widget. |
333-
| `userAgent` | no | User-Agent to solve with -- the returned token is tied to it, submit with the same one. |
333+
| `userAgent` | no | Current browser User-Agent. Pass it for Cloudflare Challenge pages; it is not needed for a standalone widget. |
334334

335335
**Response:** `token` -- submit as `cf-turnstile-response`. For Cloudflare
336-
Challenge pages, the solution also includes `userAgent`; use that User-Agent
337-
when submitting the token. Pass `action`, `data`, and `pagedata` when the page
338-
provides them. The API field is spelled `pagedata`, all lowercase.
336+
Challenge pages, pass `action`, `data`, `pagedata`, and the current browser
337+
`userAgent` in the task. Keep that browser User-Agent unchanged when invoking
338+
the callback. The solution may also contain `userAgent`; do not switch the
339+
browser to this returned value. The API field is spelled `pagedata`, all
340+
lowercase.
339341

340342
```python
341343
from captcha_solver_api import CaptchaClient

‎captcha_solver_api/tasks.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ class TurnstileTaskProxyless(BaseTask):
303303
challenge pages beyond the basic widget. Named lowercase (not `pageData`)
304304
to match the API field name exactly -- Cloudflare-specific fields are
305305
the one place this API doesn't camelCase.
306-
userAgent: User-Agent to solve with. The returned token is tied to it --
307-
submit it with the same User-Agent.
306+
userAgent: User-Agent of the browser that loaded the challenge. Pass it
307+
together with `action`, `data`, and `pagedata` for Cloudflare
308+
Challenge pages. It is not needed for a standalone widget.
308309
309310
Returns (`solution` from `solve()`):
310311
`token` -- the value to submit as `cf-turnstile-response`.
@@ -345,7 +346,9 @@ class TurnstileTask(BaseTask, ProxyMixin):
345346
pagedata: Value of the `chlPageData` parameter, needed for some Cloudflare
346347
challenge pages beyond the basic widget. Named lowercase (not `pageData`)
347348
to match the API field name exactly.
348-
userAgent: User-Agent to solve with. The returned token is tied to it.
349+
userAgent: User-Agent of the browser that loaded the challenge. Pass it
350+
for Cloudflare Challenge pages; it is not needed for a standalone
351+
widget. Do not replace the browser User-Agent after solving.
349352
350353
Returns (`solution` from `solve()`):
351354
`token` -- the value to submit as `cf-turnstile-response`.

‎tests/sync/test_turnstile.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99

1010

1111
class TestTurnstile:
12+
def test_proxyless_includes_challenge_user_agent(self):
13+
task = TurnstileTaskProxyless(
14+
websiteURL="https://example.com",
15+
websiteKey="test_key",
16+
action="managed",
17+
data="cdata",
18+
pagedata="page-data",
19+
userAgent="Mozilla/5.0",
20+
)
21+
22+
assert task.to_dict()["userAgent"] == "Mozilla/5.0"
23+
1224
def test_proxyless_to_dict(self):
1325
task = TurnstileTaskProxyless(
1426
websiteURL="https://example.com",

0 commit comments

Comments
 (0)