Sub topic 2
Forward proxies: acting on behalf of clients
This chapter assumes you know how HTTP requests, methods and headers work, what IP addresses, ports and DNS do, and what TLS provides. It covers the forward proxy: what it does, how a client reaches it, and where it fits in a design. Later chapters cover the reverse proxy, the CONNECT mechanics in more depth, and egress filtering in more depth.
What a forward proxy is
A forward proxy is an intermediary that sits in front of clients and makes requests to servers for them. The client sends its request to the proxy. The proxy opens its own connection to the destination server, relays the request, and returns the response to the client.
From the destination server's point of view, the request comes from the proxy. The server sees the proxy's IP address, not the client's. The client knows the proxy exists and is configured to use it (or is steered to it by the network, which a later chapter covers under transparent proxies).
That is the defining trait: a forward proxy represents the clients. Typical placements are a corporate network, a school, a data center with locked-down outbound traffic, or a developer's machine.
Why systems use a forward proxy
Teams add a forward proxy for a small set of reasons.
- Access control. The proxy decides which clients may reach which destinations. A rule can allow a subnet to reach only approved domains.
- Egress control. In a locked-down network, servers cannot connect to the internet directly. All outbound traffic goes through one choke point, which makes it easier to audit and restrict. A compromised host has a harder time contacting an arbitrary command-and-control server.
- Logging and auditing. One place records who requested what, and when.
- Caching. Many clients fetching the same package or file can share one cached copy, which saves bandwidth.
- Address consolidation. Outbound traffic from many hosts appears to come from one or a few addresses. A third party can then allow-list those addresses.
- Content filtering. The proxy can block categories of sites or scan downloads.
Each of these depends on one fact: all traffic passes through a single point that you control.
How a client uses a forward proxy
When a client is configured for a forward proxy, it changes how it writes the request. A normal request to a server uses a path in the request line:
GET /index.html HTTP/1.1
Host: example.orgA request sent to a forward proxy uses the absolute URL, so the proxy knows where to send it:
GET http://example.org/index.html HTTP/1.1
Host: example.orgThe proxy reads the target from the request line, connects to example.org, and sends a normal request. It typically removes proxy-specific headers before relaying.
HTTPS and the CONNECT method
Plain HTTP can be read and relayed. HTTPS cannot, because the request is encrypted between the client and the destination. The client therefore asks the proxy to open a raw TCP tunnel with the CONNECT method:
CONNECT example.org:443 HTTP/1.1
Host: example.org:443
HTTP/1.1 200 Connection establishedAfter the 200 response, the proxy only copies bytes in both directions. The client then performs the TLS handshake with example.org through the tunnel. The proxy cannot read the request paths, headers, or bodies. It does see the destination host and port from the CONNECT line, and the volume and timing of traffic. This is why a forward proxy can still allow or deny HTTPS destinations by hostname without decrypting anything.
You can watch this with curl, which sends a CONNECT first when the URL is HTTPS:
curl -x http://proxy.internal:3128 https://example.org/Add -v to see the CONNECT request and the proxy's reply before the TLS handshake starts.
A minimal Squid configuration
Squid is a widely used forward proxy. The following configuration listens on port 3128 and allows only clients in 10.0.0.0/8 to reach example.org and its subdomains.
http_port 3128
acl localnet src 10.0.0.0/8
acl allowed_sites dstdomain .example.org
http_access allow localnet allowed_sites
http_access deny allHere is how it works.
http_port 3128is the port the proxy listens on. Clients point at this port.acl localnet src 10.0.0.0/8defines a named rule that matches requests whose source address is in that range.acl allowed_sites dstdomain .example.orgdefines a rule that matches requests whose destination domain isexample.orgor any subdomain. The leading dot is what includes subdomains.http_access allow localnet allowed_sitesallows a request only if it matches both ACLs. Multiple ACLs on one line are combined with AND.http_access deny allis the final rule.
Squid evaluates http_access lines from top to bottom and stops at the first match. The last deny all makes the policy default-deny. If you leave it out, the behavior when nothing matches depends on the last rule's action, which is a common source of accidental open proxies.
Because the CONNECT method carries the destination as example.org:443, the same dstdomain rule applies to HTTPS tunnels. In real deployments you also restrict which ports CONNECT may target, usually to 443 only. Otherwise a client could tunnel to any port on an allowed host.
Authentication
Source-IP rules are simple but coarse. When many users share an address range, or users move between networks, proxies can require authentication. The proxy replies 407 Proxy Authentication Required with a Proxy-Authenticate header, and the client retries with a Proxy-Authorization header. This is the proxy-level counterpart of 401 and Authorization used by origin servers. Do not confuse the two pairs of headers. A request through a proxy can carry both, one for the proxy and one for the destination.
What the destination sees
Because the proxy makes the outbound connection, the destination sees the proxy's address. Some proxies add headers such as Via or X-Forwarded-For to identify themselves or the client, and some are configured to strip them. If you operate a forward proxy and want client privacy, check which headers it adds. If you operate a service that receives proxied traffic, do not treat the source address as one user. Many users can share it, which affects rate limiting and abuse blocking.
HTTPS inspection and its cost
A proxy that must see inside HTTPS can act as a man-in-the-middle by design. The proxy terminates the client's TLS session using a certificate it generates on the fly for each site. It then opens a second TLS session to the real server. For this to work without browser warnings, every client must trust the proxy's own certificate authority (CA).
This allows content scanning and full URL logging, but it has costs.
- You must distribute and protect the proxy CA. If its private key leaks, an attacker can impersonate any site to your clients.
- Applications that pin certificates, and some clients that ignore the system trust store, will fail.
- The proxy now handles plaintext of sensitive traffic, which has privacy and legal implications.
- The proxy does extra cryptographic work, which costs CPU and latency.
Many organizations choose hostname-level allow-listing through CONNECT and skip inspection for sensitive categories such as banking and health.
Trade-offs and failure modes
| Concern | What happens | Mitigation |
|---|---|---|
| Single point of failure | If the proxy is down, clients with no direct route lose all outbound access | Run two or more proxies behind a virtual address or DNS name |
| Added latency | Each request takes an extra hop and an extra connection | Keep proxies close to clients, reuse connections, cache |
| Clients bypassing the proxy | Apps that ignore proxy settings connect directly | Block direct egress at the firewall so the proxy is the only path |
| Misconfigured ACLs | Rules match more than intended, or the proxy is open | Default-deny, test with known allowed and denied cases |
| Inconsistent client settings | Some tools read `http_proxy`, others use system settings, others none | Standardize configuration, and document `no_proxy` exceptions |
The bypass row matters most. A forward proxy enforces policy only if it is the sole route out. If clients can still reach the internet directly, the proxy is advisory. Pairing the proxy with a firewall rule that permits outbound traffic only from the proxy makes it enforcing.
Many command-line tools read the environment variables http_proxy, https_proxy and no_proxy. Setting them is the quickest way to route a tool through a proxy:
export https_proxy=http://proxy.internal:3128
export no_proxy=localhost,127.0.0.1,.internal
curl https://example.org/Names listed in no_proxy are contacted directly. Leaving internal hosts out of no_proxy is a frequent cause of internal calls failing with 403 or timeouts, because the proxy cannot reach them or refuses them.
Exercise
A forward proxy is configured with the rule http_access allow localnet allowed_sites and no final rule. A client outside localnet requests https://example.org/. Why is this configuration risky, and what single line should you add at the end? Also, what can the proxy see of that HTTPS request when the client uses CONNECT?
Show answer
Without a final rule, the outcome for requests that match no line depends on the proxy's defaults and on the last rule's action, so the policy is not clearly default-deny and may leave the proxy more open than intended. Add http_access deny all as the last line. With CONNECT, the proxy sees the destination host and port (example.org:443), the client address, and the amount and timing of traffic. It cannot see the path, headers or body, because the TLS session runs end to end between the client and example.org.
Exercise
Your organization installs a forward proxy but a developer's tool still reaches the internet directly. Name the likely cause and the control that fixes it.
Show answer
The tool ignores the proxy settings, and nothing stops direct outbound connections. Fix it by blocking direct egress at the firewall so only the proxy may connect to the internet. The tool must then use the proxy or fail.