Cloudflare Worker Reverse Proxy

Published
Length
3 min read

Luis Felipe Dias

All posts

You build a cloudflare worker reverse proxy by writing a script at the edge. This script catches web requests and sends them to your backend servers. Teams often use this setup to combine several web apps under one main domain. Still, broad routing rules can expose internal endpoints to public users by mistake. When permissions are too wide, any caller who passes the edge can run backend actions. How a cloudflare worker reverse proxy works A cloudflare worker reverse proxy runs in edge data c

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.

You build a cloudflare worker reverse proxy by writing a script at the edge. This script catches web requests and sends them to your backend servers. Teams often use this setup to combine several web apps under one main domain. Still, broad routing rules can expose internal endpoints to public users by mistake. When permissions are too wide, any caller who passes the edge can run backend actions.

How a cloudflare worker reverse proxy works

A cloudflare worker reverse proxy runs in edge data centers around the world. When a user sends a web request, the nearest edge server catches it first. The edge script reads the incoming URL path, headers, and method right away. Next, the script changes the target host to match a private backend server. It can also add or remove headers before it forwards the network call.

The backend server gets the request and processes the work as normal. It sends a response back to the edge script over the network. The script can then change response headers or status codes if needed. Finally, the edge server sends the finished response back to the user. The user only sees the main domain name during this whole process. They do not see the true location of the hidden backend server.

Routing rules and header management at the edge

Teams use edge routing to merge different web services into one site. For example, a company might host a blog on one service and an app elsewhere. The edge script checks the path of every web call that comes in. If the path starts with the blog folder, traffic goes to the blog host. Other paths go straight to the main web app server instead.

Good header management keeps this traffic flowing without errors. When the script sends a call forward, it must set the host header right. If the host header does not match, the backend server will reject the call. Teams also use edge scripts to strip out sensitive server headers from replies. This hides the software names and versions that run on the backend machines. You can also set cache rules at the edge to speed up static files.

Reverse Proxy Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What edge scripts solve and what they leave open

An edge script is great for routing public web traffic and caching static files. It hides backend IP addresses and stops simple web attacks at the border. Teams can also check basic login tokens at the edge before forwarding calls. This setup decides who can reach the front door of a web service.

Still, an edge script leaves a big gap for internal ops and data work. Edge routing only checks if a request can pass through to the backend. It does not inspect what individual database queries or system commands do in flight. Once a user or tool passes the edge, they often hold broad backend rights. Also, edge scripts only handle web traffic and cannot govern direct database sessions. They also do not mask sensitive data like emails, phone numbers, or card numbers. If a backend reply holds national IDs, the edge script passes them right through. Teams still need a way to control specific actions and rewrite sensitive fields in results.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Why do backend servers reject forwarded edge requests?

Backend servers often check the host header to route incoming web traffic. If the edge script keeps the original host header, the backend may reject it. You must rewrite the header in your script to match the target server name.

Can an edge script handle non-web database traffic?

Standard edge workers are built to handle web requests and responses over HTTP. They are not designed to manage stateful database protocols or interactive command sessions. Teams need dedicated access tools to control direct database queries and admin shell work.

How do you prevent infinite loops in edge routing?

Loops happen when a script forwards a request back to its own domain route. Always point your target URL to a separate origin server or a different hostname. Check your route triggers to make sure forwarded calls do not hit the same script.

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.