User Agent Blocking
Last updated Aug 14, 2026
User Agent Blocking allows you to block specific browser or web application User-Agent request headers ↗︎. User agent rules apply to the entire domain instead of individual subdomains.
User agent rules are applied after zone lockdown rules. If you allow an IP address via Zone Lockdown, it will skip any user agent rules.
Note
Cloudflare recommends that you use custom rules instead of user agent rules to block specific user agents.
For example, a custom rule equivalent to the user agent example rule provided in this page could have the following configuration:
- Expression:
http.user_agent eq "BadBot/1.0.2 (+http://bad.bot)" - Action: (a block or challenge action)
Availability
Cloudflare User Agent Blocking is available on all plans. The User agent rules option appears only if you have configured at least one user agent rule.
The number of available user agent rules depends on your Cloudflare plan.
| Free | Pro | Business | Enterprise | |
|---|---|---|---|---|
| Availability | Yes | Yes | Yes | Yes |
| Number of rules | 10 | 50 | 250 | 1,000 |
Create a User Agent Blocking rule
Note
The User agent rules option appears only if you have configured at least one user agent rule. Cloudflare recommends that you use custom rules instead of user agent rules.
- In the Cloudflare dashboard, go to the Security rules page. Go to Security rules ↗
- Select Create rule > User agent rules.
- Enter a descriptive name for the rule in Name/Description.
- In Action, select the action to perform: Block, Non-Interactive Challenge, Managed Challenge, or Interactive Challenge.
- Enter a user agent value in User Agent (wildcards such as
*are not supported). For example, to block the Bad Bot web spider, enterBadBot/1.0.2 (+http://bad.bot). - Select Save and Deploy blocking rule.
Issue a POST request for the Create a User Agent Blocking rule operation similar to the following:
<details>
<summary>
Required API token permissions
</summary>
At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:
- <code>Firewall Services Write</code>
</details>
Create a User Agent Blocking rulebash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/firewall/ua_rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"description": "Block Bad Bot web spider",
"mode": "block",
"configuration": {
"target": "ua",
"value": "BadBot/1.0.2 (+http://bad.bot)"
}
}'
Challenge actions
When a User Agent Blocking rule uses a challenge action such as Managed Challenge, the visitor must pass a challenge page. After passing the challenge, a cf_clearance cookie is set. The duration of this cookie is controlled by the Challenge Passage setting.
Related resources
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/waf/tools/user-agent-blocking/#page","headline":"User Agent Blocking","description":"Block or challenge requests based on User-Agent header values.","url":"https://developers.cloudflare.com/waf/tools/user-agent-blocking/","inLanguage":"en","image":"https://developers.cloudflare.com/waf/tools/user-agent-blocking/og.png?v=470df95b9dc64385","dateModified":"2026-08-14","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Automatic request validation for malformed packets and attack vectors. title: Validation checks image: https://developers.cloudflare.com/waf/tools/validation-checks/og.png?v=c9b5b43477a7110f
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/waf/llms.txt
Use this file to discover all available pages before exploring further.
Docs