Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 36 ยท Security: WAF and DDoS

Cloudflare DDoS Protection, Bot Management and Turnstile

How Cloudflare stops DDoS attacks automatically, what Under Attack Mode and Bot Fight Mode do, how bot scores work, and how to use Turnstile CAPTCHA alternative.

A distributed denial-of-service (DDoS) attack tries to make a site unusable by overwhelming it with traffic from thousands of machines. Bots do quieter harm: scraping prices, stuffing stolen passwords into login forms, hoarding tickets. Cloudflare's network is built to absorb the first and detect the second. This lesson covers what is automatic, what you can configure, and how to keep real users out of the crossfire.

Kinds of DDoS attacks

Three layers of attack

Volumetric Fill the pipe with junk
Protocol Abuse TCP and UDP handshakes
Application Many costly HTTP requests

Different layers need different defenses.

1 / 2
  • Volumetric (layers 3/4): UDP or amplification floods that saturate your connection with sheer gigabits. Cloudflare absorbs them because its capacity is far larger than any attack, and anycast splits the load across data centers.
  • Protocol attacks: SYN floods and similar abuses of connection setup, filtered by the network edge with stateful and heuristic defenses.
  • Application layer (layer 7): floods of HTTP requests that each look valid, such as repeated search queries. These are the ones your own rules help with.

What is on by default

For every proxied zone on every plan, including Free:

  • Network-layer DDoS protection is always on and unmetered.
  • HTTP DDoS Attack Protection, a managed ruleset, detects and mitigates HTTP floods automatically by fingerprinting the attack traffic and blocking or challenging matching requests. You can see its events in Security > Events with the source "HTTP DDoS".
  • You are not billed more because of attack size.

On paid plans you can adjust each rule's sensitivity and action (for example from Block to Log, or from High to Medium sensitivity) under Security > DDoS. Leave the defaults unless you see false positives, such as an unusual but legitimate traffic spike from your own marketing campaign; then lower sensitivity or create a Skip exception for a specific path.

Important: DDoS protection only covers traffic that goes through Cloudflare. If attackers know your origin IP, they bypass everything. Lock the origin firewall to Cloudflare's IP ranges or use Tunnel (proxy status lesson).

Under Attack Mode

I'm Under Attack Mode (a security level setting, also reachable from the dashboard's quick actions) shows every visitor a short interstitial page with a JavaScript challenge before they reach the site. Real browsers pass in a few seconds; simple bots fail. Use it as an emergency measure during a live layer-7 attack and then switch it off, because it adds friction for everyone and breaks non-browser clients such as API consumers, feeds and mobile apps. A better long-term approach is targeted rate limiting and rules for the attacked path.

Bots

Roughly half of web traffic is not human. Bots are not all bad: search engines, uptime monitors and payment webhooks are verified bots, which Cloudflare recognizes through reverse-DNS and published IP ranges. The harmful ones scrape, scan, stuff credentials or hoard inventory.

Product Plan What it does
Bot Fight Mode Free A single switch that challenges requests from known bad bot patterns
Super Bot Fight Mode Pro and Business Separate actions for definitely automated, likely automated and verified bots, plus static resource handling
Bot Management Enterprise A per-request bot score from 1 (certainly a bot) to 99 (certainly human), JA3/JA4 fingerprints, and rule fields such as cf.bot_management.score

Bot scores come from machine learning over huge traffic samples, behavioral analysis, fingerprints and heuristics. With Bot Management you can write rules like "challenge POST /login when the score is below 30" and "allow verified bots".

JS Stand-in: a toy bot scorer

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The careful scraper imitates a browser well enough to be challenged rather than blocked, which is the realistic outcome: scores sort traffic into likely good, uncertain and likely bad, and you pick the action per band.

Challenges and Turnstile

When Cloudflare is unsure, it shows a challenge. Managed Challenge chooses the lightest test that works: usually an invisible browser check, sometimes a click. It replaces the old picture CAPTCHAs.

Turnstile is the same technology offered to your own pages, as a free, privacy-friendly CAPTCHA alternative that works even if the site is not behind Cloudflare. You create a widget in the dashboard, which gives a site key (public) and a secret key (private):

HTML
<form method="post" action="/signup">
  <input name="email" type="email" required>
  <div class="cf-turnstile" data-sitekey="YOUR_SITE_KEY"></div>
  <button>Sign up</button>
  <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
</form>

The widget adds a hidden field named cf-turnstile-response to the form. Your server must verify it, otherwise a bot can simply skip the widget:

Terminal
curl https://challenges.cloudflare.com/turnstile/v0/siteverify \
  -d "secret=$TURNSTILE_SECRET" \
  -d "response=$TOKEN_FROM_FORM" \
  -d "remoteip=$CLIENT_IP"

The reply is JSON with "success": true or false and error codes. Tokens are single-use and expire after a few minutes. Never expose the secret key in client code.

JS Stand-in: server-side token verification

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The replay fails because tokens are single-use: that is the property that stops a bot from reusing one solved challenge for thousands of signups.

A practical defense plan

  1. Keep the DDoS managed rulesets at defaults and check Security > Events weekly.
  2. Hide the origin IP and block non-Cloudflare traffic at the origin firewall.
  3. Turn on Bot Fight Mode (or Super Bot Fight Mode) and allow verified bots.
  4. Add rate limits to login, signup, search and other costly endpoints.
  5. Put Turnstile on public forms and verify it on the server.
  6. Keep Under Attack Mode in your runbook for emergencies, with the steps to turn it off.
  7. Set up notifications for DDoS and WAF events (alerts in chapter 8).

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which DDoS protection is active on the Free plan?

    DDoS mitigation is included on every plan for proxied traffic.
  2. 2. When should Under Attack Mode be used?

    It challenges every visitor and breaks API clients, so turn it off after the attack.
  3. 3. What does a bot score of 3 mean in Bot Management?

    Scores run from 1 (automated) to 99 (human).
  4. 4. Why must a Turnstile token be verified on the server?

    Only the secret-key verification on your backend proves a challenge was passed.
  5. 5. What defeats DDoS protection regardless of settings?

    Traffic that bypasses Cloudflare is not protected by it.

Summary

  • Cloudflare absorbs volumetric and protocol attacks with anycast capacity and runs HTTP DDoS rulesets automatically, on every plan.
  • Under Attack Mode is an emergency switch; targeted rate limits and rules are the lasting fix.
  • Bots are scored and sorted: Bot Fight Mode for free, Super Bot Fight Mode on mid plans, Bot Management on Enterprise.
  • Turnstile gives a privacy-friendly CAPTCHA alternative; always verify tokens on the server.
  • Protect the origin so attackers cannot go around the edge.

Next: Cloudflare Workers: What They Are and Why They Matter