skip to content

Edge Threat Defenses

Cloudflare filters requests at the edge with managed WAF rulesets, custom rules, rate limits, DDoS mitigation and bot detection. Interviewers ask which control fits and how to tune it.

on this pageshow

explore

questions

page 1 of 2

With Cloudflare Turnstile, how do you protect a marketplace's sign-up form, and why must the server call siteverify instead of trusting the widget?

level: juniorimportance: must knowfreq 50%

answer

  1. public sitekey, private secret key
  2. hidden cf-turnstile-response field
  3. server-side POST to siteverify
  4. 300 seconds, spendable once

basics

~20 s

Embed the Turnstile widget with its public sitekey so the form submits a token in cf-turnstile-response. The server posts that token and the secret key to siteverify and creates the account only on success; an unchecked token proves nothing.

solid answer

~40 s

A Turnstile widget has a public **sitekey** and a private **secret key**. Load `api.js` from `challenges.cloudflare.com`, put a `cf-turnstile` div with `data-sitekey` inside the sign-up form, and the widget runs its challenge in the browser and adds a hidden `cf-turnstile-response` field holding a token. On submit, the server POSTs `secret`, `response` and optionally `remoteip` to `https://challenges.cloudflare.com/turnstile/v0/siteverify` and creates the account only when `success` is true, ideally also checking `hostname` and `action`. The widget alone protects nothing: a script can post the form with an invented string, and a token is valid for 300 seconds and only once, so only siteverify can tell a real, fresh, unspent token from a forged or replayed one.

code

html · 7 lines
html
<form action="/signup" method="POST">
  <input type="email" name="email" autocomplete="email" required />
  <input type="password" name="password" autocomplete="new-password" required />
  <div class="cf-turnstile" data-sitekey="<YOUR-SITE-KEY>" data-action="signup"></div>
  <button type="submit">Create account</button>
</form>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>

go deeper

for a junior

Recall the two keys and the two halves: the sitekey and widget in the page, the secret key and siteverify on the server. Say plainly that a form without siteverify is unprotected.

for a middle

Explain the token's life: written to cf-turnstile-response, valid for 300 seconds, spendable once, checked by siteverify, and what success, hostname and action each tell the server.

for a senior

Show production hygiene: the secret held as a server-side secret, one validation per token, dummy keys in CI, hostnames restricted to your own domains, and Turnstile Analytics watched for widgets with no validations.

for a principal

Place Turnstile among the bot controls: a per-form proof of a human, separate from site-wide bot scores, and decide which flows earn a widget so friction lands only where abuse costs money.

