Sub topic 2
Forward proxies: acting on behalf of clients
This chapter assumes you know HTTP requests, methods and headers, what IP addresses, ports and DNS do, and that TLS provides encryption and server identity. It covers the forward proxy only. Reverse proxies come in a later chapter.
What a forward proxy does
A forward proxy sits between a group of clients and the servers they want to reach. The client sends its request to the proxy. The proxy makes the request to the destination on the client's behalf and returns the response.
The destination server sees the proxy's IP address, not the client's. The client knows the proxy exists and is configured to use it. That is the defining trait of a forward proxy: it represents the clients.
Why teams deploy one
- Egress control. All outbound traffic passes through one point, so you can allow or deny destinations.
- Anonymity of internal hosts. External servers see one shared address instead of many internal ones.
- Caching. Repeated downloads, such as software packages, can be served from the proxy's cache.
- Logging and audit. One place records which clients reached which sites.
A minimal configuration
This Squid configuration listens on port 3128. It lets only clients in 10.0.0.0/8 reach example.org and its subdomains, and it denies everything else.
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 allSquid checks http_access rules from top to bottom and stops at the first match. The final deny all makes the policy default-deny, so a request is refused unless a rule allows it. Putting deny all first would block everything.
Using the proxy from a client
Clients must be told about the proxy. With curl, the -x option names it:
curl -x http://proxy.internal:3128 https://example.org/For a plain http:// URL, curl sends the full URL to the proxy, and the proxy makes the upstream request. For an https:// URL, the proxy cannot read the request, because TLS runs end to end between the client and the origin. So curl first sends a CONNECT request:
CONNECT example.org:443 HTTP/1.1
Host: example.org:443
HTTP/1.1 200 Connection establishedAfter the 200, the proxy blindly copies bytes in both directions. The TLS handshake happens between the client and example.org, and the proxy sees only the destination host and port, not paths or content.
Common errors
| Symptom | Likely cause |
|---|---|
| `407 Proxy Authentication Required` | The proxy requires credentials the client did not send. |
| `403 Forbidden` from the proxy | The request matched a `deny` rule, or no `allow` rule. |
| HTTPS fails but HTTP works | The proxy does not permit `CONNECT` to port 443. |
| Some tools bypass the proxy | The tool ignores `http_proxy` and `https_proxy` environment variables. |
The last row matters for egress control. A forward proxy only controls traffic that actually goes through it. If clients can reach the internet directly, the policy can be bypassed. Pair the proxy with firewall rules that allow outbound traffic only from the proxy.
Exercise
A client uses a forward proxy to open https://example.org/account. The proxy log shows the entry for example.org:443, but not the path /account. Why?
Show answer
For HTTPS the client sends CONNECT example.org:443, and the proxy then relays encrypted bytes. The path is inside the TLS session between the client and the origin, which the proxy cannot read unless it intercepts TLS with its own certificate.
Exercise
In the Squid example, what happens to a request from 192.168.1.5 to example.org, and why?
Show answer
It is denied. The source is outside 10.0.0.0/8, so the allow rule does not match, and the final "http_access deny all" rule applies.