Skip to content

HTTP policies

Last updated View as MarkdownAgent setup

HTTP policies allow you to filter all HTTP and HTTPS requests based on URLs, hostnames, HTTP methods, file types, and other request attributes. Unlike network policies which operate at Layer 4 (TCP/UDP), HTTP policies operate at Layer 7 and can inspect the full content of web traffic.

By default, Gateway inspects HTTP traffic on port 80 and, with TLS decryption turned on, HTTPS traffic on port 443. You can also configure Gateway to inspect HTTP/HTTPS traffic on all ports. Gateway supports HTTP/3 inspection with the UDP proxy turned on.

An HTTP policy consists of an Action and a logical expression that determines the scope of the policy. To build an expression, choose a Selector and an Operator, then enter a value or range of values in the Value field. You can use And and Or logical operators to evaluate multiple conditions.

If a condition in an expression joins a query attribute (such as Source IP) and a response attribute (such as Resolved IP), then the condition will be evaluated when the response is received.

Actions

Actions in HTTP policies allow you to choose what to do with a given set of elements (domains, IP addresses, file types, and so on). You can assign one action per policy.

Allow

API value: allow

Available selectors

Traffic

Identity

Device Posture

The Allow action allows outbound traffic to reach destinations you specify within the Selectors and Value fields. For example, the following configuration allows traffic to reach all websites we categorize as belonging to the Education content category:

Selector Operator Value Action
Content Categories in Education Allow

Untrusted certificates

The Untrusted certificate action determines how to handle insecure requests.

Option Action
Error Display Gateway error page. Matches the default behavior when no action is configured.
Block Display block page as set in the Cloudflare dashboard.
Pass through Bypass insecure connection warnings and seamlessly connect to the upstream. For more information on what statuses are bypassed, refer to Troubleshooting Gateway.

Custom headers

Allow policies can modify HTTP request headers before forwarding traffic to the destination. You can add, overwrite, or delete headers, and use dynamic variables to inject identity, device, and network context into header values.

For more information, refer to Custom headers.

Block

API value: block

Available selectors

Traffic

Identity

Device Posture

The Block action blocks outbound traffic from reaching destinations you specify within the Selectors and Value fields. For example, the following configuration blocks users from being able to upload any file type to Google Drive:

Selector Operator Value Logic Action
Application in Google Drive And Block
Upload Mime Type matches regex .*

Cloudflare One Client block notifications

Feature availability

Client modes Zero Trust plans
  • Traffic and DNS mode
  • Traffic only mode
Enterprise
System Availability Minimum client version
Windows 2024.1.159.0
macOS 2024.1.160.0
Linux
iOS 1.7
Android 1.4
ChromeOS 1.4

Turn on Display block notification for Cloudflare One Client to display notifications for Gateway block events. Blocked users will receive an operating system notification from the Cloudflare One Client with a custom message you set. If you do not set a custom message, the Cloudflare One Client will display a default message. Custom messages must be 100 characters or less. The Cloudflare One Client will only display one notification per minute.

Upon selecting the notification, the Cloudflare One Client will direct your users to the Gateway block page you have configured. Optionally, you can direct users to a custom URL, such as an internal support form.

When you turn on Send policy context, Gateway will append details of the matching request to the redirected URL as a query string. Not every context field will be included. Potential policy context fields include:

Policy context fields

Field Definition Example
User email Email of the user that made the query. &cf_user_email=user@example.com
Site URL Full URL of the original HTTP request or domain name in DNS query. &cf_site_uri=https%3A%2F%2Fmalware.testcategory.com%2F
URL category Domain categories of the URL to be redirected. &cf_request_categories=New%20Domains,Newly%20Seen%20Domains
Original HTTP referer For HTTP traffic, the original HTTP referer header of the HTTP request. &cf_referer=https%3A%2F%2Fexample.com%2F
Rule ID ID of the Gateway policy that matched the request. &cf_rule_id=6d48997c-a1ec-4b16-b42e-d43ab4d071d1
Source IP Source IP address of the device that matched the policy. &cf_source_ip=203.0.113.5
Device ID UUID of the device that matched the policy. &cf_device_id=6d48997c-a1ec-4b16-b42e-d43ab4d071d1
Application names Name of the application the redirected domain corresponds to, if any. &cf_application_name=Salesforce
Filter The traffic type filter that triggered the block. &cf_filter=http, &cf_filter=dns, &cf_filter=av, or &cf_filter=l4
Account ID Cloudflare account ID of the associated Zero Trust account. &cf_account_id=d57c3de47a013c03ca7e237dd3e61d7d
Query ID ID of the DNS query for which the redirect took effect. &cf_query_id=f8dc6fd3-a7a5-44dd-8b77-08430bb4fac3
Connection ID ID of the proxy connection for which the redirect took effect. &cf_connection_id=f8dc6fd3-a7a5-44dd-8b77-08430bb4fac3
Request ID ID of the HTTP request for which the redirect took effect. &cf_request_id=f8dc6fd3-a7a5-44dd-8b77-08430bb4fac3

