Cloudflare Under Attack mode stops a layer 7 DDoS attack, a flood of HTTP requests aimed at your site, by putting a challenge page in front of every visitor. Everything that isn’t a browser fails that challenge: your API clients, your mobile app, the webhooks other services send you. When the attack’s requests share something, such as one path, a few IP addresses or one network, a WAF rule that matches only them stops the attack and leaves the rest of your traffic alone. Lelops Sentry alerts you when requests leave your zone’s usual range and shows which IP addresses send them, and Ask Lelops, the chat in Lelops Advise, writes the rule that blocks only the attack, saved as a version you can restore.
What Cloudflare Under Attack Mode Does and What It Breaks
Under Attack mode makes Cloudflare answer each new visitor of the zone with a Managed Challenge page, which needs JavaScript to be displayed and passed. A browser that passes gets a cf_clearance cookie and is not challenged again until it expires, after 30 minutes by default. Cloudflare calls the mode one of the last resorts and warns that it pauses access to your site and affects its analytics.
Clients that run no browser never pass: API clients, mobile apps, payment providers posting webhooks, uptime checks. Cloudflare’s own caution gives your API traffic as its example. They receive the challenge page instead of your response, with the header cf-mitigated: challenge and a content type that is always text/html, so a client expecting JSON fails to read it. Your own pages break the same way when they load data with JavaScript after the visitor’s cookie expired, because the challenge fails when the browser expects a non-HTML response.
How to Turn On Cloudflare Under Attack Mode

Exempt your API first, then turn the mode on in the dashboard or through the API.
- Exempt your API. Create a configuration rule that matches it, for example URI Path starts with
/api/, then in its settings, for I’m Under Attack, select Add and set the toggle to Off. Add the paths that receive webhooks to the same rule. Configuration rules are available on every plan. - Turn the mode on. In the dashboard, turn on Under Attack Mode in the zone’s Quick Actions sidebar, or under Security > Settings in the new security dashboard. Through the API, read the current value with
GET /zones/{zone_id}/settings/security_level, then send aPATCHto the same path with{"value": "under_attack"}and a token that has Zone Settings Write (Edit zone setting). - Check what is still challenged. A
cf-mitigated: challengeheader in your clients’ errors tells a challenged call apart from an origin that is down, and a path that still gets it needs adding to the rule. - Turn it off when the attack is over. We recommend waiting until the request rate is back in its usual range for that time of day for three 5-minute windows in a row, counting challenged requests too: counted at the origin only, the challenge itself makes the attack look finished. Then switch the toggle off or send back the value you read, and delete the configuration rule, since a setting changed during an attack and never changed back is configuration drift.
How to Block an Attack Without Under Attack Mode

Find what the attack’s requests have in common, then block only the requests that match it. Cloudflare’s HTTP DDoS managed ruleset is always on and stops the attacks it detects; these steps are for the requests that still get through.
- Find what the attack’s requests share. Open the zone’s Analytics page under Security, which shows Security Analytics on every plan: every request, whether or not Cloudflare acted on it. Set the time frame to the attack and look for a value that stands out in the top statistics: a path, a source IP address, an ASN (the network an IP address belongs to), a country or a user agent. Select Filter on it to see the attack’s requests alone, or Exclude to check that what is left looks like your usual traffic.
- Turn your filters into a rule. Select Create custom security rule above the main chart. Cloudflare builds a WAF custom rule from your filters, for example
http.request.uri.path eq "/search" and ip.src.asnum eq 64500, where 64500 is the network you found. Choose Block, or Managed Challenge if real visitors share the same trait, then select Deploy. The Free plan includes five custom rules (how they fit with the other rule types). - Rate limit the path if the senders keep changing. When the attack comes from too many addresses to list, a rate limiting rule on the attacked path blocks each IP address that goes over the rate you set.
- Check the rule matches. Its matches show in Security Events, and the requests Served by origin in Security Analytics fall. If nothing stands out, with requests spread over every path, address and network, that is the case Under Attack mode is for.
How to Find and Block an Attack with Lelops

