The problem
Why can't web filtering on your secure web gateway enforce your business rules?
Web filtering on a secure web gateway follows one model: match a condition, apply a terminal action. Category, URL, user group, device posture: the condition can be precise, but the outcome is always one of a few verdicts. URL filtering knows where a user is going. It doesn't know why, whether their security training is up to date, or whether the on-call team should hear about it.
So the rule moves elsewhere. A pool of NGINX proxies to add a header in front of an internal app. A pipeline from logs to a SIEM (security information and event management system) to Slack, which flags a new SaaS sign-up minutes after the fact. A ticket, a manual exception, and someone who has to remember to remove it. Each workaround is one more system to patch, monitor and explain to an auditor.
This is web filtering at the HTTP level, after TLS decryption (TLS: the protocol that encrypts web traffic), where the gateway sees the URL, the body and the user's identity. Filtering at the DNS level, before any connection, is a different control: see DNS filtering in our glossary, and secure web gateway for the definition.
A policy engine answers yes or no. Your business rarely does.
The rules
Which rules does your web gateway need that Allow or Block can't express?
Ask for a reason before a sensitive site opens
Your users need occasional access to a sensitive category, and you want to know why, without opening a ticket each time. Cloudflare documents a coaching page template that shows a page without contacting the destination; according to Cloudflare, a Worker can also record the reason and keep a session so the user isn't asked on every request. We build the unlock, the audit trail and the session around your groups and your retention rules.
Keep an application closed until security training is done
Your auditors want proof that only trained staff reach the finance or HR application. No Cloudflare template does this. A Worker can check your training records before letting the request through and return an explanatory page otherwise; we design that check with your HR system and decide with you what happens when it can't answer.
Alert the team when someone signs up to a new SaaS or AI tool
You want to know about a new tool the day someone signs up, without blocking them. Cloudflare documents a Slack notification template: the request goes through, and the alert is sent in the background. We map the sign-up endpoints of the tools you care about and route the alert to your on-call tool. This complements our shadow AI detection, which finds the AI tools already in use in your organisation.
Pass identity to internal apps
Your internal apps expect the user's identity or role in a header, and today a reverse proxy adds it. For identity passed as it is (email, groups, or a SAML or OIDC attribute, from the single sign-on protocols of your identity provider), a native Allow policy is enough: Gateway adds the header with dynamic variables, with no code. A Worker is only needed when the value requires logic, such as turning groups into an application role. Either way, the NGINX proxies placed in front of internal apps are no longer needed.
Set aside downloads for review
Your analysts want a copy of certain downloads for review. Cloudflare documents a template that copies files of up to 25 MiB to a private R2 bucket (R2: Cloudflare's object storage) while the user gets the download. The copy is taken before Gateway's final response inspection, so we keep the bucket private, apply retention, and integrate a third-party sandbox case by case.
Check whether a leaked secret is still live before blocking
Your DLP (data loss prevention) flags API keys, and some of the alerts are for keys already revoked. This is not a Forward rule: it is a separate DLP capability that runs a Worker to score or veto a match, available and enabled account by account. It sharpens detection without uploading reference data, as Exact Data Match (EDM) would require. See our managed DLP service.
The mechanism
Your code runs after the policy, not instead of it
Cloudflare Gateway evaluates your HTTP policies first: a Block always wins. Only then does a Forward policy hand the allowed request to your Worker. Gateway inspects the original body before passing it to the Worker; if that inspection blocks, it interrupts the Worker, even one already running. The Worker can modify the request, answer it itself, raise an alert, or let it through, once, to its original destination. Gateway inspects the final response before the user sees it. According to Cloudflare, Gateway and Workers run on the same servers. Three prerequisites: Gateway HTTP filtering, TLS decryption, and a trusted root certificate on users' devices.
See Gateway Forward in Cloudflare One, and how Gateway Forward works, step by step.
The decision
Native policy, Forward Worker or custom function: where should each rule live?
| Your need | Native policy | Forward Worker (public beta) | DLP validation (available) | Custom Function (announced) | Outside the gateway |
|---|---|---|---|---|---|
| Block a category, allow a domain | yes | ||||
| Pass identity in a header (email, groups, SAML or OIDC attribute) | yes (dynamic variables) | ||||
| Compute a role from groups | yes | yes (Cloudflare's example) | |||
| Ask for a reason and keep a record | yes (coaching page template, KV, D1) | ||||
| Warn the on-call team without blocking | yes, in the background (Slack template) | ||||
| Mask a field before it leaves | yes (JSON redaction template), without bypassing DLP | ||||
| Watermark a page with the user's name | yes (watermark template) | ||||
| Copy a download for review | yes (capture to R2 template) | ||||
| Gate access on external data (training, risk score) | possible, to design | yes, as a condition | |||
| Decide whether a detected secret is still live | no | yes | |||
| Layer 4 rule (ports, protocols) | no | yes | |||
| WebSocket, CONNECT, uninspected traffic | no | yes (another control) |
Custom Functions: expected before the end of the year, according to Cloudflare.
The principle is simple: native as long as the policy can express the rule, code only when the rule justifies it, because every coded rule has to be maintained. KV, D1 and R2 are Cloudflare's key-value store, SQL database and object storage.
The boundaries
What does a programmable gateway not do?
A Worker attached to Cloudflare Gateway only sees decrypted HTTP traffic. Traffic exempted from inspection, WebSocket connections and CONNECT tunnels go straight to their destination, and if the Worker fails, the request fails rather than passing unchecked.
We design every rule with these limits in mind:
- Traffic exempted from inspection never reaches the Worker, including applications with pinned certificates.
- WebSocket, CONNECT tunnels, protocol upgrades and HTTP trailers bypass the Worker.
- On error, the request fails (fail closed). If a Worker is deleted before its policies are updated, matching requests return HTTP 500.
- Gateway inspects the original body before the Worker. What the Worker adds to a request is not scanned again by DLP on the request side.
- Traffic your own Workers send through Workers VPC (their private connection to your networks) is dropped if it matches a Forward policy. Exclude it from your policies.
- A Forward policy can't be triggered by a DLP result. That decision belongs to DLP validation.
- Forward is in public beta. Pilot on a narrow scope first.
Expert tip. Before you delete a Worker, update every Forward policy that points to it. Gateway doesn't remove the policy, and matching requests start returning HTTP 500.
Code on Workers is not new to us: our engineers built Bot Shield entirely on Workers for an airline.
The operator
How does Brixio design and build your gateway rules?
Review your rules
- We go through what your gateway, proxies and scripts enforce today, and decide which rules stay native and which need code.
Put the prerequisites in place
- If Gateway HTTP filtering or TLS decryption isn't deployed yet, we deploy it first.
Write and test
- Each rule is built as a Worker, tested on a pilot group and host, and put into production progressively, in warn-only mode before it blocks.
Hand over a maintainable rule
- Versions, tests, rollback and a runbook for each rule, reviewed as Cloudflare's features evolve.
Cloudflare ASDP
Authorized Service Delivery Partner
Cloudflare only
no other vendor in delivery
ISO 27001:2022
certified
450+
delivered projects
5 hubs
Paris · Dubai · Singapore · Casablanca · Zurich
The offer is called Programmable Gateway modules. Brixio, a Cloudflare Authorized Service Delivery Partner (ASDP) with more than 450 projects delivered, decides which rules stay native and which need code, and builds them as Cloudflare Workers, alongside your Cloudflare One deployment, from Paris, Dubai, Singapore, Casablanca and Zurich. Our own site, brixio.io, is built and served on Cloudflare Workers.
See also our professional services and custom application development.