Ensure that your operating system allows notifications for the Cloudflare One Client. Your device may not display notifications if focus, do not disturb, or screen sharing settings are turned on. To turn on client notifications on macOS devices running DisplayLink software, you may have to allow system notifications when mirroring your display. For more information, refer to the macOS documentation.

Redirect

API value: redirect

Available selectors

Traffic

Identity

Device Posture

The Redirect action allows you to redirect matched HTTP requests to a different URL you specify. For example, if your users browse to the public web page of a SaaS app, you can redirect them to your own self-hosted instance, a single sign-on page, or an internal policy page.

To redirect URLs with a Block action and the block page, refer to Redirect to a block page.

Policy settings

In Policy URL redirect, you can define what URL to redirect matched requests to. The redirect URL can contain paths and queries. For example, you can redirect example.com to cloudflare.com/path/to/page?querystring=x.

When you turn on Send policy context, Gateway will append details of the matching request to the redirected URL as a query string. Not every context field will be included. Potential policy context fields include:

Policy context fields

Field Definition Example
User email Email of the user that made the query. &cf_user_email=user@example.com
Site URL Full URL of the original HTTP request or domain name in DNS query. &cf_site_uri=https%3A%2F%2Fmalware.testcategory.com%2F
URL category Domain categories of the URL to be redirected. &cf_request_categories=New%20Domains,Newly%20Seen%20Domains
Original HTTP referer For HTTP traffic, the original HTTP referer header of the HTTP request. &cf_referer=https%3A%2F%2Fexample.com%2F
Rule ID ID of the Gateway policy that matched the request. &cf_rule_id=6d48997c-a1ec-4b16-b42e-d43ab4d071d1
Source IP Source IP address of the device that matched the policy. &cf_source_ip=203.0.113.5
Device ID UUID of the device that matched the policy. &cf_device_id=6d48997c-a1ec-4b16-b42e-d43ab4d071d1
Application names Name of the application the redirected domain corresponds to, if any. &cf_application_name=Salesforce
Filter The traffic type filter that triggered the block. &cf_filter=http, &cf_filter=dns, &cf_filter=av, or &cf_filter=l4
Account ID Cloudflare account ID of the associated Zero Trust account. &cf_account_id=d57c3de47a013c03ca7e237dd3e61d7d
Query ID ID of the DNS query for which the redirect took effect. &cf_query_id=f8dc6fd3-a7a5-44dd-8b77-08430bb4fac3
Connection ID ID of the proxy connection for which the redirect took effect. &cf_connection_id=f8dc6fd3-a7a5-44dd-8b77-08430bb4fac3
Request ID ID of the HTTP request for which the redirect took effect. &cf_request_id=f8dc6fd3-a7a5-44dd-8b77-08430bb4fac3

When you turn on Preserve original path and query string, Gateway will append the original path and query string to the redirected URL. Paths and queries in the redirect URL take precedence over the original URL. For example, if the original URL is example.com/path/to/page?querystring=X and the redirect URL is cloudflare.com/redirect-path?querystring=Y, Gateway will redirect requests to:

cloudflare.com/redirect-path/path/to/page?querystring=Y

When you turn on both options, Gateway will preserve the original path and query string, then append policy context to the end of the redirect URL. For example, if the original URL is example.com/path/to/page?querystring=X&k=1 and the redirect URL is cloudflare.com/redirect-path?querystring=Y, Gateway will redirect requests to:

cloudflare.com/redirect-path/path/to/page?querystring=Y&k=1&cf_user_email=user@example.com

Isolate

API value: isolate

Available selectors

Traffic

Identity

Device Posture

The Isolate action serves matched traffic to users via Cloudflare Browser Isolation. For more information on this action, refer to Isolation policies.