Lelops Sentry tells you when an attack starts and shows who sends it, and Lelops Advise, the Ask Lelops chat in the same app, reads the attacked paths and writes the rule, saving each change as a version.
- Connect Cloudflare with the right token. When you connect, the Resources & permissions screen lists what your API token allows. Lelops needs read access; for Ask Lelops to add rules, the token must also allow editing WAF rules, plus Zone Settings Write to switch Under Attack mode.
- Read the alert. Sentry compares each zone’s requests, in 5-minute windows, with the zone’s usual level for that time of day, weekdays and weekends apart. After two windows in a row above it, an alert opens in Alerts with the observed rate and the baseline in requests per minute, and a Lelops AI recommendation. Select Acknowledge so the rest of your team sees that someone is on it.
- See who sends the traffic. Open Sentry > Monitoring and set Zones to the attacked zone and the time range to the alert’s. The Traffic tab shows the Total volume of requests and Top10 IP, the addresses that sent the most requests. The Security tab shows Traffic by Bot score, which splits requests into Automated, Human and Verified Bot.
- Ask for the attacked paths. In Ask Lelops, write, for example, “Which paths on example.com got the most requests in the last hour?” Ask Lelops reads the zone’s top 50 paths for that time range from Cloudflare’s analytics.
- Ask for the rule. Write “Add a custom rule on example.com that blocks requests to /search from these IP addresses”, followed by the addresses from Top10 IP. Ask Lelops creates the WAF custom rule, with Block, Managed Challenge or another challenge action, and saves the change as a version in Versioning. If the traffic shares nothing a rule can match, exempt your API in Cloudflare as above and ask “Turn on Under Attack mode for example.com.”, which also saves a version.
- Check what the rule stops. Ask “Show the last security events on example.com.” Ask Lelops lists the 50 most recent security events, each with its action, the rule’s ID, the IP address, the path, the user agent and the country.
- Close the incident. Sentry’s count includes the requests Cloudflare blocked, so the alert stays open while the attack goes on, even once your rule stops it. After three normal windows in a row, the alert ends and its status becomes Dismissed. Keep the rule, or ask Ask Lelops to delete it. In Versioning, Restore and deploy brings back the zone’s custom rules as they were before the change.
Lelops shows who sends an attack and turns what you find into a rule that blocks only it, saved as a version you can restore: lelops.ai/product/advise.
FAQ
What does Cloudflare Under Attack mode do?
Cloudflare Under Attack mode is the emergency setting for a flood of HTTP requests that gets past Cloudflare's automatic DDoS protection. Every visitor of the zone is checked with a challenge page before the site loads, and only browsers that pass the check reach it. Scripts, apps and integrations don't pass, so they stop working until the mode is off.
Can I stop a DDoS attack without Cloudflare Under Attack mode?
Yes, when the attack's requests share something you can match, such as one path, a few IP addresses, one network or one user agent. Filter the attack in Cloudflare's Security Analytics, then create a WAF custom rule from those filters with the Block or Managed Challenge action. Only the matching requests are stopped, and the rest of your traffic, your API included, keeps working.
Why do API calls fail when Cloudflare Under Attack mode is on?
API clients don't run JavaScript in a browser, so they can't pass the challenge page. They receive that page as an HTML response carrying the header cf-mitigated: challenge, instead of the data they asked for. That header lets engineers tell a challenged call apart from an origin that is down.
Can Cloudflare Under Attack mode be turned on for only part of a site?
Yes. A configuration rule can switch Under Attack mode on for matching requests only, such as one attacked path, or off for matching requests, such as an API, while the rest of the zone stays in the mode. Configuration rules are available on every Cloudflare plan.
Should Cloudflare Under Attack mode stay on after an attack?
No. Cloudflare describes it as one of the last resorts and warns that it pauses access to the site and affects its analytics. Switch it off once request rates are back to their usual level, and keep any protection you still need as a rule scoped to the attacked path, such as a custom rule or a rate limiting rule.
Christophe Pronier


