Skip to content

Cloudflare Turnstile pre-clearance demo

This page carries a Cloudflare Turnstile widget with pre-clearance on. Passing it gives the form a token, as any widget does, and also sets a cf_clearance cookie on this site, which lets later requests skip challenge rules up to the widget's clearance level.

The widget

Live

Check a token from a task

A task's solution.token for this page. It passes once, within 300 seconds of the solve.

This widget's settings

Sitekey0x4AAAAAAFMVElae0AKMyQgM
Mode
managed, pre-clearance
Appearance
always
Size
normal
Rendering
implicit
Task
TurnstileTaskProxyless

The verdict

The token goes to this site's API, which asks Cloudflare's siteverify with the widget's secret key. The reply is shown as it came.

No token checked yet

Solve the widget and press Verify, or paste a token a task returned for this page.

success
not checked yet
hostname
not checked yet
challenge_ts
not checked yet
action
not checked yet
cdata
not checked yet
error-codes
not checked yet
Widget
not checked yet
Round trip
not checked yet

Solve this page with the API

The complete createTask request for this page, then getTaskResult every 2 seconds until it is ready, then the result used as the page uses it. Set ZEROCAPTCHA_KEY to your API key.

type
TurnstileTaskProxyless, or TurnstileTask with your proxy
websiteURL
https://zerocaptcha.io/captcha-test/cloudflare-turnstile-pre-clearance
websiteKey
0x4AAAAAAFMVElae0AKMyQgM
metadata.action
This widget sets none
metadata.cdata
This widget sets none
proxy
Only with TurnstileTask: http://user:pass@host:port
callbackUrl
Optional: called with the result when the task ends
Idempotency-Key
A header: sent again within 24 hours, it returns the first task

A task is charged at the listed price when it succeeds; a failed one costs nothing. The same task over REST, POST /v1/tasks, is inSolving Cloudflare Turnstile.

#!/usr/bin/env bash
# Solve this page's Cloudflare Turnstile widget with createTask, then check the token here.
set -euo pipefail
API=${ZEROCAPTCHA_API:-https://api.zerocaptcha.io}
KEY=${ZEROCAPTCHA_KEY:?Set ZEROCAPTCHA_KEY to your API key, zc_live_..., from the dashboard.}

# 1. createTask for this page and its sitekey.
#    This widget sets no data-action or data-cdata. For one that does, send both, or a site
#    that checks them refuses the token: add metadata: {action: "login", cdata: "session-7f3a9c2e"}.
#    To solve through your own proxy, make the type TurnstileTask and add
#    proxy: "http://user:pass@proxy.example.net:8080" to the task.
#    CALLBACK_URL, when set, is called with the result when the task ends.
BODY=$(jq -n --arg key "$KEY" --arg callback "${CALLBACK_URL:-}" '{
  clientKey: $key,
  task: {
    type: "TurnstileTaskProxyless",
    websiteURL: "https://zerocaptcha.io/captcha-test/cloudflare-turnstile-pre-clearance",
    websiteKey: "0x4AAAAAAFMVElae0AKMyQgM"
  },
  callbackUrl: (if $callback == "" then null else $callback end)
}')
CREATED=$(curl -sS --fail-with-body "$API/createTask" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d "$BODY")
# errorId 1 is a refusal: errorCode and errorDescription say why.
if [ "$(jq -r .errorId <<<"$CREATED")" != 0 ]; then echo "$CREATED" >&2; exit 1; fi
TASK_ID=$(jq -r .taskId <<<"$CREATED")

# 2. getTaskResult every 2 seconds until the task is ready; errorId 1 means it failed, unpaid.
while :; do
  sleep 2
  RESULT=$(curl -sS --fail-with-body "$API/getTaskResult" \
    -H "Content-Type: application/json" \
    -d "$(jq -n --arg key "$KEY" --arg id "$TASK_ID" '{clientKey: $key, taskId: $id}')")
  if [ "$(jq -r .errorId <<<"$RESULT")" != 0 ]; then echo "$RESULT" >&2; exit 1; fi
  if [ "$(jq -r .status <<<"$RESULT")" = ready ]; then break; fi
done
TOKEN=$(jq -r .solution.token <<<"$RESULT")

# 3. Use solution.token once, within 300 seconds: here, this page's check, which asks
#    Cloudflare's siteverify. Or paste it into the token box on the page.
curl -sS --fail-with-body "$API/v1/demo/verify" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg token "$TOKEN" '{widget: "pre-clearance", token: $token}')"

What this widget is

Pre-clearance is a widget setting that makes Turnstile issue cf_clearance in addition to its token, the same cookie a challenge page sets. It works only on a site whose traffic runs through Cloudflare, for hostnames the widget and the zone share, and the cookie lasts for the zone's Challenge Passage time, 30 minutes by default.

Single-page apps use it so that their API calls behind challenge rules go through without ever getting a challenge page back.

Bring a token from elsewhere: the Cloudflare Turnstile token checker.

How to use the result

The task's result is a token: the same value a browser puts in the form's hidden cf-turnstile-response field. Send it where the page's own form sends it, in the same field. On this page that is the check at the top, beside the widget, which asks Cloudflare's siteverify about it with this widget's secret and shows the verdict; a task's token goes in its token box.

A token passes siteverify once, within 300 seconds of the solve. Use it straight away, and solve again for the next submission rather than reusing one.

A task returns the token. The cf_clearance cookie the widget sets stays in the browser that solved it, so to get a clearance for your own client, point a CloudflareChallengeTask at a page behind a challenge rule, such as the managed challenge page, through your proxy.

How to recognise it on a real site

  • The markup is an ordinary widget's; the difference shows after it passes: a fetch to the site's own /cdn-cgi/ path, and a cf_clearance cookie on the site's domain.

  • The page loads https://challenges.cloudflare.com/turnstile/v0/api.js, the only script Cloudflare supports: it must not be copied, proxied or cached.

  • The widget itself is an iframe from challenges.cloudflare.com, under /cdn-cgi/challenge-platform/. Its requests go to Cloudflare, never to the site.

  • Inside a form, the widget adds a hidden input named cf-turnstile-response and puts the token there. The site's server checks it with POST https://challenges.cloudflare.com/turnstile/v0/siteverify.

This page's widget markup
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<div class="cf-turnstile" data-sitekey="0x4AAAAAAFMVElae0AKMyQgM"></div>
<!-- once solved: <input type="hidden" name="cf-turnstile-response" value="…"> -->

Pre-clearance questions

Which ZeroCaptcha task solves the Cloudflare Turnstile widget with pre-clearance?

TurnstileTaskProxyless, or TurnstileTask to solve through your own proxy, with the page's URL and its sitekey, plus action and cdata when the widget sets them. The same task solves every Cloudflare Turnstile widget, whatever its mode or appearance.

Does a Cloudflare Turnstile task return the pre-clearance cookie?

No. It returns the token. The cookie stays in the solver's browser; a CloudflareChallengeTask through your proxy returns a clearance your own client can use.