Do Not Inspect

API value: off

Available selectors

Traffic

Identity

Device Posture

Do Not Inspect lets you bypass certain elements from inspection. To prevent Gateway from decrypting and inspecting HTTPS traffic, your policy must match against the Server Name Indication (SNI) in the TLS header. When accessing a Do Not Inspect site in the browser, your browser may display a Your connection is not private warning, which you can proceed through to connect. For more information about applications which may require a Do Not Inspect policy, refer to TLS decryption limitations.

Do Not Isolate

API value: noisolate

Available selectors

Traffic

Identity

Device Posture

The Do Not Isolate action turns off browser isolation for matched traffic. For more information on this action, refer to Isolation policies.

Do Not Scan

API value: noscan

Available selectors

Traffic

Identity

Device Posture

When an admin enables AV scanning for uploads and/or downloads, Gateway will scan every supported file. Admins can selectively choose to disable scanning by leveraging the HTTP rules. For example, to prevent AV scanning of files uploaded to or downloaded from example.com, an admin would configure the following rule:

Selector Operator Value Action
Hostname matches regex .*example.com Do Not Scan

When a Do Not Scan rule matches, nothing is scanned, regardless of file size or whether the file type is supported or not.

Quarantine

API value: quarantine

Available selectors

Traffic

Identity

Device Posture

The Quarantine action sends files in matching requests to a file sandbox to scan for malware. Gateway will only quarantine files not previously seen in the file sandbox. For more information on this action, refer to File sandboxing.

Sandbox file types

In Sandbox file types, you can select which file types to quarantine with your policy. You must select at least one file type.

File sandboxing supports scanning the following file types:

Supported sandboxing file types

  • .exe
  • .pdf
  • .doc
  • .docm
  • .docx
  • .rtf
  • .ppt
  • .pptx
  • .xls
  • .xlsm
  • .xlsx
  • .zip
  • .rar

Selectors

Gateway matches HTTP traffic against the following selectors, or criteria:

Access Infrastructure Target

All targets secured by an Access infrastructure application.

UI name API example
Access Infrastructure Target access.target

Access Private App

All destination IPs and hostnames secured by an Access self-hosted private application.

UI name API example
Self-hosted Access App with Private Address access.private_app

Application Approval Status

The review approval status of an application from Shadow IT Discovery or the Application Library. For more information, refer to Review applications.

UI name API example
Application Status any(app.statuses[*] == "approved")

Application

You can apply HTTP policies to a growing list of popular web applications. Refer to Application and app types for more information.

UI name API example
Application any(app.ids[*] in {505})

Granular controls

When using the is operator with the Application selector, you can use Application Granular Controls to choose specific actions and operations to match application traffic. For example, you can block file uploads to ChatGPT without blocking all ChatGPT traffic:

Selector Operator Value Controls Action
Application is ChatGPT Upload Block

You can match traffic based on Application Controls, which group multiple user actions together, or Operations, which allow for granular control of supported API-level actions for an application.

For more information, refer to Application Granular Controls.

Body Phase

The phase of an HTTP request. You can use this selector to specify whether to scan either the data sent in an HTTP request to your user's device or from your user's device to a destination. Policies without this selector will scan both the HTTP request and response bodies.

UI name API example
Body Phase http.body_phase == \"download\"

Content Categories

Applications within a specific security category as categorized by Cloudflare Radar.

UI name API example
Content Categories any(http.request.uri.content_category[*] in {1})

Destination Continent

The continent where the request is destined. Geolocation is determined from the target IP address. To specify a continent, enter its two-letter code into the Value field:

Continent Code
Africa AF
Antarctica AN
Asia AS
Europe EU
North America NA
Oceania OC
South America SA
UI name API example
Destination Continent IP Geolocation http.dst_ip.geo.continent == "EU"

Destination Country

The country that the request is destined for. Geolocation is determined from the target IP address. To specify a country, enter its ISO 3166-1 Alpha 2 code in the Value field.

UI name API example
Destination Country IP Geolocation http.dst_ip.geo.country == "RU"

Destination IP

The IP address of the request's target.

UI name API example
Destination IP any(http.conn.dst_ip[*] in {10.0.0.0/8})

Device Posture

With the Device Posture selector, admins can use signals from end-user devices to secure access to their internal and external resources. For example, a security admin can choose to limit all access to internal applications based on whether specific software is installed on a device and/or if the device or software are configured in a particular way.

