Unlocking New Flexibility with Cloudflare’s Programmable Gateway
Cloudflare introduces programmable features in Gateway, boosting security flexibility for all plan users.

Cloudflare has announced a major development in the field of secure web gateways, introducing a fully programmable gateway integrated with their edge computing platform. This shift promises significant flexibility and customization opportunities for enterprises. By combining Cloudflare Gateway with Cloudflare Workers, users can now execute custom code on the fly, directly within the policy evaluation path.
What Changed with Cloudflare's Gateway?
The key change here is the true programmability brought to Cloudflare Gateway and Data Loss Prevention (DLP). Unlike traditional secure web gateways that operate on a fixed set of actions — Allow, Block, Isolate, Log — Cloudflare's new approach allows users to implement their own logic using a Cloudflare Worker. This change moves beyond surface-level programmability, such as public APIs and webhooks, offering real-time code execution for policy decisions.
Why Does This Matter to Enterprises?
For enterprises managing complex environments, the traditional binary approach of vendor-specific solutions comes with limited flexibility. Enterprises either had to maintain their own cumbersome security infrastructure or depend on vendor constraints. With Cloudflare’s new offering, users can write and execute custom logic inline without the need for additional infrastructure, thus balancing high customization with low maintenance.
This development is particularly valuable for teams needing to dynamically manipulate HTTP traffic, such as injecting headers based on JWT claims, or automating Slack notifications for specific user actions without the infrastructure overhead.
Forward Action and Custom Functions
Cloudflare introduced two new capabilities: Forward actions and Custom Functions.
- Forward Action: This new beta feature allows HTTP requests to be routed to a Cloudflare Worker. The Worker acts as middleware, enabling you to modify requests or responses as needed without additional network latency. This grants the ability to perform transformations like header injections, content modifications, or routing logic.
- Custom Functions: These allow you to call a Worker inline, providing a value directly used in Gateway policies. The Worker processes input data, such as user identity or device posture, and returns a value that dictates policy action. Custom Functions enable the use of context-aware decisions, expanding the scope of policy conditions beyond static rules.
Am I Affected by This Change?
If you use Cloudflare Gateway in any capacity, these changes offer you powerful new tools. The Forward action is currently in public beta, meaning you can start integrating it into your workflows immediately. Custom Functions will be available by the end of the year, expanding the possibilities for inline policy evaluations. All Zero Trust plan users can leverage these features, removing barriers based on plan types. It’s an opportunity for businesses to enhance their security posture dynamically and contextually.
Implementing Cloudflare's Programmable Features
- Enable the Forward Action: Access the Cloudflare dashboard, navigate to your Gateway policies, and modify your HTTP rules to include the new Forward action. Link this action to a custom Worker that performs the necessary transformations. Confirm the Worker is properly set up to handle request headers, manipulating them as required.
- Create Custom Functions: Develop a Cloudflare Worker that can be used as a selector within Gateway policies. This function can evaluate complex conditions like parsing JWT tokens and return a role for policy decisions. Ensure the returned values meet your security criteria and thoroughly test the logic against anticipated traffic scenarios.
- Test and Iterate: Deploy these Workers in a testing environment to ensure that the logic performs as intended without affecting user traffic negatively. Monitor performance to confirm there is no additional latency beyond code execution time. Revise and optimize code based on the feedback received during testing to maintain efficiency and effectiveness.
- Implement Monitoring: Utilize Cloudflare's analytics and logging features to observe the real-world performance of implemented Workers. Establish alerts for unexpected behaviors or failures to maintain robust oversight.
import { WorkerEntrypoint } from "cloudflare:workers";
import type {
GatewayMiddlewareContext,
GatewayMiddlewareNext,
} from "@cloudflare/zt-types";
export class GatewayMiddleware extends WorkerEntrypoint {
async handle(request: Request, context: GatewayMiddlewareContext, next: GatewayMiddlewareNext): Promise<Response> {
request.headers.set("X-Gateway-Client-IP", context.srcIp);
const response = await next(request);
response.headers.set("X-Processed-By", "gateway-middleware");
return response;
}
}
Limitations of Cloudflare's Programmable Gateway
While these newly programmable capabilities open up vast possibilities, they do have limitations. The Forward action requires careful design to avoid complex transformations that may degrade user experience. Additionally, deploying custom Workers requires understanding of Cloudflare’s serverless execution model, including any applicable limitations of the Workers Free usage policy.
Custom functions are deterministic but require thoughtful implementation to ensure they return correct and reliable responses under all conditions. Misconfigurations or excessive logic within Workers can lead to increased latency or unintended security gaps. As such, a strategic approach to design and testing is crucial.
Practical Use Cases for Cloudflare's Programmable Gateway
Several common use cases showcase the value of the programmable capabilities:
- Purpose Justification and Interstitial Pages: A Worker intercepts requests to sensitive destinations, prompting users for justification. This creates an audit trail and limits access frequency based on set conditions. By using Cloudflare KV and D1, businesses can build comprehensive access control solutions.
- Dynamic HTTP Header Injection: Automatically inject headers based on user roles extracted from JWT tokens, eliminating the need for additional proxy infrastructure. This reduces operational overhead and enhances security protocols by dynamically applying policies.
- File Inspection and Logging: Workers can send files to third-party services for analysis, log data within Cloudflare R2, ensuring a secure and compliant data management system.
- Real-Time Alerting on Policy Match: Workers can send alerts to platforms like Slack whenever specific policy conditions are met, providing immediate feedback on user actions. This enables organizations to respond swiftly to potential security incidents.
My Take on Cloudflare’s Programmable Gateway
I believe this enhancement represents a significant leap forward, particularly for cloud-native organizations that rely on adaptable security measures. The new flexibility could save countless hours and resources typically devoted to maintaining separate proxy infrastructure. While some teams might face a learning curve with Workers, the potential payoff in efficiency and agility is substantial. If I were managing a deployment, I'd pilot this in a non-critical environment to understand its nuances before full-scale adoption.
Frequently asked questions
What is Cloudflare's new Forward action?
It allows routing of HTTP requests to a Cloudflare Worker for custom processing and is available in public beta.
How do Custom Functions work in Cloudflare Gateway?
They enable calling a Worker inline to return values used in policy decisions, available by the end of the year.
Who can use these new programmable features?
All Zero Trust plan users have access to both the Forward action and Custom Functions once released.
What are the benefits of using Cloudflare's programmable gateway?
It offers flexibility and reduces infrastructure needs by allowing custom code execution directly in security policies.
Source: blog.cloudflare.com
How this article was made: drafted with AI from the source above, then fact-checked against it before publishing.