## What Turnstile does **Turnstile** is Cloudflare's check that a visitor is a person rather than a script, without an image puzzle. It runs as a JavaScript widget in the visitor's browser, collects client-side signals and runs challenges, and when it is satisfied it produces a **token**: an opaque string of up to 2,048 characters. Your server then asks Cloudflare whether that token is genuine. Both halves are required; the widget on its own is decoration. Turnstile is an independent service. It works on any site, whether or not the site's traffic is proxied through Cloudflare, so a marketplace can put it on a sign-up form wherever that form is served from. Each **widget** you create (in the dashboard or through the API) has: - a **sitekey**, the public identifier you place in HTML; - a **secret key**, the private credential only your server uses; - a **mode**: Managed (recommended; asks for a checkbox click only when a further check is needed), Non-Interactive (a visible spinner, no interaction) or Invisible (nothing shown); - a list of **hostnames** where the widget may load; adding a hostname also allows its subdomains. ## The client side With implicit rendering, the page loads the script and declares a container: 1. Add `<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer>`. The file must be fetched from that exact URL; proxying or caching it breaks the widget when Cloudflare updates it. 2. Place `<div class="cf-turnstile" data-sitekey="...">` inside the `<form>`. 3. Optionally set `data-action="signup"`, a label of up to 32 characters that siteverify returns, so one sitekey can serve several forms and the server can check which form a token was minted for. When the challenge succeeds, the widget writes the token into a hidden input named `cf-turnstile-response` (renamable with `data-response-field-name`) and calls any `data-callback` you set. Single-page apps use explicit rendering with `turnstile.render()` and read the token from the callback or from `turnstile.getResponse(widgetId)`. ## The server side: siteverify The form handler takes the token and sends it to the **Siteverify API**: - endpoint: `POST https://challenges.cloudflare.com/turnstile/v0/siteverify`, with a JSON or form-encoded body; - required: `secret` (the widget's secret key) and `response` (the token); - optional: `remoteip` (the visitor's IP, for example from `CF-Connecting-IP`) and `idempotency_key` (a UUID that makes a retry of the same validation safe). The JSON answer carries `success`, `error-codes`, `challenge_ts`, `hostname`, `action` and `cdata`. Accept the request only when `success` is true and, where you set them, when `hostname` is your domain and `action` is the form you expected. | Answer | What it tells the server | | --- | --- | | `success: true` | A challenge was solved for this widget and the token had not been spent | | `invalid-input-response` | The token is malformed or not one Cloudflare issued | | `timeout-or-duplicate` | The token has already been validated once | | `invalid-input-secret` | The secret key is wrong or no longer valid | ## Why the widget alone protects nothing The browser is the attacker's machine. Three facts make the server-side call mandatory: - **Tokens can be forged.** A script can post your form with any string in `cf-turnstile-response` without ever loading the widget. Only siteverify knows whether Cloudflare issued that string. - **Tokens expire.** Each is valid for 300 seconds after it was generated, so a token farmed earlier fails validation later. - **Tokens are single-use.** A second validation of the same token fails with `timeout-or-duplicate`, so one solved challenge cannot be replayed across a thousand sign-ups. A form that renders the widget but never calls siteverify also shows zero token validations in Turnstile Analytics, which is often how a team discovers the gap. ## Keeping the secret secret The secret key belongs on the server only: in a Worker it is a secret rather than a value in the page, and in any other backend an environment variable or a secret store. Calling siteverify from front-end code would publish the key and let anyone vouch for their own tokens. If a key leaks, **Rotate Secret Key** in the widget's settings issues a new one, and the old and new keys both stay valid for two hours while you deploy it. For automated tests, Cloudflare publishes dummy keys: the sitekey `1x00000000000000000000AA` always passes and the secret `1x0000000000000000000000000000000AA` always validates, while production secret keys reject the dummy tokens. Keep `localhost` off a production widget's hostname list.

  • What do data-action and the hostname field add to a Turnstile siteverify check?
    `data-action` labels a widget (up to 32 letters, digits, `_` or `-`) and siteverify echoes it as `action`, so a token minted on the newsletter form cannot be spent on sign-up. `hostname` reports where the challenge was served, confirming the token came from your own page. Both are checked after `success` is true: they narrow what a valid token may be used for.
  • Which Turnstile widget mode suits a marketplace sign-up form, and why?
    Managed mode, which Cloudflare recommends: it runs non-interactively for most visitors and shows a single checkbox only when its signals call for a further check, with no images or text to decipher. Non-Interactive and Invisible never ask for interaction, trading a little assurance for zero friction. Whichever mode you choose, the server-side siteverify call is the same.
  • How do you test a Turnstile-protected form in CI without real challenges?
    Use Cloudflare's dummy keys: the sitekey `1x00000000000000000000AA` always passes, `2x00000000000000000000AB` always fails, and the secret `1x0000000000000000000000000000000AA` always validates while `3x0000000000000000000000000000000AA` returns a token-already-spent error. Dummy keys work on any domain, including `localhost`, and production secret keys reject dummy tokens, so a test key cannot leak into production unnoticed.

