The following policies are commonly used to secure HTTP traffic.
Refer to the HTTP policies page for a comprehensive list of other selectors, operators, and actions.
Block attempts to reach sites by hostname or URL paths. Different approaches may be required based on how a site is organized.
Block all subdomains that use a host.
Selector Operator Value Action Host matches regex .*example\.com
Block
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Block sites by hostname",
"description": "Block all subdomains that use a specific hostname",
"traffic": "http.request.host matches \".*example\\.com\"",
Block a section of a site without blocking the entire site. For example, you can block a specific subreddit, such as reddit.com/r/gaming
, without blocking reddit.com
.
Selector Operator Value Action URL matches regex /r/gaming
Block
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Block sites by URL",
"description": "Block specific parts of a site without blocking the hostname",
"traffic": "http.request.uri matches \"/r/gaming\"",
Block content categories which go against your organization's acceptable use policy.
Selector Operator Value Action Content Categories in Adult Themes , Gambling Block
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Block content categories",
"description": "Block access to unauthorized adult and gambling applications",
"traffic": "any(http.request.uri.content_category[*] in {2 67 125 133 99})",
Block unauthorized applications
To minimize the risk of shadow IT , some organizations choose to limit their users' access to certain web-based tools and applications. For example, the following policy blocks known AI tools:
Selector Operator Value Action Application in Artificial Intelligence Block
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Block unauthorized applications",
"description": "Block access to unauthorized AI applications",
"traffic": "any(app.type.ids[*] in {25})",
Configure access on a per user or group basis by adding identity-based conditions to your policies.
Selector Operator Value Logic Action Application in Salesforce And Block User Group Names in Contractors
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Check user identity",
"description": "Block access to Salesforce by temporary employees and contractors",
"traffic": "any(app.ids[*] in {606})",
"identity": "any(identity.groups.name[*] in {\"Contractors\"})",
Skip inspection for groups of applications
Certain client applications, such as Zoom or Apple services, rely on certificate pinning. The TLS decryption performed by Cloudflare Gateway will cause errors when users visit those applications. To avoid this behavior, you must add a Do Not Inspect HTTP policy.
Gateway evaluates Do Not Inspect policies first . We recommend moving your Do Not Inspect policies to the top of the list to reduce confusion.
Selector Operator Value Action Application in Do Not Inspect Do Not Inspect
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Bypass incompatible applications",
"description": "Skip TLS decryption for applications that are incompatible with Gateway",
"traffic": "any(app.type.ids[*] in {16})",
Require devices to have certain software installed or other configuration attributes. For instructions on setting up a device posture check, refer to Enforce device posture .
Enforce a minimum OS version
Perform an OS version check to ensure users are running at least a minimum version.
Selector Operator Value Action Passed Device Posture Checks in Minimum OS version Allow
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Require OS version",
"description": "Perform an OS version check for minimum version",
"device_posture": "any(device_posture.checks.passed[*] in {\"<POSTURE_CHECK_UUID>\"})"
To get the UUIDs of your device posture checks, use the List device posture rules endpoint.
Check for a specific file
Perform a file check to ensure users have a certain file on their device.
Since the file path will be different for each operating system, you can configure a file check for each system and use the Or logical operator to only require one of the checks to pass.
Selector Operator Value Logic Action Passed Device Posture Checks in macOS File Check Or Allow Passed Device Posture Checks in Linux File Check
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Check for specific file",
"description": "Ensure users have a specific file on their device regardless of operating system",
"device_posture": "any(device_posture.checks.passed[*] in {\"<POSTURE_CHECK_1_UUID>\"}) or any(device_posture.checks.passed[*] in {\"<POSTURE_CHECK_2_UUID>\"})"
To get the UUIDs of your device posture checks, use the List device posture rules endpoint.
Require users to re-authenticate after a certain amount of time has elapsed.
Isolate high risk sites in remote browser
If you are using the Browser Isolation add-on , refer to our list of common Isolate policies .
Bypass inspection for self-signed certificates
When accessing origin servers with certificates not signed by a public certificate authority, you must bypass TLS decryption.
Selector Operator Value Action Domain in internal.example.com
Do Not Inspect
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Bypass internal site inspection",
"description": "Bypass TLS decryption for internal sites with self-signed certificates",
"traffic": "any(http.conn.domains[*] in {\"internal.example.com\"})",
Block the upload or download of files based on their type.
Selector Operator Value Logic Action Upload File Types in Microsoft Office Word Document (docx) And Block Download File Types in PDF (pdf)
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Block file types",
"description": "Block the upload or download of files based on their type",
"traffic": "any(http.upload.file.types[*] in {\"docx\"}) and any(http.download.file.types[*] in {\"pdf\"})",
For more information on supported file types, refer to Download and Upload File Types .
To enable Gateway inspection for Google Drive traffic, you must add a Cloudflare certificate to Google Drive .
Block Google Drive downloads
Block file downloads from Google Drive.
Selector Operator Value Logic Action Application in Google Drive And Block URL Path & Query matches regex .*(e=download|export).*
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Block Google Drive downloads",
"description": "Block file downloads from Google Drive",
"traffic": "any(app.ids[*] in {554}) and http.request.uri.path_and_query matches \".*(e=download\\|export).*\"",
Block file downloads from Gmail.
Selector Operator Value Logic Action Host is mail-attachment.googleusercontent.com
And Block URL Path & Query is /attachment/u/0
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rule \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <API_TOKEN>" \
"name": "Block Gmail downloads",
"description": "Block file downloads from Gmail",
"traffic": "http.request.host == \"mail-attachment.googleusercontent.com\" and http.request.uri.path_and_query matches \"/attachment/u/0\"",
Thank you for helping improve Cloudflare's documentation!