For more information on device posture checks, refer to Device posture.

UI name API example
Passed Device Posture Checks any(device_posture.checks.failed[*] in {"1308749e-fcfb-4ebc-b051-fe022b632644"}), any(device_posture.checks.passed[*] in {"1308749e-fcfb-4ebc-b051-fe022b632644"})"

Domain

Use this selector to match against a domain and all subdomains. For example, you can match example.com and its subdomains, such as www.example.com.

UI name API example
Domain any(http.request.domains[*] == "example.com")

Gateway policies do not support domains with non-Latin characters directly. To use a domain with non-Latin characters, add it to a list.

Download and Upload File Size

Use these selectors to limit the file size of upload or download transactions. File sizes are measured in mebibytes (MiB).

UI name API example
Download File Size (MiB) http.download.file.size >= 10
UI name API example
Upload File Size (MiB) http.upload.file.size < 10

Download and Upload File Types

These selectors will scan file signatures in the HTTP body. You can select from file categories or specific file types, such as executables, archives and compressed files, unscannable files, Microsoft 365/Office documents, and Adobe files.

UI name API example
Download File Types any(http.download.file.types[*] in {"docx" "7z"})
UI name API example
Upload File Types any(http.upload.file.types[*] in {"compressed"})

Supported file types

Gateway supports the following file types for use with the Download File Types and Upload File Types selectors:

Compressed

  • 7-Zip archive (.7z)
  • bzip2 archive (.bz2)
  • GNU Gzip archive (.gz)
  • Microsoft Cabinet file (.cab)
  • Microsoft Compiled HTML Help file (.chm)
  • RAR archive (.rar)
  • xz archive (.xz)
  • ZIP archive (.zip)

Documents

  • Microsoft Office/365 files
    • Word document (.doc, .docx, .docm)
    • Excel spreadsheet (.xls, .xlsx, .xlsm)
    • PowerPoint presentation (.ppt, .pptx, .pptm)
  • PDF document (.pdf)

Executable

  • Apple Software Package (.pkg)
  • Dynamic-link library (DLL) file (.dll)
  • Executable and Linkable Format (ELF) file (.elf)
  • Java archive (JAR) package (.jar)
  • Java class file (.class)
  • Mach object (Mach-O) file (.macho)
  • Microsoft Windows installer (.msi)
  • Microsoft Software Installer (.msix, .appx)
  • Microsoft Windows executable (.exe)

Image

  • Adobe Photoshop document (.psd)
  • Bitmap image (.bmp)
  • GIF image (.gif)
  • Icon file (.ico)
  • JPEG image (.jpg, .jpeg)
  • PNG image (.png)
  • WebP image (.webp)

Other

  • BitTorrent file (.torrent)

System

  • Apple Disk Image (.dmg)

Unscannable

  • Password-protected Microsoft Office document
  • Password-protected PDF
  • Password-protected ZIP archive
  • Unscannable ZIP archive

Download and Upload Mime Type

These selectors depend on the Content-Type header being present in the request (for uploads) or response (for downloads). The MIME type value must match the format used in the Content-Type header (for example, image/png, application/pdf).

UI name API example
Download Mime Type http.download.mime == "image/png"
UI name API example
Upload Mime Type http.upload.mime == "image/png"

DLP Profile

Use Cloudflare Data Loss Prevention (DLP) to scan HTTP traffic for the presence of sensitive data such as personally identifiable information (PII) or source code. You must configure a DLP profile before you can use this selector in a policy.

UI name API example
DLP Profile any(dlp.profiles[*] in {\"a0cabf16-7491-4c9a-ac02-f64cabc66394\"})

Host

Use this selector to match against only the hostname specified. For example, you can match test.example.com but not example.com or www.test.example.com.

UI name API example
Host http.request.host == "example.com"

Gateway policies do not support hostnames with non-Latin characters directly. To use a hostname with non-Latin characters, add it to a list.

HTTP Method

The HTTP request method used in the traffic.

UI name API example
HTTP Method http.request.method == "GET"

HTTP Response

The HTTP response status code received by the traffic.

UI name API example
URL http.response.status_code == "200"

Proxy Endpoint

The proxy server where your browser forwards HTTP traffic.

UI name API example
Proxy Endpoint proxy.endpoint == "3ele0ss56t.proxy.cloudflare-gateway.com"

Security Risks

Applications within a specific security category as categorized by Cloudflare Radar.

UI name API example
Security Categories any(http.request.uri.security_category[*] in {1})

Source Continent

The continent of the user making the request.

Geolocation is determined from the device's public IP address (typically assigned by the user's ISP). To specify a continent, enter its two-letter code into the Value field:

Continent Code
Africa AF
Antarctica AN
Asia AS
Europe EU
North America NA
Oceania OC
South America SA
UI name API example
Source Continent IP Geolocation http.src_ip.geo.continent == "North America"

Source Country

The country of the user making the request.

Geolocation is determined from the device's public IP address (typically assigned by the user's ISP). To specify a country, enter its ISO 3166-1 Alpha-2 code in the Value field.