A Turnstile token works like a numbered cloakroom ticket: the attendant who issued it checks the number against their own book and tears the ticket up when the coat is collected. A ticket drawn at home fails the book check, and the same ticket cannot collect a second coat.

  • The widget's success callback proves the visitor is human, so the server can skip siteverify.
  • The secret key can sit in front-end JavaScript beside the sitekey.
  • Turnstile only works on sites whose traffic is proxied through Cloudflare.
  • One Turnstile token can be reused for every form the visitor submits in a session.
  • Turnstile makes every visitor solve an image puzzle.
open as a page

Behind Cloudflare's proxy, why should an origin firewall accept web traffic only from Cloudflare's IP ranges, and how is that list kept current?

level: juniorimportance: must knowfreq 65%

basics

~20 s

Proxying hides the origin's address but cannot stop anyone who already knows it. Accepting web traffic only from Cloudflare's published ranges makes the proxy the only way in; sync the list from www.cloudflare.com/ips or the API's /client/v4/ips endpoint.

open as a page

In Cloudflare, what does a rate limiting rule count, and what happens to a client that goes over its threshold?

level: juniorimportance: must knowfreq 62%

basics

~20 s

A Cloudflare rate limiting rule counts matching requests, one counter per value of its characteristics such as the client IP. Once a counter passes requests per period, the action, such as Block with status 429, applies for the configured duration.

open as a page

In a Cloudflare WAF custom rule, what do the expression and the action do, and how would you block a scraper on one search endpoint?

level: juniorimportance: must knowfreq 62%

basics

~20 s

A WAF custom rule pairs a Rules language expression, which tests request fields such as http.request.uri.path and ip.src.asnum, with an action such as Block or Managed Challenge that Cloudflare applies to every request the expression matches.

open as a page

In Cloudflare Bot Management, what does a bot score from 1 to 99 mean, and how do you act on cf.bot_management.score in a rule?

level: middleimportance: must knowfreq 42%

basics

~20 s

The bot score is Cloudflare's confidence that a request is automated: 1 almost certainly a bot, 2-29 likely automated, 30-99 likely human, 0 not scored. Enterprise Bot Management exposes it as cf.bot_management.score for custom rules, Workers and logs.

open as a page

In Cloudflare's HTTP DDoS Attack Protection, how do sensitivity levels, actions and overrides work, and which override wins when several match?

level: middleimportance: must knowfreq 40%

basics

~20 s

Each rule has a sensitivity level (High by default, then Medium, Low, Essentially Off) and an action; an override changes either for the ruleset, a tag or a rule, the most specific scope wins, and the first override matching expression and sensitivity applies.

open as a page

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?

level: middleimportance: must knowfreq 44%

basics

~20 s

Under 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.

open as a page

With a Cloudflare rate limiting rule on a login endpoint, how does a custom counting expression count only failed logins, and what must it repeat?

level: middleimportance: must knowfreq 55%

basics

~20 s

Set Increment counter when to an expression that tests the response, such as http.response.code in {401 403}, so only failed logins add to the counter. It replaces rather than extends the matching expression, so repeat the login path and method in it.

open as a page

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?

level: middleimportance: must knowfreq 58%

basics

~20 s

Managed 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.

open as a page

A SaaS app proxied through Cloudflare still sees attack traffic hitting its origin directly; how did the origin IP likely leak, and in what order do you close it?

level: seniorimportance: must knowfreq 60%

basics

~20 s

Through a path the proxy never covers: a DNS-only record on the same server, mail on that host, DNS history from before onboarding, or the app's outbound calls. Lock the origin to Cloudflare, close every leak, then rotate the IP.

open as a page

In Cloudflare, what do the two DDoS Attack Protection managed rulesets cover, and why can a team tune them but never switch them off?

level: juniorimportance: should knowfreq 38%

basics

~20 s

HTTP DDoS Attack Protection covers layer-7 floods and Network-layer DDoS Attack Protection covers layer-3/4 floods; both are always on and unmetered on every plan, and a team can only override their action and sensitivity, never remove them.

open as a page

In Cloudflare, how do Bot Fight Mode, Super Bot Fight Mode and Bot Management for Enterprise differ in plan, control and exceptions?

