Cloudflare Workers Reverse Proxy

Published
Length
3 min read

Luis Felipe Dias

All posts

A cloudflare workers reverse proxy catches web requests at the edge and sends them to backend servers. You set it up by writing a script that reads the URL and rewrites the host header. Platform teams use this pattern to combine several backend services under one domain name. When teams grant broad backend access to that edge script, one bad rule exposes internal data. How a cloudflare workers reverse proxy routes traffic Every request from a user hits a nearby edge server first. Your worker

Reverse Proxy Security: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

A cloudflare workers reverse proxy catches web requests at the edge and sends them to backend servers. You set it up by writing a script that reads the URL and rewrites the host header. Platform teams use this pattern to combine several backend services under one domain name. When teams grant broad backend access to that edge script, one bad rule exposes internal data.

How a cloudflare workers reverse proxy routes traffic

Every request from a user hits a nearby edge server first. Your worker script wakes up and reads the incoming request path and headers. The script matches the path against a map of internal origins that your team maintains. Next, the script builds a new web request that points to the right origin server.

Teams often change request headers before the worker sends the call upstream. You might strip cookies, add custom routing headers, or rewrite the URL path to match backend folders. Once the origin server replies, the worker receives the response payload at the edge. The script can then add security headers or cache rules before the user gets the reply.

Setting up origin trust and edge permissions

Origin servers must verify that incoming traffic really came from your edge worker. If an origin accepts public traffic directly, attackers can skip your edge rules and hit the backend. Teams solve this by locking down origin firewall rules to allow only edge network address ranges. Many teams also set up mutual TLS certificates between the edge script and the origin server.

Your edge script needs secret keys to talk to private internal services. Admins store those keys as encrypted variables inside the edge platform account. Anyone on the team with edit rights to the worker can change how the script uses those keys. If a developer gives a worker broad role permissions, every route on that domain shares that trust.

What edge routing solves and what it leaves open

Edge routing solves the problem of splitting traffic across old and new backend systems. It lets you move pages to new servers without changing the links that users click. It also hides your internal server names and network layout from public view. Edge firewall rules can block bad traffic before it ever touches your own servers.

Reverse Proxy Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, edge routing only decides where a web request goes and whether the caller can log in. It does not inspect what individual backend commands or data queries do once inside your network. When engineers use edge routes to reach internal tools or admin APIs, the edge script passes requests blindly. A static secret at the edge also gives every forwarded call the same high level of backend trust.

Nor does a basic routing script remove sensitive values from backend responses on its own. If an internal API returns raw emails, phone numbers, or card numbers, the script passes them straight through. Teams need a way to check each action and rewrite matched fields in results before data leaves.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

When should a team use an edge script for routing?

Use an edge script when you need to combine separate websites under one main domain name. It also works well when you must rewrite paths or headers during a server migration.

How do you stop users from bypassing the edge script?

Set your origin firewall to drop all web traffic that does not come from edge IP ranges. You should also require a client certificate from the edge network before the origin accepts requests.

Can an edge routing script protect internal admin tools?

An edge script can check user login tokens before it forwards traffic to an internal tool. Still, it cannot approve individual actions or mask sensitive fields like national IDs in the response.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.