UI name API example
Source Country IP Geolocation http.src_ip.geo.country == "RU"

Source Internal IP

Use this selector to apply HTTP policies to a private IP address, assigned by a user's local network, that requests arrive to Gateway from.

UI name API example
Source Internal IP http.conn.internal_src_ip == "192.168.86.0/27"

Source IP

The originating IP address or addresses of a device proxied by Gateway.

UI name API example
Source IP http.conn.src_ip[*] in {10.0.0.0/8}

URL

Gateway ignores trailing forward slashes (/) in URLs. For example, https://example.com and https://example.com/ will count as the same URL and may return a duplicate error.

UI name API example
URL http.request.uri matches "/r/gaming"

URL Path

The pathname of a webpage's URL.

UI name API example
URL Path http.request.uri.path == \"/foo/bar\"

URL Path and Query

The pathname and query of a webpage's URL.

UI name API example
URL Path and Query http.request.uri.path_and_query == \"/foo/bar?ab%242=%2A342\"

URL Query

The query of a webpage's URL.

UI name API example
URL Query http.request.uri.query == "ab%242=%2A342"

Users

Use these selectors to match against identity attributes.

UI name API example
User Email identity.email == "user@example.com"
User Name identity.name == "Test User"
User Group IDs any(identity.groups[*].id in {"group_id"})
User Group Names any(identity.groups[*].name in {"group_name"})
User Group Emails any(identity.groups[*].email in {"group@example.com"})
SAML Attributes any(identity.saml_attributes["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"] in {"Test User"})

Virtual Network

Use this selector to match all traffic routed through a specific Virtual Network via the Cloudflare One Client.

UI name API example
Virtual Network http.conn.vnet_id == "957fc748-591a-e96s-a15d-1j90204a7923"

Comparison operators

Comparison operators are the way Gateway matches traffic to a selector. When you choose a Selector in the dashboard policy builder, the Operator dropdown menu will display the available options for that selector.

Operator Meaning
is equals the defined value
is not does not equal the defined value
in matches at least one of the defined values
not in does not match any of the defined values
in list in a pre-defined list of values
not in list not in a pre-defined list of values
matches regex regex evaluates to true
does not match regex regex evaluates to false
greater than exceeds the defined number
greater than or equal to exceeds or equals the defined number
less than below the defined number
less than or equal to below or equals the defined number

Value

In the Value field, you can input a single value when using an equality comparison operator (such as is) or multiple values when using a containment comparison operator (such as in). Additionally, you can use regular expressions (or regex) to specify a range of values for supported selectors.

Regular expressions

Regular expressions are evaluated using Rust. The Rust implementation is slightly different than regex libraries used elsewhere. For more information, refer to our guide for Wildcards. To evaluate if your regex matches, you can use Rustexp.

If you want to match multiple values, you can use the pipe symbol (|) as an OR operator. You do not need to use an escape character (\) before the pipe symbol. For example, the following expression evaluates to true when the hostname matches either .*whispersystems.org or .*signal.org:

Selector Operator Value
Hostmatches regex.*whispersystems.org|.*signal.org

In addition to regular expressions, you can use logical operators to match multiple values.

Logical operators

To evaluate multiple conditions in an expression, select the And logical operator. These expressions can be compared further with the Or logical operator.

Operator Meaning
And match all of the conditions in the expression
Or match any of the conditions in the expression

The Or operator will only work with conditions in the same expression group. For example, you cannot compare conditions in Traffic with conditions in Identity or Device Posture.

If a condition in an expression joins a request attribute (such as Source IP) and a response attribute (such as a DLP Profile), then the condition will be evaluated when the response is received.

Was this helpful?