level: middleimportance: should knowfreq 36%

basics

~20 s

Bot Fight Mode (Free) challenges bot patterns site-wide and no custom rule can skip it. Super Bot Fight Mode (Pro and up) adds per-group actions and Skip exceptions. Bot Management for Enterprise exposes a per-request score and fields for custom rules.

open as a page

How do Cloudflare's Authenticated Origin Pulls prove an origin request came through Cloudflare, and how do you roll them out without an outage?

level: middleimportance: should knowfreq 50%

basics

~20 s

Authenticated Origin Pulls add mutual TLS to the edge-to-origin connection: Cloudflare presents a client certificate and the origin refuses any HTTPS handshake without a valid one. Install the CA, verify optionally, enable AOP, confirm, then require.

open as a page

How does serving an origin through a Cloudflare Tunnel make the proxy the only way in, and what must you still shut down?

level: middleimportance: should knowfreq 45%

basics

~20 s

With a Cloudflare Tunnel, cloudflared dials out to Cloudflare, so the origin needs no inbound port and can block all inbound traffic. Still close the old public listener, delete records pointing at the old address, and rotate a leaked IP.

open as a page

In Cloudflare Workers, how does the rate limiting binding enforce a per-user limit, and how do its periods and counters differ from a rate limiting rule's?

level: middleimportance: should knowfreq 32%

basics

~20 s

A ratelimits binding sets a namespace_id, a limit and a 10 or 60 second period; the Worker calls limit({ key }) with, say, the account ID and answers with its own 429 when success is false. Counters are per location and approximate.

open as a page

With Cloudflare WAF custom rules, how do you let a partner's fixed IP range past your other security rules, and what exactly does Skip skip?

level: middleimportance: should knowfreq 50%

basics

~20 s

Add a custom rule at the top matching ip.src in $partner_ips on the partner's paths, with the Skip action. Skip bypasses only what you select: remaining custom rules, later phases such as rate limiting, or listed products.

open as a page

How do you test a new Cloudflare WAF custom rule against live traffic before it blocks anyone, on Enterprise and on lower plans?

level: middleimportance: should knowfreq 45%

basics

~20 s

On Enterprise, deploy the rule with the Log action and read its matches in Security Events. Log is Enterprise-only, so on Free, Pro and Business start with Managed Challenge, review the matched requests, then switch to Block.

open as a page

In Cloudflare's WAF, what does the attack score in cf.waf.score measure, and how should a team start acting on it?

level: middleimportance: should knowfreq 30%

basics

~20 s

WAF attack score is a machine-learning detection that gives each request a score from 1 (almost certainly malicious) to 99 (likely clean), catching modified payloads that miss signatures. It acts only through a rule, so start with a strict threshold such as 20.

open as a page

In Cloudflare's WAF, how does leaked credentials detection protect a shop's login endpoint, and what does it leave to your own rules and origin?

level: middleimportance: should knowfreq 30%

basics

~20 s

Leaked credentials detection finds usernames and passwords in requests, checks them against breached-credential data and fills fields such as cf.waf.credential_check.password_leaked. It blocks nothing itself: you challenge with a rule and let the origin force a reset.

open as a page

In Cloudflare's WAF managed rulesets, how does an override differ from an exception (a skip rule), and which wins when both apply?

level: middleimportance: should knowfreq 40%

basics

~20 s

An override changes how managed rules behave for every request the deployment covers: their action or whether they are enabled. An exception is a separate skip rule that bypasses chosen rules or rulesets only for matching requests. Exceptions take priority over overrides.

open as a page

In Cloudflare's WAF, how do the Cloudflare Managed Ruleset and the Cloudflare OWASP Core Ruleset differ in how they decide to act?

level: middleimportance: should knowfreq 42%

basics

~20 s

The Cloudflare Managed Ruleset matches signatures, and each matching rule applies its own action. The OWASP Core Ruleset adds the scores of matching rules into a threat score and acts only when that total reaches the threshold.

open as a page

