When does turning on Cloudflare's Under Attack mode help during a layer-7 attack, and what does it cost real users and API clients?
answer
- an interstitial for every visitor
- browsers pass, scripts do not
- scope it with a Configuration Rule
- cf_clearance and Challenge Passage
basics
~20 sUnder Attack mode puts a Managed Challenge page before every matching request, stopping floods that slip under the DDoS rules, but it breaks API, mobile and fetch clients; use it as a last resort, scoped by a Configuration Rule.
solid answer
~40 sUnder Attack mode is off by default. When on, every matching request gets an interstitial Managed Challenge page: browsers that pass it get a `cf_clearance` cookie, valid for the Challenge Passage period (30 minutes by default), and suspicious clients are stopped. It helps against a layer-7 flood the DDoS managed rules are not catching, typically aimed at HTML pages. The cost: the challenge needs a JavaScript-capable browser and returns HTML with `cf-mitigated: challenge`, so `fetch()` calls, mobile apps, partner integrations and monitors fail, and analytics drop. Since the new security dashboard, it is turned on through Security Level; to scope it, use a Configuration Rule's I'm Under Attack setting on the paths under attack, or turn it off for `/api`.
code
json · 13 lines{
"rules": [
{
"ref": "under_attack_event_pages",
"expression": "starts_with(http.request.uri.path, \"/events\")",
"description": "Turn on Under Attack mode for event pages only",
"action": "set_config",
"action_parameters": {
"security_level": "under_attack"
}
}
]
}go deeper
Know that Under Attack mode shows an interstitial challenge to every matching visitor, is off by default, and is a last resort during a layer-7 attack.
Explain cf_clearance and the 30-minute Challenge Passage default, why fetch, mobile and partner clients fail, and how a Configuration Rule's I'm Under Attack setting scopes the mode.
Reach for it when the DDoS rules miss an attack on browser pages, scoped to those paths, with API paths left out and the cf-mitigated header handled in the front end.
Decide in advance who may switch it on, for which paths, and when it comes off, weighing a lost API and skewed analytics against a flood that the managed rules and rate limits are not stopping.
## What Under Attack mode does **Under Attack mode** is a zone setting that performs extra checks to mitigate layer-7 DDoS attacks. When it is on, matching visitors receive an **interstitial challenge page**, a Managed Challenge, before the site loads. Validated users continue to the site; suspicious traffic is blocked. It is **off by default**, and Cloudflare describes it as one of the last resorts when a zone is under attack, because it temporarily pauses access for everyone it covers and affects site analytics. After a visitor passes, Cloudflare sets the `cf_clearance` cookie. The visitor is not challenged again until the **Challenge Passage** period expires: 30 minutes by default, with 15 to 45 minutes recommended, configurable in the zone's security settings. ## When it helps The DDoS docs list Under Attack mode, alongside WAF custom rules and rate limiting rules, as the response to a **false negative**: attack traffic the managed rulesets do not mitigate because it stays under their thresholds or matches no rule. It works best when: - the attack targets **HTML pages** that real people open in browsers, such as an event listing or a landing page; - the attacking clients cannot run the challenge, as with simple scripted floods; - you can limit it to the **paths under attack** rather than the whole zone. It adds little when the HTTP DDoS rules are already mitigating the flood, and it cannot help an origin that attackers reach directly by IP address, which never passes through Cloudflare. ## What it costs | Client | Under Attack mode | Why | |---|---|---| | Browser on a normal page | Waits for the interstitial, then continues | Runs the challenge, gets `cf_clearance` | | Single-page app `fetch()` / XHR | Fails | Gets an HTML challenge page it cannot render or solve | | Native mobile app or partner API client | Fails | No browser to run the challenge | | Uptime monitor, webhook sender | Fails or reports an outage | Same reason | | Third-party analytics | Undercounts | The interstitial needs JavaScript and delays the real page | Every challenge page response, whatever was requested, comes back as `text/html` with the header `cf-mitigated: challenge`. A front end can test for that header to tell a challenge from a real API error, but it still cannot complete the challenge inside a `fetch()`. For a ticketing site this matters: buyers in a queue see an interstitial on every page that matches, and the mobile app's API calls stop working while the mode is on for them. ## Turning it on, and scoping it How it is switched on depends on the dashboard: 1. **Whole zone.** In the new security dashboard and the Cloudflare API, it is the **Security Level** setting. In the old dashboard, Security Level is fixed at *Always protected* and Under Attack mode is a separate toggle in the zone overview's Quick Actions. 2. **Selected paths or hosts.** A **Configuration Rule** with the **I'm Under Attack** setting (API property `security_level`, values `off`, `essentially_off`, `under_attack`) turns the mode on or off for matching requests. Configuration Rules replace the Page Rules once used for this. 3. **Trusted networks.** An IP Access Rule with the **Allow** action exempts the listed visitors from security checks, including Under Attack mode. A practical pattern for an attack on public pages: - a Configuration Rule turns Under Attack mode on for `/events` and the home page only; - if the mode is on zone-wide, a second Configuration Rule turns it off for `/api` so the app keeps working, while the DDoS rules, rate limiting rules and WAF custom rules keep protecting those paths; - Challenge Passage stays near the default so buyers are not challenged on every page. ## Turning it off Treat it as an incident setting with an owner and an end time. Once the attack subsides, or a narrower control replaces it, switch it off; while it stays on, legitimate clients that cannot pass a challenge are locked out and analytics stay distorted. Before switching it off, read the security events. If the HTTP DDoS rules, a rate limiting rule or a WAF custom rule now catch the attack traffic on their own, Under Attack mode is adding cost for real users without adding protection, and narrowing or removing it is the right call.
- A Configuration Rule turns Under Attack mode on for /events; why do buyers not see the interstitial on every page view there?After a visitor passes the challenge, Cloudflare sets the cf_clearance cookie, and no new challenge is shown while it is valid. Its lifetime is the zone's Challenge Passage setting, 30 minutes by default, with 15 to 45 minutes recommended. A cookie-less client such as a script or many API clients never holds clearance, so it is challenged on every request.
- How can a single-page app tell that its API call hit a Cloudflare challenge rather than a server error?Challenge page responses carry the header cf-mitigated set to challenge, its only valid value, and a text/html content type whatever was requested. The app can check response.headers.get("cf-mitigated") and show a reload prompt, but it cannot solve the challenge inside fetch(), so the better fix is keeping Under Attack mode off for API paths.
A venue under threat checks every arriving guest at the door: ticket holders queue a little and get in, but a courier sent by a partner company, with no ticket and no time to queue, is turned away. Under Attack mode is that door check, so scope it to the entrances under threat.
- Leaving Under Attack mode on zone-wide for days as a standing defence.
- Expecting mobile apps and API clients to pass the interstitial challenge on their own.
- Scoping Under Attack mode with a Page Rule, a deprecated feature, instead of a Configuration Rule.
- Believing Under Attack mode protects an origin that attackers reach directly by IP.
- Thinking Under Attack mode replaces the always-on DDoS managed rulesets.
Assumes Cloudflare as of 2026-10-10: in the new security dashboard and the API, Under Attack mode is set through Security Level, and per-path scoping uses Configuration Rules since Page Rules were deprecated.