Sub topic 6
Access control and egress filtering with a forward proxy
This chapter assumes you know HTTP methods and headers, what the CONNECT method does, and the basic idea of TLS. It covers how a forward proxy decides which outbound requests to allow, and where that control breaks down.
Why filter outbound traffic
Most security work focuses on inbound traffic. Outbound traffic (egress) matters too. A compromised server can download malware, send stolen data to an attacker, or contact a command server. Staff can also visit sites that policy forbids.
A forward proxy is a natural control point. If clients can reach the internet only through the proxy, every outbound request passes one place where you can allow it, deny it, or log it.
A minimal Squid policy
Squid is a widely used forward proxy. Its policy is written as access control lists (ACLs), which name a set of requests, and rules that allow or deny them.
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 allEach part does one job:
http_port 3128makes Squid listen for client connections on port 3128.acl localnet src 10.0.0.0/8matches requests whose source address is in the internal network.acl allowed_sites dstdomain .example.orgmatches requests toexample.organd its subdomains. The leading dot covers the subdomains.http_access allow localnet allowed_sitesallows a request only when it matches both ACLs. Names on one line are combined with AND.http_access deny allends the list with a default deny.
Squid checks http_access rules from top to bottom and stops at the first match. Because of this, the order matters, and the final deny all makes anything unlisted fail closed.
flowchart TDWhat the proxy can see
For plain HTTP, the proxy reads the full request, including the URL and headers. For HTTPS, the client sends a CONNECT request first:
CONNECT example.org:443 HTTP/1.1
Host: example.org:443
HTTP/1.1 200 Connection establishedAfter the 200 response, the proxy relays encrypted bytes. It sees the destination host and port, but not the path, headers or body. Filtering therefore works on the domain, not on the URL path, unless you add TLS interception.
You can test a policy from a client with curl:
curl -x http://proxy.internal:3128 https://example.org/A request to an allowed domain succeeds. A request to any other domain should return 403 Forbidden from Squid.
Common errors
- Allowing CONNECT to any port. A client can tunnel any protocol through CONNECT. Restrict it to port 443, or to the ports you actually need, with a
Safe_portsandSSL_portsstyle ACL ondstport. - Rule order mistakes. A broad
allowplaced above a specificdenymakes the deny unreachable. - Leaving a way around the proxy. If clients can reach the internet directly, the proxy is advice, not enforcement. Block direct outbound traffic at the firewall, so that only the proxy host may connect out.
- Exposing the proxy to the internet. A proxy with no source restriction is an open proxy that strangers use to hide their traffic. Always include a
srcACL. - Trusting domain filtering too much. A content delivery network or cloud service can host both allowed and unwanted content under one domain name. Domain rules cannot tell the two apart.
Logging
The proxy's access log records who requested what and when. This helps with audits and incident response, for example finding which host contacted a suspicious domain. Remember that the log shows the destination host for HTTPS, not the full URL.
Exercise
A Squid server has the rules http_access deny all followed by http_access allow localnet allowed_sites. Clients in the internal network cannot reach example.org. Why, and how do you fix it?
Show answer
Squid stops at the first matching rule, and deny all matches every request, so the allow rule is never reached. Move http_access allow localnet allowed_sites above http_access deny all.
Exercise
Why can a forward proxy block https://example.org/ but not only https://example.org/private without extra setup?
Show answer
For HTTPS the proxy sees only the CONNECT line, which names the host and port. The path is inside the encrypted tunnel, so the proxy would need TLS interception to read it.