Explainers

Cloudflare Challenge cf_clearance Cookie Guide

When Cloudflare flags a visitor as suspicious, it serves an interstitial challenge page. Once solved, the browser receives a cf_clearance cookie that grants access for the session. This guide explains how the challenge flow works and how CaptchaAI handles it.


How Cloudflare Challenge pages work

  1. User requests a Cloudflare-protected page
  2. Cloudflare evaluates risk signals (IP reputation, headers, TLS fingerprint)
  3. If flagged, Cloudflare returns a 403 or 503 with a JavaScript challenge page
  4. The challenge page runs browser checks and may present a Turnstile widget
  5. On success, Cloudflare sets cf_clearance and redirects to the original URL
  6. Subsequent requests with the cookie pass through without challenge

Property Details
Name cf_clearance
Domain Target site domain (e.g., .example.com)
Path /
Lifetime Typically 30 minutes to 24 hours
HttpOnly Yes
Secure Yes (HTTPS only)
SameSite None

The cookie is tied to several factors:

  • IP address — Using the cookie from a different IP usually fails
  • User-Agent — Must match the UA used during challenge solving
  • TLS fingerprint — Some configurations bind to the TLS ClientHello

Challenge types

Cloudflare serves different challenge levels:

Challenge Response code User interaction Description
JS Challenge 503 None JavaScript execution only
Managed Challenge 403 Maybe Cloudflare decides — may show Turnstile or pass silently
Interactive Challenge 403 Yes Always shows a Turnstile widget

CaptchaAI solves all three types through the Cloudflare Challenge solver.


Solving with CaptchaAI

Python

import requests
import time

API_KEY = "YOUR_API_KEY"
TARGET_URL = "https://example.com/protected-page"

# Submit Cloudflare Challenge task
resp = requests.post("https://ocr.captchaai.com/in.php", data={
    "key": API_KEY,
    "method": "turnstile",
    "sitekey": "0x0000000000000000000000",  # may be generic for CF challenge
    "pageurl": TARGET_URL,
    "json": "1",
}).json()

if resp["status"] != 1:
    raise Exception(f"Submit error: {resp['request']}")

task_id = resp["request"]
print(f"Task ID: {task_id}")

# Poll for result
for _ in range(30):
    time.sleep(5)
    result = requests.get("https://ocr.captchaai.com/res.php", params={
        "key": API_KEY, "action": "get", "id": task_id, "json": "1"
    }).json()

    if result["status"] == 1:
        token = result["request"]
        print(f"Token received: {token[:50]}...")
        break
    if result["request"] != "CAPCHA_NOT_READY":
        raise Exception(f"Error: {result['request']}")

JavaScript

const axios = require('axios');

const API_KEY = 'YOUR_API_KEY';
const TARGET_URL = 'https://example.com/protected-page';

const submit = await axios.post('https://ocr.captchaai.com/in.php', null, {
  params: {
    key: API_KEY,
    method: 'turnstile',
    sitekey: '0x0000000000000000000000',
    pageurl: TARGET_URL,
    json: 1,
  }
});
const taskId = submit.data.request;

// Poll
let token = null;
for (let i = 0; i < 30; i++) {
  await new Promise(r => setTimeout(r, 5000));
  const poll = await axios.get('https://ocr.captchaai.com/res.php', {
    params: { key: API_KEY, action: 'get', id: taskId, json: 1 }
  });
  if (poll.data.status === 1) {
    token = poll.data.request;
    break;
  }
}
console.log(`Token: ${token.substring(0, 50)}...`);

Using the solved token

After solving, inject the token into the challenge page to obtain cf_clearance:

# With Selenium
from selenium import webdriver

driver = webdriver.Chrome()
driver.get(TARGET_URL)  # Load the challenge page

# Inject token into Turnstile response field
driver.execute_script("""
    const input = document.querySelector('input[name="cf-turnstile-response"]');
    if (input) input.value = arguments[0];

    // Trigger form submit or callback
    const form = document.querySelector('form');
    if (form) form.submit();
""", token)

# Wait for redirect and extract cookies
import time
time.sleep(3)
cookies = driver.get_cookies()
cf_clearance = next(
    (c for c in cookies if c['name'] == 'cf_clearance'), None
)
if cf_clearance:
    print(f"cf_clearance: {cf_clearance['value'][:30]}...")
session = requests.Session()
session.cookies.set("cf_clearance", cf_clearance["value"], domain=".example.com")
session.headers.update({
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
})

# Now access protected pages
resp = session.get("https://example.com/api/data")
print(resp.status_code)  # 200

The cf_clearance cookie expires. Plan for re-solving:

import datetime

def is_cookie_valid(cookie):
    if not cookie:
        return False
    expiry = cookie.get("expiry", 0)
    return datetime.datetime.now().timestamp() < expiry - 60  # 60s buffer

def get_or_refresh_clearance(driver, target_url, solve_func):
    cookies = driver.get_cookies()
    cf = next((c for c in cookies if c["name"] == "cf_clearance"), None)
    if is_cookie_valid(cf):
        return cf["value"]

    # Re-solve
    token = solve_func(target_url)
    # ... inject and extract new cookie

Troubleshooting

Problem Cause Fix
Cookie rejected after solving IP mismatch Use the same proxy for solving and requests
Cookie expires quickly Short TTL set by site Re-solve before expiry; check expiry field
403 despite valid cookie User-Agent mismatch Match UA between solve and request sessions
Challenge page not loading JavaScript disabled Use a full browser (Selenium, Puppeteer)

