Order of enforcement

Last updated Apr 23, 2026 Gateway follows a specific order of enforcement as traffic travels through the Cloudflare global network to the Internet:

Enforcement flowchart

flowchart TB
    %% Accessibility
    accTitle: Gateway order of enforcement
    accDescr: Flowchart describing request enforcement for Gateway policies. After HTTP request policies, the first matching Forward policy invokes a Worker before body policies and inspection. Gateway inspects the original body before delivering it to the Worker, and a Block decision from body policies or inspection can interrupt the Worker. Gateway inspects the final response returned by the Worker.

subgraph Resolution["Resolution"]
        dns2["1.1.1.1"]
        dns4["Custom resolver"]
        dns3["Resolver policies <br>(Enterprise users only)"]
        internal["Internal DNS"]
  end
 subgraph DNS["DNS"]
        dns1["DNS policies"]
        Resolution
  end
 subgraph HTTP["HTTP policies"]
        http1{{"Do Not Inspect policies"}}
        http2["Isolate policies  <br>(with Browser Isolation add-on)"]
        http3["HTTP request policies: Allow, Block, Do Not Scan, Quarantine, and Redirect"]
        forward["First matching Forward policy (beta), if any"]
        worker["Worker selected by the policy"]
        body["Body policies and inspection: DLP, anti-virus scanning, and file sandboxing"]
        blocked["Block response"]
        https["HTTP or HTTPS?"]
  end
 subgraph Proxy["Proxy"]
        HTTP
        network1["Network policies"]
        nonhttp["Non-HTTP(S) traffic"]
  end
 subgraph Egress["Egress"]
        egress1["Egress policies <br>(Enterprise users only)"]
  end
    start(["Traffic"]) --> dns0[/"DNS query"/] & http0["Network connections"]
    dns0 ----> dns1
    dns1 -- Resolved by --> dns2
    dns1 --> dns3
    dns3 -- Resolved by --> dns4
    dns2 -----> internet(["Internet"])
    dns4 -----> internet
    dns4 ---> cloudflare["Private network services <br>(Cloudflare Tunnel, Cloudflare WAN, Cloudflare Mesh)"]
    http1 -- Do Not Inspect --> internet
    http1 -- Inspect --> http2
    http2 --> http3
    http0 --> magic["Cloudflare Network Firewall (Enterprise users only)"]
    magic --> egress1
    egress1 --> timing{"Defer upstream connection for a Worker?"}
    timing -- No --> tcp["Check for origin availability (TCP SYN)"]
    timing -- Yes --> network1
    tcp --> network1
    http3 -- Permitted request --> forward
    http3 -- Blocked --> blocked
    forward -- Matches --> worker
    forward -- Original body --> body
    body -- Inspected body stream, Forward matches --> worker
    body -- Blocked --> blocked
    body -. Body Block interrupts Worker .-> worker
    worker -- next, connect upstream if deferred --> internet
    body -- No Forward match, connect upstream if deferred --> internet
    https -- HTTPS --> http1
    https -- HTTP --> http2
    network1 --> https & nonhttp
    dns3 -- Resolved by --> internal & dns2
    nonhttp -----> internet

https@{ shape: hex}
    http0@{ shape: lean-r}

Order of enforcement change on 2025-07-14

On 2025-07-14, Gateway began evaluating network-level policies before application-level policies and verify the network path to an origin server before accepting a connection. This only affects your policies if you are applying HTTP policies in your account. For example:

<details>

<summary>

Comparison of old and new order of enforcement

</summary>

Old order of enforcement New order of enforcement
Network Block policy and HTTP Block policy Gateway blocks traffic and displays the block page and/or follows the client notification settings on the HTTP policy. Gateway blocks traffic. Gateway does not display the block page but will follow the client notification settings on the Network policy.
Network Allow policy and HTTP Block policy Gateway blocks traffic and displays the block page and follows the client notification settings on the HTTP policy. No change.
Network Block policy and HTTP Allow policy Gateway blocks traffic and follows the client notification settings on the Network policy. No change.

</details>

Connection establishment

For traffic that Gateway does not forward to a Worker, Gateway first establishes a TCP connection with the destination server on the port the user requested. Because TCP traffic is proxied by Cloudflare, the connection Gateway establishes with the origin is independent from the connection users establish with Gateway. This means Gateway assigns a new source IP and port to the user's connection and no details from the user's TCP handshake are included in the TCP handshake with the origin server.

If the TCP connection to the destination server is successful, Gateway will apply policies. If Gateway policies allow the connection, Gateway will connect the user to the destination server. If Gateway policies block the connection, Gateway will end the connection and will not send any data between the user and the destination server. If the TCP connection to the destination server is unsuccessful, Gateway will not run any policies and retry TCP connections from the user to the server.

For requests handled by a Worker invoked through the Forward action (beta), Gateway defers the original upstream connection until the Worker calls next(). A Worker that returns a synthetic response without calling next() does not send the request to the origin.

The following flowchart describes connections that Gateway does not forward to a Worker:

