cf_clearance is the cookie Cloudflare sets after a visitor passes one of its challenges, such as a Managed Challenge, a JavaScript (non-interactive) challenge or an interactive challenge. While the cookie is valid, Cloudflare does not challenge that visitor again; how long that lasts is set by the site's Challenge Passage setting, 30 minutes by default. The cookie is tied to the visitor and device that earned it, so reusing it from another IP, User-Agent or HTTP client usually gets you a 403 or a fresh challenge.
That last point explains most "cf_clearance not working" reports. This guide covers what the cookie proves, what it appears to be bound to, how its lifetime works, how to get one programmatically, and how to detect expiry and renew it, with full curl, Python and Node.js examples.
Short version: solve the challenge once through a sticky proxy, replay cf_clearance with the returned user_agent through that same proxy, and solve again when Cloudflare answers with cf-mitigated: challenge. The NSLSolver Cloudflare Challenge API returns both values in about 3.3 s, for $1.00 per 1,000 successful solves.
Related reading: if you are blocked before any challenge page appears, start with Cloudflare 403 Forbidden in Python. For a complete scraping walkthrough, see Bypass Cloudflare Managed Challenge with Python. This page is about the cookie itself.
What is the cf_clearance cookie?
Cloudflare describes cf_clearance as the clearance cookie that "stores the proof of challenge passed". When it is present and valid, Cloudflare stops issuing the challenge and lets the request through to the origin server. Cloudflare also stores the results of its JavaScript detections in this cookie.
A few documented properties are useful when you handle it in code:
- It is set with SameSite=None; Secure; Partitioned, so it needs HTTPS. In a third-party (embedded) context it is stored per top-level site and is not shared across embedding sites.
- It cannot be larger than 4,096 bytes. Treat the value as opaque: it is not a token you can decode, edit or generate yourself.
- It has a clearance level. A cookie earned on an interactive challenge also clears Managed and non-interactive challenges, a Managed clearance also clears non-interactive challenges, and a non-interactive clearance clears only non-interactive challenges. Solving a higher-level challenge later replaces the original clearance.
- Other Cloudflare cookies are separate. __cf_bm belongs to Bot Management and Bot Fight Mode and expires after 30 minutes of inactivity. The cf_chl_rc_* cookies are documented as internal diagnostics. Neither replaces cf_clearance.
When does Cloudflare set cf_clearance?
Cloudflare sets cf_clearance when a client completes a challenge page. Site owners trigger those pages with WAF custom rules or IP Access rules set to a challenge action, and Cloudflare's own security features can serve them too. In practice you meet it in these situations:
- Managed Challenge: the "Just a moment..." or "Verify you are human" interstitial, where Cloudflare decides whether to run a non-interactive check or show an interactive one.
- JavaScript challenge (non-interactive): the page runs a script in the browser and redirects once it completes. A plain HTTP client cannot do this, which is why the "cloudflare js challenge solver" query exists.
- Interactive challenge: the visitor has to interact with the page before the cookie is issued.
- Turnstile pre-clearance: when a site owner enables it on a widget, solving the widget also issues a cf_clearance cookie for that zone, in addition to the usual Turnstile token.
What is cf_clearance bound to?
Cloudflare's documentation says the cookie is "securely tied to the specific visitor and device it was issued to, preventing reuse across machines". It does not publish the exact inputs. The table separates what Cloudflare documents from what you should plan for.
| Attribute | What Cloudflare documents | What to plan for |
|---|---|---|
| Visitor and device | Tied to the visitor and device it was issued to; not reusable across machines | Treat each cookie as belonging to one client identity |
| IP address | Not specified | A different exit IP commonly gets a new challenge. Use a sticky proxy and one cookie per IP |
| User-Agent | Not specified | Send the exact User-Agent of the browser that solved the challenge |
| TLS / HTTP/2 fingerprint | Not specified | A client that looks nothing like the solving browser can be challenged again. Use a browser-impersonating client |
| Site (zone) | Clearance applies to challenges on the zone that issued it | A cookie from one site is useless on another |
| Clearance level | Interactive > Managed > non-interactive; higher clears lower | A low-level clearance may not get past a stricter rule |
Sources: developers.cloudflare.com (Challenge clearance, Cloudflare cookies). The right-hand column reflects commonly observed behaviour, not a Cloudflare guarantee.
How long does cf_clearance last?
The lifetime comes from the zone's Challenge Passage setting, not from anything you control. Cloudflare's documentation gives these rules:
- The default is 30 minutes. Site owners can change it in the dashboard, and Cloudflare recommends a value between 15 and 45 minutes.
- Cloudflare adds a few extra minutes to absorb clock skew, and adds an extra hour to the validation time for XmlHTTP (XHR) requests.
- Challenge Passage covers challenges triggered by WAF custom rules and IP Access rules. It does not apply to rate limiting rules, so a valid cf_clearance does not exempt you from a 429.
- Clearance can end early. Cloudflare says its session analysis can reduce or invalidate clearance and challenge again before the cookie expires if a session looks suspicious.
- You usually cannot read another site's Challenge Passage value. Measure it: log when each solve happened and when the next challenge appeared.
Why does a reused cf_clearance return 403 Forbidden?
A challenge response is often a 403 (or a 503) with a "Just a moment..." body, and Cloudflare marks it with the response header cf-mitigated: challenge. If you get that after setting cf_clearance, Cloudflare did not accept the cookie for that request. The usual reasons:
- The request left through a different IP than the solve, for example because of a rotating proxy or a request sent without the proxy.
- The User-Agent differs from the browser that earned the cookie, even by a version number.
- The HTTP client has a TLS or HTTP/2 fingerprint that does not look like a browser (plain Python requests, Node fetch, Go net/http).
- The Challenge Passage window ended, or Cloudflare cut the clearance short.
- The cookie was earned at a lower clearance level than the rule now requires.
- The 403 is not a challenge at all. Error 1020 (Access denied) means a firewall rule blocks you outright, and no cookie will change that.
How do you get cf_clearance programmatically?
You need a real browser to pass the challenge, then you hand the cookie to your HTTP client. NSLSolver runs that browser step for you: POST the page URL, the challenge site_key and your proxy to /solve with type "challenge", and you get back cf_clearance plus the user_agent it was minted with. The average solve takes about 3.3 seconds and costs $1.00 per 1,000 successful solves; failed solves are not billed.
The proxy is required because the cookie is earned from that proxy's exit IP. The site_key is the challenge widget id (it starts with 0x): open the page with DevTools, find the request to challenges.cloudflare.com ending in /new/normal in the Network tab, and copy the path segment after /rch/xxxxx/. Optionally pass user_agent and accept_language to have the cookie minted with the exact headers your client will send.
Use this on your own sites, on staging and QA environments, and on sites whose terms allow automated access.
# 1) Ask NSLSolver for a cf_clearance minted through YOUR proxy
curl -s https://api.nslsolver.com/solve \
-H "X-API-Key: nsl_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "challenge",
"url": "https://example.com/protected-page",
"site_key": "0x4AAAAAAA...",
"proxy": "http://user:pass@sticky-proxy.example.com:8080"
}'
# Response (200 OK)
# {
# "success": true,
# "type": "challenge",
# "cookies": { "cf_clearance": "LnMR5BKt0.dCjH..." },
# "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...",
# "cost": 0.001
# }
# 2) Replay the cookie with the SAME proxy and the returned user_agent
curl -s https://example.com/protected-page \
-x "http://user:pass@sticky-proxy.example.com:8080" \
-A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) ..." \
-b "cf_clearance=LnMR5BKt0.dCjH..."Reuse cf_clearance in Python (curl_cffi)
The pattern is: one proxy, one solve, many requests. The session below sends every request through the same sticky proxy, sets the returned user_agent and cookies, and solves again only when Cloudflare answers with a challenge. curl_cffi reproduces a Chrome TLS and HTTP/2 fingerprint; plain requests works on many sites, but it is the first thing to change if a valid cookie keeps getting rejected.
# cf_clearance_session.py (pip install curl_cffi)
# Solve once, reuse cf_clearance through the same proxy, re-solve when it stops working.
import threading
from curl_cffi import requests
API_KEY = "nsl_YOUR_API_KEY"
PROXY = "http://user:pass@sticky-proxy.example.com:8080" # sticky exit IP
SITE_KEY = "0x4AAAAAAA..." # challenge widget id of the target (see above)
def is_challenge(resp) -> bool:
"""True when Cloudflare answered with a challenge instead of the page."""
if resp.headers.get("cf-mitigated") == "challenge":
return True
body = resp.text[:5000]
return resp.status_code in (403, 503) and (
"Just a moment..." in body or "/cdn-cgi/challenge-platform/" in body
)
class ClearanceSession:
def __init__(self, proxy: str):
self.proxy = proxy
self.cookies: dict = {}
self.generation = 0
self.lock = threading.Lock()
# Browser-like TLS + HTTP/2 fingerprint; keep it on a Chrome target
# when the returned user_agent is a Chrome UA.
self.s = requests.Session(impersonate="chrome")
self.s.proxies = {"http": proxy, "https": proxy}
def solve(self, url: str) -> None:
r = requests.post(
"https://api.nslsolver.com/solve",
headers={"X-API-Key": API_KEY},
json={"type": "challenge", "url": url, "site_key": SITE_KEY, "proxy": self.proxy},
timeout=120,
)
data = r.json()
if r.status_code != 200 or not data.get("success"):
raise RuntimeError(f"solve failed: {r.status_code} {data}")
# Reuse BOTH values: the cookie only works with the identity that earned it.
self.s.headers["User-Agent"] = data["user_agent"]
self.cookies = dict(data["cookies"]) # cf_clearance (+ any others returned)
self.generation += 1
def _fetch(self, url: str):
return self.s.get(url, cookies=self.cookies, timeout=30)
def get(self, url: str):
seen = self.generation
resp = self._fetch(url)
if is_challenge(resp): # first visit, expired, or rejected cf_clearance
with self.lock: # one solve per proxy IP, not one per thread
if self.generation == seen:
self.solve(url)
resp = self._fetch(url)
return resp
cf = ClearanceSession(PROXY)
for page in range(1, 51):
r = cf.get(f"https://example.com/catalog?page={page}")
print(page, r.status_code)Reuse cf_clearance in Node.js
The same flow in Node.js uses undici's ProxyAgent so that the solve and every later request use the same exit IP. Node's TLS fingerprint is not a browser's. If the site keeps challenging a fresh cookie with the right IP and User-Agent, move those requests to a browser-impersonating client.
// cf-clearance.mjs (Node 18+, npm i undici)
import { fetch, ProxyAgent } from "undici";
const API_KEY = "nsl_YOUR_API_KEY";
const PROXY = "http://user:pass@sticky-proxy.example.com:8080";
const SITE_KEY = "0x4AAAAAAA...";
const dispatcher = new ProxyAgent(PROXY); // same exit IP for every request
let clearance = null; // { cookie, userAgent }
async function solve(url) {
const res = await fetch("https://api.nslsolver.com/solve", {
method: "POST",
headers: { "X-API-Key": API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ type: "challenge", url, site_key: SITE_KEY, proxy: PROXY }),
});
const data = await res.json();
if (!res.ok || !data.success) {
throw new Error("solve failed: " + res.status + " " + JSON.stringify(data));
}
clearance = {
cookie: Object.entries(data.cookies).map(([k, v]) => k + "=" + v).join("; "),
userAgent: data.user_agent, // replay this exact UA
};
}
function isChallenge(res, body) {
if (res.headers.get("cf-mitigated") === "challenge") return true;
return [403, 503].includes(res.status) &&
(body.includes("Just a moment...") || body.includes("/cdn-cgi/challenge-platform/"));
}
async function fetchOnce(url) {
const headers = clearance ? { Cookie: clearance.cookie, "User-Agent": clearance.userAgent } : {};
const res = await fetch(url, { dispatcher, headers });
return { res, body: await res.text() };
}
export async function get(url) {
let { res, body } = await fetchOnce(url);
if (isChallenge(res, body)) { // first visit, expired, or rejected cf_clearance
await solve(url);
({ res, body } = await fetchOnce(url));
}
return { status: res.status, body };
}
for (let page = 1; page <= 20; page++) {
const { status } = await get("https://example.com/catalog?page=" + page);
console.log(page, status);
}How do you detect an expired cf_clearance and re-solve?
Do not try to predict expiry exactly. Detect the challenge on each response and renew the cookie when you see one:
- Check the cf-mitigated response header first. Cloudflare documents challenge as its only value, and it is set on every challenge page type.
- As a fallback, treat a 403 or 503 whose body contains "Just a moment..." or /cdn-cgi/challenge-platform/ as a challenge.
- On a challenge, solve once and retry the request once. If the retry is challenged again, stop and check the proxy, User-Agent and client fingerprint instead of looping.
- Share one cf_clearance per proxy IP across workers, behind a lock, so that ten threads hitting expiry at the same time trigger one solve, not ten.
- If you know the window (from measurement or because it is your zone), refresh a little before it ends to avoid a failed request at the boundary.
Troubleshooting cf_clearance problems
| Symptom | Likely cause | Fix |
|---|---|---|
| 403 right after a successful solve | Request sent through a different IP, or without the proxy | Send every request through the proxy you passed to /solve |
| Challenge page again despite cf_clearance | User-Agent differs from the returned user_agent | Set User-Agent to the user_agent value exactly |
| Cookie works in curl_cffi but not in requests or Node | TLS / HTTP/2 fingerprint does not look like a browser | Use curl_cffi with a Chrome target, or another browser-grade client |
| Worked for a while, then challenged again | Challenge Passage window ended (30 min by default) | Detect the challenge and solve again |
| Challenged well before 30 minutes | Shorter Challenge Passage on that zone, or the session was flagged | Re-solve on detection, keep headers consistent, lower the request rate |
| Random 403s on a rotating proxy | Exit IP changes between requests | Use a sticky session and one cookie per IP |
| 403 with error 1020 (Access denied) | A firewall rule blocks you; there is no challenge to solve | Change IP or request profile; a cookie will not help |
| 429 Too Many Requests | Rate limiting rule; Challenge Passage does not apply to it | Slow down; cf_clearance does not exempt you |
| /solve returns 400 | Missing or invalid url, site_key or proxy | Check the 0x... site_key and the protocol://user:pass@host:port proxy format |
Only successful solves are billed, so retrying a failed solve does not cost extra.