A Cloudflare Turnstile-protected sign-up endpoint rejects some genuine users because siteverify returns timeout-or-duplicate; what causes it, and how do you fix it?

level: seniorimportance: should knowfreq 28%

basics

~20 s

timeout-or-duplicate means the token was already validated or outlived its 300 seconds: a second verifier, a retried request, a resubmitted form or a stale copy. Validate each token once, retry siteverify with an idempotency_key, and reset the widget before resubmitting.

open as a page

After a marketplace's Cloudflare custom rule blocked bot scores below 30, its search crawlers and in-house uptime checker were blocked too; why, and what fixes each?

level: seniorimportance: should knowfreq 34%

basics

~10 s

Crawlers and checkers are automated, so they score below 30. Adding not cf.bot_management.verified_bot lets Cloudflare's verified crawlers pass; the in-house checker is not verified, so it needs a narrowly scoped Skip rule placed first.

open as a page

During a real layer-7 flood, Cloudflare's HTTP DDoS Attack Protection is mitigating yet the origin still falls over; how do you tighten the response?

level: seniorimportance: should knowfreq 26%

basics

~20 s

Find the rule and the softer action it applied, override that rule to Block, undo any earlier override that lowered sensitivity, and if the flood stays under the rules' thresholds add Under Attack mode, rate limits and custom rules.

open as a page

With Cloudflare's HTTP DDoS Attack Protection, a ticketing site's legitimate on-sale rush was mitigated as a flood; how do you confirm it and fix it without weakening the whole zone?

level: seniorimportance: should knowfreq 34%

basics

~20 s

Filter security events by Service equals HTTP DDoS to find the rule that fired and confirm the traffic was real buyers, then lower only that rule's sensitivity one step at a time, path-scoped only with Advanced DDoS Protection.

open as a page

An origin accepts any HTTPS request from Cloudflare's IP ranges that presents Cloudflare's global Authenticated Origin Pulls certificate; why does that not prove the request passed your zone, and what closes the gap?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Cloudflare's IP ranges and global AOP certificate are shared by all customers, so they prove only that a request crossed Cloudflare's network, not your zone's rules. Use zone-level or per-hostname AOP with your own certificate, or a Tunnel.

open as a page

After a Cloudflare rate limiting rule keyed on IP went live on a mobile app's login API, thousands of users on one carrier got blocked; why, and how do you fix it?

level: seniorimportance: should knowfreq 48%

basics

~20 s

Carrier-grade NAT puts thousands of phones behind one public IP, so an IP-keyed counter adds all their logins together and can block them all. Count only failed logins, key on IP with NAT support or an identifier, and block with a JSON 429.

open as a page

A Cloudflare WAF custom rule meant to block two scraper ASNs on /search and /api/search blocked every visitor to /api/search; why, and how do you fix it?

level: seniorimportance: should knowfreq 42%

basics

~10 s

In Cloudflare's Rules language and binds tighter than or, so ASN and path1 or path2 meant (ASN and path1) or path2, matching everyone on /api/search. Group the paths in parentheses or an inline set.

open as a page

After a Cloudflare zone turned on the managed WAF rulesets, admins saving rich-text product descriptions through the API are blocked; how do you find which rules fired and fix it narrowly?

level: seniorimportance: should knowfreq 38%

basics

~20 s

Filter Security Events to the save endpoint and read the rule. Rule 949110 means the OWASP threat score crossed its threshold, so open Additional logs for the contributing rules. Then add an exception skipping only those rules for that host, path and method.

open as a page

As the lead for a public API on Cloudflare whose clients send an API key header, some from shared egress IPs, how do you decide what its rate limits are keyed on?

level: principalimportance: should knowfreq 36%

basics

~20 s

Layer the limits: a high per-IP ceiling that shared egress addresses can live with, a per-customer limit keyed on a validated key or claim, and a failed-authentication limit. Plan, precision and who owns the thresholds decide which layer holds which key.

open as a page

showing 1–30 of 33