flowchart TD
    %% Accessibility
    accTitle: How Gateway proxy works
    accDescr: Flowchart describing how the Gateway proxy uses the Happy Eyeballs algorithm to establish TCP connections and proxy user traffic.

%% Flowchart
    A[User's device sends TCP SYN to Gateway] --> B[Gateway sends TCP SYN to origin server]
    B --> C{{Origin server responds with TCP SYN-ACK?}}
    C -->|Yes| E[TCP handshakes completed]
    C -->|No| D[Connection fails]
    E --> F{{Connection allowed?}}
    F -->|Allow policy| G[Gateway proxies traffic bidirectionally]
    F -->|Block policy| H[Connection blocked by firewall policies]

%% Styling
    style D stroke:#D50000
    style G stroke:#00C853
    style H stroke:#D50000

Connections to Zero Trust will always appear in your Zero Trust network session logs regardless of connection success. Because Gateway does not inspect failed connections, they will not appear in your Gateway activity logs.

Filter TCP SYN packets with Cloudflare Network Firewall

For traffic that Gateway does not forward to a Worker, Gateway sends a TCP SYN to the destination server before evaluating policies. Therefore, Gateway Network or HTTP Block policies do not prevent the initial TCP SYN from reaching the destination server. If you need to prevent TCP SYN packets from being sent to specific destination IP addresses, you can create a Cloudflare Network Firewall rule to block traffic at the packet level. As shown in the enforcement flowchart, Cloudflare Network Firewall evaluates traffic before Gateway checks for origin availability.

Note

Cloudflare Network Firewall is available to Enterprise users only.

To block TCP SYN packets to a specific destination:

  1. In the Cloudflare dashboard ↗︎, go to Zero Trust > Firewall policies > Custom policies.
  2. Select Add a policy.
  3. Create a rule with the destination IP address or CIDR range you want to block. For example, to block all traffic to 10.0.0.0/8, use the expression ip.dst in {10.0.0.0/8} with a Block action.
  4. Select Add new policy.

For more information on creating packet filtering rules, refer to Add policies.

Priority between policy builders

Gateway applies your policies in the following order:

  1. DNS policies with selectors evaluated before resolution
  2. Resolver policies (if applicable)
  3. DNS policies with selectors evaluated after resolution
  4. Egress policies (if applicable)
  5. Network policies
  6. HTTP policies

DNS and resolver policies are standalone. For example, if you block a site with a DNS policy but do not create a corresponding HTTP policy, users can still access the site if they know its IP address.

HTTP/3 traffic

For proxied HTTP/3 traffic, Gateway applies your policies in the following order:

  1. DNS policies
  2. Network policies
  3. HTTP policies

Priority within a policy builder

DNS policies

Gateway evaluates DNS policies first in order of DNS resolution, then in order of precedence.

When DNS queries are received, Gateway evaluates policies with pre-resolution selectors, resolves the DNS query, then evaluates policies with post-resolution selectors. This means policies with selectors evaluated before DNS resolution take precedence. For example, the following set of policies will block example.com:

Precedence Selector Operator Value Action
1 Resolved Country IP Geolocation is United States Allow
2 Domain is example.com Block

Despite an explicit Allow policy ordered first, policy 2 takes precedence because the Domain selector is evaluated before DNS resolution.

If a policy contains both pre-resolution and post-resolution selectors, Gateway will evaluate the entire policy after DNS resolution. For information on when each selector is evaluated, refer to the list of DNS selectors.

Network policies

Gateway evaluates network policies in order of precedence.

HTTP policies

Gateway applies HTTP policies based on a combination of action type and order of precedence:

  1. All Do Not Inspect policies are evaluated first, in order of precedence.
  2. If no policies match, all Isolate policies are evaluated in order of precedence.
  3. All Allow, Block and Do Not Scan policies are evaluated in order of precedence.
  4. For traffic permitted by HTTP request policies, Gateway evaluates Forward policies in order of precedence and invokes the first matching Worker. Traffic that matches no Forward policy continues without a Worker.
  5. Gateway then evaluates body policies and inspects the original request body, including Data Loss Prevention (DLP), AV scanning, and file sandboxing, before delivering it to the Worker or origin. A Block decision from body policies or inspection can interrupt an already-running Worker.
  6. Gateway inspects the final response, including any changes or synthetic response produced by the Worker.

This order of enforcement allows Gateway to first determine whether decryption should occur. If a site matches a Do Not Inspect policy, it is automatically allowed through Gateway and bypasses all other HTTP policies.

Note

The only exception is if you are using Clientless Web Isolation — all sites within the clientless remote browser are implicitly isolated even if they match a Do Not Inspect policy.

Next, Gateway checks decrypted traffic against your Isolate policies. When a user makes a request which triggers an Isolate policy, the request will be rerouted to a remote browser.

Next, Gateway evaluates all Allow, Block, and Do Not Scan policies. These policies apply to both isolated and non-isolated traffic. For example, if example.com is isolated and example.com/subpage is blocked, Gateway will block the subpage (example.com/subpage) inside of the remote browser.