Most secure web gateways decide from a fixed menu: allow, block, isolate, log. When a rule needs something the menu doesn't offer, such as a reason for access, a copy of a downloaded file or an alert in Slack, teams end up running a proxy or a pipeline next to the gateway. Since 15 October 2026, Cloudflare's secure web gateway can hand that traffic to your own code, and that changes the list of secure web gateway use cases you can cover.
Gateway Forward is an action in Cloudflare Gateway HTTP policies that hands traffic Gateway has already allowed to a Cloudflare Worker. The Worker can change the request or the response, answer on its own, or run a background task such as an alert. Forward has been in public beta on all Zero Trust plans since 15 October 2026.
Public beta, all Zero Trust plans, Workers billing. Updated at every status change.
What does Gateway Forward add to a secure web gateway?
A secure web gateway (SWG) filters the web traffic of your users: it evaluates a condition, then applies a terminal action. The model is solid, but the list of actions is closed. As soon as a rule needs business logic, the gateway can only allow or block, and the logic moves elsewhere.
Forward adds one more action. It hands traffic Gateway has already allowed to a Worker in the same Cloudflare account. That Worker can modify the request before it leaves, transform the response, return a response of its own without contacting the destination, or start background work. Cloudflare's documentation states the aim plainly: implement these controls "without operating a separate HTTP proxy".
A Forward rule never loosens a policy: it only acts on traffic Gateway already allows.
Two clarifications avoid common mix-ups. Cloudflare Gateway, the SWG of Cloudflare One (sometimes called Cloudflare SWG), is not AI Gateway, which routes and monitors calls to AI models. And an SWG is not a CASB (cloud access security broker): the SWG controls traffic as it flows, the CASB inspects the configuration and data of your SaaS applications. See the glossary entries for secure web gateway and CASB.
How does a Forward policy handle a request?
The Forward traffic documentation describes five steps:
- HTTP request policies run first. A Block always wins, and the Worker is never called.
- The first matching Forward policy, in order of precedence, selects the Worker. A Forward policy matches on request metadata (host, URL, method), identity and device posture. It never matches on an inspection result or a DLP (data loss prevention) match.
- Gateway inspects the original body before handing it to the Worker. A Block decision from body inspection can interrupt a Worker that is already running.
- The Worker receives the request, a context and
next(). The context includes the source IP, host, normalised URL, domain categories, identity and device posture. The Worker can modify the request and callnext()once, modify the response, or answer without calling the destination. - Gateway inspects the final response, including a response generated by the Worker, before returning it to the user.
In brief. Gateway evaluates Forward policies after HTTP request policies and before body inspection. It inspects the original request body before the Worker receives it, and the final response after the Worker. Data the Worker adds to a request is not scanned again, and a Block policy always takes precedence over Forward.
Here is what the entry point looks like. The Worker exports a class named GatewayMiddleware:
// Illustrative only. See Cloudflare's "Forward traffic" documentation.
import { WorkerEntrypoint } from "cloudflare:workers";
export class GatewayMiddleware extends WorkerEntrypoint {
async handle(request, context, next) {
let identity;
try { identity = await context.identity(); }
catch { return new Response(null, { status: 503 }); }
if (!identity?.email) return new Response(null, { status: 403 });
return next(request); // at most once per invocation
}
}On the policy side, the rule uses "action": "forward" with "rule_settings": { "forward": { "worker_id": "<WORKER_ID>" } }.
Which Cloudflare secure web gateway use cases can you build with Forward today?
Cloudflare publishes Worker templates for most of the use cases below. Where there is no template, we say what has to be built.
| Use case | Trigger (Forward policy) | What the Worker does | Building blocks | Status | Main limit |
|---|---|---|---|---|---|
| Access justification | sensitive host or URL, target groups | interstitial page, record, session | KV, D1 or Hyperdrive | documented template (page); unlocking to build | HTML navigation only |
| SaaS or AI sign-up alert | sign-up endpoint (host, path, POST) | lets the request through, alerts in the background | Slack or on-call webhook, Queues | documented template | detection app by app |
| Computed headers | internal application host | computes a header (role, value from KV or D1) | identity context, KV or D1 | documented capability, no template | native first: Allow policy and dynamic variables |
| File copy | targeted downloads | returns the file, bounded copy | R2 | documented template (R2); sandbox to build | 25 MiB in the template |
| Identity watermark | internal application | visible label on pages | HTMLRewriter | documented template | uncompressed HTML |
| Field redaction | endpoint with a known schema | replaces a JSON field | none | documented template | not a DLP replacement |
| Request archiving | approved test endpoint | copies headers and JSON bodies | R2 | documented template | 256 KiB per body |
| Screenshot | public page you control | capture by an independent browser | Browser Run, R2 | documented template | not what the user saw |
Scope every Forward policy to a method and a path. A single page load sends several requests, so a policy on a whole domain runs your Worker, and bills it, on each one.
Ask for a reason before a sensitive site opens
Trigger: a Forward policy on the host or URL of the sensitive destination, limited to the groups concerned.
What the Worker does: returns an interstitial page without contacting the destination; records the reason and the identity (in D1, or in an internal database through Hyperdrive); keeps a session with an expiry (in KV) so the user isn't asked on every request; once the session is valid, lets the request through with next().
Limit: the documented template shows a page but unlocks nothing; unlocking after justification has to be built. It only covers navigation (GET requests for HTML pages).
Status: "Display a coaching page" template documented; justification and unlocking described by Cloudflare in its launch post.
Alert your team when someone signs up to a new SaaS or AI tool
Trigger: a Forward policy on the sign-up endpoint (host, path, POST method) of the tools you want to watch.
What the Worker does: lets the request through, returns the response, then sends a message to Slack or your on-call tool in the background (user, policy, destination). The alert doesn't slow the traffic down.
Limit: you have to identify the sign-up endpoint application by application; the background task is not a durable queue (use Queues or Workflows if the alert must not be lost).
Status: "Send a Slack notification" template documented.
Related: shadow AI detection.
Compute a header the native policy can't produce
Native first: to pass on the email, groups, a SAML attribute or an OIDC claim as they are, an Allow policy is enough, with no Worker. It adds, overwrites or removes headers with dynamic variables such as @{identity.email}, @{identity.groups} or @{device.posture}.
Trigger: a Forward policy on the host of the internal application, when the value needs logic.
What the Worker does: computes the header before next(): turn groups into an application role, look up KV or D1, combine several claims.
Limit: native variables need an active identity session; without one, Gateway inserts a warning value, such as cf-unresolved, instead of the identity. Never trust an identity header sent by the client, as the documentation stresses; next() keeps the original destination; plan for the case where identity can't be read.
Status: dynamic headers are native and documented; computed headers go through a documented Forward capability, with no template. According to Cloudflare, this use case replaces the pools of NGINX proxies placed in front of internal applications.
Discuss a Programmable Gateway module →
Keep a copy of downloaded files for review or sandboxing
Trigger: a narrow Forward policy on the downloads you want to monitor (hosts, groups).
What the Worker does: returns the file to the user and stores a bounded copy in a private R2 bucket; sending it to a sandbox analysis service is a call you have to build.
Limit: the template copies files up to 25 MiB and skips larger ones; duplicating the stream can use memory on large transfers. The copy is taken before Gateway's final response inspection, so a file Gateway later blocks can still be stored: keep the bucket private, apply a retention rule, and treat captured files as untrusted.
Status: "Capture a downloaded file" template documented; sandboxing described by Cloudflare, to build.
Watermark internal pages with the user's identity
Trigger: a Forward policy on an internal application you control.
What the Worker does: adds a visible label (the user's name or email) to HTML pages, as a stream, without holding them in memory.
Limit: uncompressed HTML pages, 200 responses to GET requests; it discourages screenshots without preventing them.
Status: "Watermark HTML pages" template documented.
Strip a field before a request reaches an application
Trigger: a Forward policy on a specific endpoint with a known JSON schema.
What the Worker does: replaces a field, such as a customer identifier, with [REDACTED] before next().
Limit: this is a field-based transformation, not sensitive data detection; Gateway inspects the original body before the Worker, so the redaction doesn't bypass DLP; the modified data is not inspected again.
Status: "Redact a JSON field" template documented.
Can a Worker validate a DLP match?
Yes, but not through Forward. A Forward policy can't be selected by a DLP match, and the Worker's context doesn't include DLP match details.
Validation goes through a separate DLP capability, documented as "Validate data loss prevention matches with Cloudflare Workers". A Worker attached to a custom pattern entry receives an excerpt of the match and returns a score from -1 to 1, or a veto that rejects the match. Cloudflare's example: check that a detected GitHub secret is still active before blocking. The benefit is a sharper detection without uploading reference data for EDM (Exact Data Match).
According to the documentation, these custom functions appear in the entry editor "when this feature is available for your account". Check your account before you plan on it. See also our data loss prevention service and the DLP glossary entry.
What do you need before your first Forward policy?
- Gateway HTTP filtering turned on, with your test devices' traffic routed through Gateway.
- TLS (Transport Layer Security) inspection turned on, with a trusted root certificate installed on the devices.
- Workers and Gateway in the same Cloudflare account.
- A Workers subdomain configured for the account, and a Worker with no public route (
workers_devandpreview_urlsset tofalse). - The
@cloudflare/zt-typestypes if you write in TypeScript. - A test policy limited to one host and one test group.
If Gateway itself isn't in production yet, start there: our Zero Trust and SASE deployment covers that groundwork.
Where does Gateway Forward stop during the public beta?
Gateway Forward only handles regular HTTP traffic that Gateway decrypts. WebSocket connections, CONNECT tunnels, protocol upgrades and traffic matched by a Do Not Inspect policy never reach the Worker. If the Worker fails, Gateway fails closed: the request does not reach its destination.
| Point | Documented behaviour | What to plan |
|---|---|---|
| Decryption | HTTPS traffic has to be decrypted; Do Not Inspect traffic never reaches the Worker | applications with pinned certificates are exempt from inspection, so from the Worker too |
| Protocols | WebSocket, CONNECT tunnels, protocol upgrades and trailers bypass the Worker | don't rely on Forward for those flows |
| Selection | metadata, identity, posture; never an inspection, DLP or response result | DLP validation goes through the DLP capability |
| Destination | next() keeps the original URL and host, once; no retry, no fan-out | routing logic belongs elsewhere |
| Failure | any error fails closed | monitor the Worker as a critical component |
| Deletion | deleting a bound Worker returns HTTP 500 | update the policies first |
| Added data | no second DLP pass on the request side | decide at design time which controls apply to the modified version |
| Captures | the template copies are taken before the final response inspection | private bucket, retention rule, files treated as untrusted |
| fetch() | an independent subrequest, without the user's policies or egress IP | use next() to continue the user's request |
| Workers VPC | Workers VPC traffic that matches a Forward policy is dropped | exclude it from Forward policies |
| Background tasks | waitUntil() is subject to execution limits, not a durable queue | Queues or Workflows |
| Cost and limits | Gateway and Workers limits apply; Workers billing | size on representative traffic |
Use next(), not fetch(), to continue the user's request: only next() keeps Gateway's routing and egress. If the Worker must reach private services, give it a VPC Network binding to your Cloudflare One network, and exclude that Workers VPC traffic from your Forward policies, which Gateway drops.
What comes after Forward?
Cloudflare has announced Custom Functions for release before the end of the year. According to Cloudflare, a Worker will return a value that Gateway uses as a policy condition, including in network policies. We'll update this article when they ship.
How do you take a Forward rule into production?
- Start small. One host and one test group, then widen.
- Treat the Worker's availability like a security component's. On error, Gateway fails closed and the request never reaches its destination.
- Separate errors from refusals. In the documentation's example, the Worker returns 503 when identity can't be read and 403 when it is missing. An uncaught error gives an HTTP 500.
- Update policies before deleting a Worker, or matching requests fail with HTTP 500.
- Watch invocations in Workers Logs, and disable the test policy while you fix a failing script.
- Version and review the code like a security policy.
- Track consumption. Every call is a billed Workers request.
At Brixio, our Cloudflare engineers design, test and run this kind of rule, with more than 450 projects delivered and 24/7 operations from Paris, Dubai, Singapore, Casablanca and Zurich. Our own site, brixio.io, runs on Cloudflare Workers. See also our professional services, managed services and custom application development.
Workers in production. Beyond the gateway, our engineers build on Workers for clients: Bot Shield was built entirely on Workers for an airline.
Gateway Forward: frequently asked questions
Gateway Forward is an action in Cloudflare Gateway HTTP policies that hands traffic Gateway has already allowed to a Cloudflare Worker in your account. The Worker can change the request or the response, answer on its own, or run a background task. It lets you add business logic to your secure web gateway without running a separate proxy.
Gateway Forward has been in public beta since 15 October 2026, on all Zero Trust plans, and Worker calls are billed as standard Workers requests. Whether to use it in production depends on the risk of the rule: start with non-critical rules on a narrow scope, and plan for the fact that the Worker fails closed.
No for the original request body and the final response: Gateway inspects both, and a Block always wins. Data the Worker adds or changes in the request is not inspected again, so decide at design time which controls apply to the modified version.
Gateway fails closed: the request does not reach its destination. If the Worker bound to a policy is deleted, matching requests return HTTP 500 until the policy is updated.
Regular HTTP traffic that Gateway decrypts. WebSocket connections, CONNECT tunnels, protocol upgrades, trailers and traffic matched by a Do Not Inspect policy never reach the Worker.
Forward transforms HTTP traffic and is available in public beta. Custom Functions have been announced by Cloudflare: according to Cloudflare, a Worker will return a value that Gateway uses as a policy condition.
Cloudflare Gateway is the secure web gateway of Cloudflare One, sometimes called Cloudflare SWG. It filters DNS, network and HTTP traffic for users on any network. It is a different product from AI Gateway, which routes and monitors calls to AI models.