With a Cloudflare WAF custom rule on logins from countries you do not serve, why choose Managed Challenge over Block, and where does it fail?
answer
- country is a coarse signal
- Cloudflare picks the challenge type
- cf_clearance after passing
- challenge pages are HTML
basics
~20 sManaged Challenge lets a real person caught by a broad rule pass, usually without a click, while Block refuses everyone it matches. It fails for clients that cannot render a challenge page: fetch calls, mobile apps, server-to-server integrations.
solid answer
~50 sA country rule is broad: it also catches travellers, VPN users and customers whose address geolocates wrongly. With **Managed Challenge**, Cloudflare picks the challenge from the request's signals. Most humans pass a non-interactive check, some get an interactive one, and a pass sets a `cf_clearance` cookie for the Challenge Passage period, 30 minutes by default. Automated clients mostly give up. Block would turn all those real people away, so Cloudflare recommends Managed Challenge for most WAF rules. Its limit is that a challenge is an HTML page. A `fetch()` call, a native app or a partner's backend cannot solve it and just receives HTML with `cf-mitigated: challenge`. So I would scope the rule to the login page browsers load, `http.request.uri.path eq "/login" and not ip.src.country in {"DE" "AT" "CH"}`, and watch the rule's Challenge Solve Rate for false positives.
code
javascript · 9 linesconst form = new FormData(document.querySelector("form"));
const res = await fetch("/login", { method: "POST", body: form, credentials: "include" });
if (res.headers.get("cf-mitigated") === "challenge") {
// The edge returned a challenge page instead of the login result: reload so the browser can solve it.
window.location.assign("/login");
} else {
const result = await res.json();
console.log(result);
}go deeper
Recall that Managed Challenge lets humans through and Block stops everyone, and that a pass sets a cf_clearance cookie.
Explain how Managed Challenge picks a challenge type, how Challenge Passage and clearance levels work, and why a fetch call or app cannot solve a challenge.
Show how you scope a challenge rule away from API, app and partner traffic, and use the Challenge Solve Rate and cf-mitigated to spot false positives.
Frame the action as the price of being wrong: who pays for a false positive under Block versus a challenge, and which rules earn a hard block.
## Why a broad rule needs a softer action The operations team wants logins from countries the business does not serve to face extra friction. The expression is simple: the login path, and a country outside the served set. ```plaintext http.request.uri.path eq "/login" and not ip.src.country in {"DE" "AT" "CH"} ``` `ip.src.country` is the two-letter ISO 3166-1 code Cloudflare derives from the client address. It is a **coarse** signal. It also matches: - customers travelling abroad; - employees and customers on a VPN or corporate proxy that exits elsewhere; - addresses whose geolocation is simply wrong. A **Block** on that rule refuses all of them, and nobody can get through. The right action for a rule that is *likely* right but sometimes wrong lets humans prove themselves. ## How Managed Challenge decides With **Managed Challenge** (API value `managed_challenge`), Cloudflare looks at the request's signals and chooses what to show: 1. a **non-interactive** challenge page, which the browser solves by running JavaScript, usually in under five seconds; 2. an **interactive** challenge, such as clicking a box, when the signals look automated. Most real visitors pass without touching anything. A pass sets a `cf_clearance` cookie tied to that visitor and device. It lasts for the zone's **Challenge Passage**, 30 minutes by default, and Cloudflare recommends a setting between 15 and 45. Clearance also has levels: | Clearance earned | Later challenges it satisfies | |---|---| | Interactive | Interactive, Managed, Non-Interactive | | Managed | Managed, Non-Interactive | | Non-Interactive | Non-Interactive only | Cloudflare's documentation recommends Managed Challenge for most WAF rules, and other challenge types only for specific compatibility issues. Non-Interactive Challenge (`js_challenge`) and Interactive Challenge (`challenge`) remain available. ## Where a challenge cannot work A challenge is a full **HTML** page that interrupts the request, and its content type is `text/html` whatever was requested. So it fails for any client that cannot render and solve a page: - a single-page app's `fetch()` or XHR call to a JSON endpoint; - a native mobile app calling the API directly; - a partner's server-to-server integration, a monitoring probe or a webhook sender. Those clients get HTML they cannot use. Every challenge response carries `cf-mitigated: challenge`, so a front end can detect it and react. The usual design challenges the **HTML page** a browser loads, so the visitor carries `cf_clearance` into the calls that follow. Programmatic clients are kept out of the rule's scope, by path or with a Skip rule above it. Turnstile pre-clearance is the dedicated way to protect API calls from a browser, covered with bot defences. ## Writing the country rule well The action is only half the design; the expression decides who meets the challenge at all. - **List the countries you serve** and negate the set, `not ip.src.country in {"DE" "AT" "CH"}`, rather than enumerating everyone else. The served set is short and changes only when the business does. - **Scope to the login surface.** Matching the login path, and the method if the form posts, keeps browsing, assets and public pages free of friction. - **Use the current field names.** `ip.src.country` holds the same value as the deprecated `ip.geoip.country`; new rules should use the former. - **Know the special codes.** Cloudflare marks Tor exit traffic with the continent code `T1` in `ip.src.continent`, a separate field from the country code, should the team want to treat Tor differently. - **Put exceptions above the rule.** A partner or monitoring service that logs in from abroad gets a Skip rule placed before this one, because custom rules run top to bottom. ## Measuring whether the rule is too broad For a custom rule with a challenge action, the Security rules page shows its **Challenge Solve Rate (CSR)**: challenges solved divided by challenges issued. - Most automated traffic abandons a challenge immediately, so a rule aimed at bots should show a **low** CSR. - A **high** CSR means many real visitors are solving it, the false-positive signal: the rule matches too much legitimate traffic. - Security Events lists `challengeSolved` events. These record that an earlier challenge was answered, not a fresh match of the rule. ## When Block is still right Block suits a rule with no legitimate matches at all, for example a path that should never be reachable from outside, or a scraper's networks on one endpoint once events confirm that. For broad, probabilistic rules such as geography, Managed Challenge keeps the cost of being wrong low.
- How long does a solved challenge keep a visitor from being challenged again?Passing sets a `cf_clearance` cookie whose lifetime is the zone's Challenge Passage, 30 minutes by default, with 15 to 45 minutes recommended. While it is valid, the visitor passes challenges at or below the level they solved. An interactive clearance covers Managed and Non-Interactive Challenges too. Challenge Passage does not apply to rate limiting rules.
- What does a high Challenge Solve Rate on this rule tell you?That a large share of the challenges it issues are being solved, so many matched visitors are real people. Bots mostly abandon challenges, so a rule aimed at them should show a low rate. A high rate is the false-positive signal: narrow the expression, for example by adding the served countries a sales team travels to, or by limiting the rule to the login path.
- A partner's backend logs in through the same path and starts failing. Why, and what do you change?A server-to-server client cannot render or solve a challenge page, so it receives HTML marked with `cf-mitigated: challenge` instead of its login response. Exclude it from the rule: put a Skip rule matching the partner's IP list above the country rule, or move its traffic to a path the rule does not cover.
- Managed Challenge always makes the visitor solve a CAPTCHA.
- A challenge protects a JSON API endpoint exactly as it protects an HTML page.
- A high challenge solve rate proves the rule is stopping attackers.
- Interactive Challenge is Cloudflare's recommended default for WAF rules.
- Blocking by country is safe because legitimate users never travel or use a VPN.