Order of enforcement·续
Gateway then evaluates Forward policies before body policies and inspection, including DLP policies, anti-virus scanning, and file sandboxing. If DLP Block policies are present, the action Gateway ultimately takes may not match the action it initially logs.
For more information, refer to DLP policy precedence.
A matching Allow policy does not skip the Forward phase. An HTTP request policy with a Block action prevents Worker invocation, while a Block decision from body policies or inspection can interrupt the Worker.
Gateway inspects the original request body before delivering it to the Worker and the final response returned by the Worker. Modified request bytes do not receive another request-side inspection.
Refer to Forward traffic.
Resolver policies
When resolver policies are present, Gateway first evaluates any DNS policies with pre-resolution selectors, then routes any DNS queries according to the order of precedence of your resolver policies, and lastly evaluates any DNS policies with post-resolution selectors.
Default behavior when no policy matches
If traffic does not match any explicit Allow or Block policy, Gateway applies the following defaults:
| Policy type | Default action | Description |
|---|---|---|
| DNS | Allow | DNS queries resolve normally through the configured resolver. |
| Network | Allow | TCP and UDP connections are allowed through the Gateway proxy. |
| HTTP | Allow | HTTP and HTTPS requests are allowed. However, if you have configured a default Block action in your HTTP policy settings, unmatched traffic is blocked instead. |
Because the default is to allow unmatched traffic, Gateway follows a permissive model. To switch to a restrictive model (block by default, allow by exception), create a catch-all Block policy at the lowest precedence in the relevant policy builder and add specific Allow policies above it.
Note
Do Not Inspect policies are evaluated before all other HTTP policies. If traffic matches a Do Not Inspect policy, it bypasses all remaining HTTP policies and is allowed through Gateway. For details, refer to HTTP policy priority.
Order of precedence
Order of precedence refers to the priority of individual policies within the DNS, network, or HTTP policy builder. Gateway evaluates policies in ascending order beginning with the lowest value.
The order of precedence follows the first match principle. Once traffic matches an Allow or Block policy, evaluation stops in that filtering phase.
Later filtering policies in the same phase cannot override the decision. HTTP traffic permitted by HTTP request policies still undergoes the separate Forward phase, then body policies and inspection.
Therefore, Cloudflare recommends assigning the most specific policies and exceptions with the highest precedence and the most general policies with the lowest precedence.
Cloudflare dashboard
In the Cloudflare dashboard, policies are in order of precedence from top to bottom of the list. Policies begin with precedence 1 and count upward. You can modify the order of precedence by dragging and dropping individual policies in the dashboard.
Cloudflare API
To update the precedence of a policy with the Cloudflare API, use the Update a Zero Trust Gateway rule endpoint to update the precedence field.
DLP policy precedence
For Gateway configurations with DLP policies, Gateway will filter and log traffic based on first match, then scan the body of the HTTP request for matching content. Because of the first match principle, Gateway may perform and log a decision for traffic, then perform a contradicting decision. For example, if traffic is first allowed with an Allow HTTP policy, then blocked with a DLP Block policy, Gateway will log the initial Allow action despite ultimately blocking the request.
Access applications
If Gateway traffic is headed to a private IP address protected as an Access application, that traffic will still be evaluated by the destination application's Access policies, even if a Gateway Allow policy matched first. Gateway Block policies that match traffic will terminate any other policy evaluation. This is expected behavior. A Gateway Allow policy does not override or bypass Access policies.
Terraform provider v4 precedence limitation
To avoid conflicts, version 4 of the Terraform Cloudflare provider applies a hash calculation to policy precedence. For example, a precedence of 1000 may become 1000901. This can cause errors when reordering policies. To avoid this issue, manually set the precedence of policies created with Terraform using the Update a Zero Trust Gateway rule endpoint.
To ensure your precedence is set correctly, Cloudflare recommends upgrading your Terraform provider to version 5 ↗︎.
Example
Suppose you have a list of policies arranged in the following order of precedence:
- DNS policies:
| Precedence | Selector | Operator | Value | Action |
|---|---|---|---|---|
| 1 | Host | is | example.com |
Block |
| 2 | Host | is | test.example.com |
Allow |
| 3 | Domain | matches regex | .\ |
Block |
| - HTTP policies: |
| Precedence | Selector | Operator | Value | Action |
|---|---|---|---|---|
| 1 | Host | is | example.com |
Block |
| 2 | Host | is | test2.example.com |
Do Not Inspect |
| - Network policies: |
| Precedence | Selector | Operator | Value | Action |
|---|---|---|---|---|
| 1 | Destination Port | is | 80 |
Block |
| 2 | Destination port | is | 443 |
Allow |
| 3 | SNI Domain | is | test.example.com |
Block |
When a user goes to https://test.example.com, Gateway performs the following operations:
- Evaluate DNS request against DNS policies:
- Policy #1 does not match
test.example.com— move on to check Policy #2. - Policy #2 matches, so DNS resolution is allowed.
- Policy #3 is not evaluated because there has already been an explicit match.
- Evaluate HTTPS request against network policies:
- Policy #1 does not match because port 80 is used for standard HTTP, not HTTPS.
- Policy #2 matches, so the request is allowed and proxied to the upstream server.
- Policy #3 is not evaluated because there has already been an explicit match.
- Evaluate HTTPS request against HTTP policies:
- Policy #2 is evaluated first because Do Not Inspect always takes precedence over Allow and Block. Since there is no match, move on to check Policy #1.
- Policy #1 does not match
test.example.com. Since there are no matching Block policies, the request passes the HTTP filter.
Therefore, the user is able to connect to https://test.example.com.
Precedence calculations
When arranging policies in the Cloudflare dashboard ↗︎, Gateway automatically calculates the precedence for rearranged policies.
When using the API to create a policy, unless the precedence is explicitly defined in the policy, Gateway will assign precedence to policies starting at 1000. Every time a new policy is added to the bottom of the order, Gateway will calculate the current highest precedence in the account and add a random integer between 1 and 100 to 1000 so that it now claims the maximum precedence in the account. To manually update a policy's precedence, use the Update a Zero Trust Gateway rule endpoint. You can set a policy's precedence to any value that is not already in use.
Changing the order within the Cloudflare dashboard or API may result in configuration issues when using Terraform.
Manage precedence with Terraform
You can manage the order of execution of your Gateway policies using Terraform. With version 5 of the Terraform Cloudflare provider, Gateway users can list their policies in a Terraform file with any desired integer precedence value. Cloudflare recommends starting with a precedence of 1000 and adding extra space between each policy's precedence for any future policies. For example:
resource "cloudflare_zero_trust_gateway_policy" "policy_1" {
account_id = var.cloudflare_account_id
# other attributes...
precedence = 1000
}
resource "cloudflare_zero_trust_gateway_policy" "policy_2" {
account_id = var.cloudflare_account_id
# other attributes...
precedence = 2000
}
resource "cloudflare_zero_trust_gateway_policy" "policy_3" {
account_id = var.cloudflare_account_id
# other attributes...
precedence = 3000
}
To avoid precedence calculation errors when reordering policies with Terraform, you should move one policy at a time before running terraform plan and terraform apply. If you use both Terraform and the Cloudflare dashboard or API, sync your polices with terraform refresh before reordering policies in Terraform. Alternatively, you can set your account to read-only in the Cloudflare dashboard, only allowing changes using the API or Terraform.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/learning-paths/secure-internet-traffic/understand-policies/order-of-enforcement/#page","headline":"Order of enforcement","description":"Understand Gateway policy enforcement order.","url":"https://developers.cloudflare.com/learning-paths/secure-internet-traffic/understand-policies/order-of-enforcement/","inLanguage":"en","image":"https://developers.cloudflare.com/learning-paths/secure-internet-traffic/understand-policies/order-of-enforcement/og.png?v=b682d791bf6d5001","dateModified":"2026-04-23","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: Protect your organization from email phishing attacks. title: Concepts image: https://developers.cloudflare.com/learning-paths/secure-your-email/concepts/og.png?v=7bc7bd59b1702974
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/learning-paths/llms.txt
Use this file to discover all available pages before exploring further.
Docs