FAQ

Can I share cf_clearance between different machines?

Only if they share the same IP and you match the User-Agent string. Cloudflare often ties the cookie to the originating IP.

How long does cf_clearance last?

Typically 30 minutes to 24 hours, depending on the site owner's Cloudflare configuration.


Solve Cloudflare Challenge pages with CaptchaAI

Get your API key at captchaai.com.


Discussions (0)

No comments yet.

Related Posts

Troubleshooting CaptchaAI Proxy Connection Failures: Diagnosis and Fixes
Troubleshoot proxy connection failures when using Captcha AI.

Troubleshoot proxy connection failures when using Captcha AI. Fix timeout errors, authentication issues, and p...

Python reCAPTCHA v2 Web Scraping
Mar 27, 2026
Troubleshooting Cloudflare Challenge vs Turnstile: How to Detect Which One You Have
how to identify whether a site uses Cloudflare Challenge (full-page) or Cloudflare Turnstile (embedded widget) and choose the correct Captcha AI method.

Learn how to identify whether a site uses Cloudflare Challenge (full-page) or Cloudflare Turnstile (embedded w...

Python Cloudflare Turnstile Web Scraping
Feb 28, 2026
Integrations Bright Data + CaptchaAI: Complete Proxy Integration Guide
Integrate Bright Data's residential, datacenter, and ISP proxies with Captcha AI for high-success-rate CAPTCHA solving at scale.

Integrate Bright Data's residential, datacenter, and ISP proxies with Captcha AI for high-success-rate CAPTCHA...

Python reCAPTCHA v2 Cloudflare Turnstile
Feb 21, 2026
Troubleshooting Cloudflare Challenge Loop: Why Challenges Keep Repeating
Fix Cloudflare Challenge loops where the challenge page keeps reappearing after solving.

Fix Cloudflare Challenge loops where the challenge page keeps reappearing after solving. Covers cookie handlin...

Python Web Scraping Cloudflare Challenge
Feb 28, 2026
Reference CAPTCHA Token Injection Methods Reference
Complete reference for injecting solved CAPTCHA tokens into web pages.

Complete reference for injecting solved CAPTCHA tokens into web pages. Covers re CAPTCHA, Turnstile, and Cloud...

Automation Python reCAPTCHA v2
Apr 08, 2026
Troubleshooting Turnstile Token Invalid After Solving: Diagnosis and Fixes
Fix Cloudflare Turnstile tokens that come back invalid after solving with Captcha AI.

Fix Cloudflare Turnstile tokens that come back invalid after solving with Captcha AI. Covers token expiry, sit...

Python Cloudflare Turnstile Web Scraping
Apr 08, 2026
API Tutorials Case-Sensitive CAPTCHA API Parameter Guide
How to use the regsense parameter for case-sensitive CAPTCHA solving with Captcha AI.

How to use the regsense parameter for case-sensitive CAPTCHA solving with Captcha AI. Covers when to use, comm...

Python Web Scraping Image OCR
Apr 09, 2026
Tutorials Extracting reCAPTCHA Parameters from Page Source
Extract re CAPTCHA parameters from any web page — sitekey, action, data-s, enterprise flag, and version — using regex, DOM queries, and network interception.

Extract all re CAPTCHA parameters from any web page — sitekey, action, data-s, enterprise flag, and version —...

Python reCAPTCHA v2 Web Scraping
Apr 07, 2026
Comparisons ScrapingBee vs Building with CaptchaAI: When to Use Which
Compare Scraping Bee's -in-one scraping API with building your own solution using Captcha AI.

Compare Scraping Bee's all-in-one scraping API with building your own solution using Captcha AI. Cost, flexibi...

Python All CAPTCHA Types Web Scraping
Mar 16, 2026
Use Cases Job Board Scraping with CAPTCHA Handling Using CaptchaAI
Scrape job listings from Indeed, Linked In, Glassdoor, and other job boards that use CAPTCHAs with Captcha AI integration.

Scrape job listings from Indeed, Linked In, Glassdoor, and other job boards that use CAPTCHAs with Captcha AI...

Python reCAPTCHA v2 Cloudflare Turnstile
Feb 28, 2026
Explainers How BLS CAPTCHA Works: Grid Logic and Image Selection
Deep dive into BLS CAPTCHA grid logic — how images are arranged, how instructions map to selections, and how Captcha AI processes BLS challenges.

Deep dive into BLS CAPTCHA grid logic — how images are arranged, how instructions map to selections, and how C...

Automation BLS CAPTCHA
Apr 09, 2026
Explainers Browser Fingerprinting and CAPTCHA: How Detection Works
How browser fingerprinting affects CAPTCHA challenges, what signals trigger CAPTCHAs, and how to reduce detection with Captcha AI.

How browser fingerprinting affects CAPTCHA challenges, what signals trigger CAPTCHAs, and how to reduce detect...

reCAPTCHA v2 Cloudflare Turnstile reCAPTCHA v3
Mar 23, 2026
Explainers GeeTest v3 Challenge-Response Workflow: Technical Deep Dive
A technical deep dive into Gee Test v 3's challenge-response workflow — the registration API, challenge token exchange, slider verification, and how Captcha AI...

A technical deep dive into Gee Test v 3's challenge-response workflow — the registration API, challenge token...

Automation Testing GeeTest v3
Mar 02, 2026