Sub topic 6
Access control and egress filtering with a forward proxy
This chapter assumes you know how a forward proxy relays HTTP and HTTPS requests, including the CONNECT method from the previous chapter. It also assumes basic familiarity with IP addresses, ports, DNS and HTTP headers. Here you will see how a forward proxy decides which requests may leave a network, and what it can and cannot see when it decides.
Why a forward proxy is a control point
In a forward proxy deployment, clients send their outbound web traffic to the proxy instead of connecting to servers directly. That makes the proxy the one place where outbound traffic can be checked, allowed, denied and recorded.
Organizations use this for several reasons:
- Egress control. Egress is traffic leaving your network. Limiting it to known destinations reduces the damage from malware that tries to contact a command server or upload stolen data.
- Policy enforcement. A company can block categories of sites, or allow only the package registries and APIs that build servers need.
- Accountability. Every request passes through one component, so one access log records who asked for what and when.
- Source address consolidation. External services see the proxy's address, so you can give a partner a single IP to allow.
The proxy only controls traffic that goes through it. This point comes up again below, because most real failures of egress filtering are bypasses.
Rules and how they are evaluated
Squid is a widely used forward proxy. Its policy is a list of acl definitions, which name a set of matching conditions, followed by http_access rules, which say allow or deny for requests matching those names.
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 allReading this configuration:
http_port 3128makes Squid listen on port 3128.acl localnet src 10.0.0.0/8matches requests whose client address is in10.0.0.0/8.acl allowed_sites dstdomain .example.orgmatches requests forexample.organd any subdomain. The leading dot is what includes subdomains.http_access allow localnet allowed_siteslists two ACLs on one line. A line matches only when all of its ACLs match (logical AND).http_access deny allis the final catch-all.
Squid checks http_access lines from top to bottom and the first matching line wins. Order is therefore part of the policy. If you put http_access allow localnet above a more specific deny line, the deny line never runs for those clients.
The last line is a default-deny. If no rule matches, Squid applies the opposite of the last rule's action, so end the list with an explicit deny all to make the intent clear.
Matching on more than the domain
Real policies combine several kinds of conditions. A fuller example:
http_port 3128
acl localnet src 10.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80 443
acl CONNECT method CONNECT
acl allowed_sites dstdomain .example.org
acl blocked_sites dstdomain "/etc/squid/blocked_domains.txt"
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny blocked_sites
http_access allow localnet allowed_sites
http_access deny allWhat each rule does:
deny !Safe_portsrejects requests to any port other than 80 and 443. The!negates the ACL.deny CONNECT !SSL_portsallows tunnels only to port 443. Without this, a client could ask the proxy toCONNECTto port 25 on an internal mail server and use the proxy as a relay into places it should never reach.deny blocked_sitesreads a list of domains from a file, which is easier to maintain than inline rules.allow localnet allowed_sitesis the actual allow-list.deny allcloses the policy.
Putting the safety denials first means no later allow rule can accidentally override them.
What the proxy can see: HTTP versus HTTPS
What you can filter on depends on whether the traffic is encrypted.
| Traffic | What the proxy sees | What you can filter on |
|---|---|---|
| Plain HTTP | Full request line, headers, body | Domain, URL path, method, headers, content |
| HTTPS through `CONNECT` | Only the target host and port | Domain and port, not the path or content |
| HTTPS with TLS interception | Decrypted requests | Same as plain HTTP, at a cost |
For HTTPS, the client sends a CONNECT request and the proxy opens a raw TCP tunnel:
CONNECT example.org:443 HTTP/1.1
Host: example.org:443
HTTP/1.1 200 Connection establishedAfter the 200, the proxy copies bytes in both directions without reading them. The decision to allow or deny happens before the tunnel opens, using only example.org:443. A rule such as "allow example.org/docs but deny example.org/admin" cannot be enforced on tunneled HTTPS.
You can test this from a client with an explicit proxy setting:
curl -x http://proxy.internal:3128 https://example.org/For a URL on a denied domain, curl reports a failure at the CONNECT step (typically 403 Forbidden from the proxy), and the origin server never receives anything.
TLS interception
Some proxies decrypt HTTPS so they can see paths and content. The proxy presents its own certificate for each site, signed by an internal certificate authority that is installed on every client. In Squid this feature is called SSL bump.
Interception gives deeper filtering, but it has costs:
- The proxy holds the key that can impersonate any site to your clients, so it becomes a very sensitive system.
- Applications that pin certificates, and some tools with their own trust stores, will fail.
- Privacy and legal rules may restrict decrypting some traffic, such as banking or health sites. Many deployments exempt these categories.
- CPU use rises because the proxy performs two TLS handshakes per connection.
Many teams skip interception and filter by domain only, which is enough for an allow-list of known services.
Authentication
IP-based rules are simple but identify only machines. When the proxy needs to know the user, it can require authentication. An unauthenticated request receives 407 Proxy Authentication Required with a Proxy-Authenticate header, and the client retries with a Proxy-Authorization header. Squid supports Basic, Digest, NTLM and Negotiate (Kerberos) through helper programs.
Note the number: 407 is the proxy asking for credentials, while 401 comes from the origin server. Confusing the two is a common debugging mistake.
Once users are identified, you can write rules per user or group, for example allowing only the engineering group to reach package registries. Authenticated names also appear in the access log, which makes audits meaningful.
Making the filter hard to bypass
A proxy policy matters only if traffic cannot go around it. The usual pattern is to combine the proxy with network-level rules:
- The firewall or security group blocks outbound ports 80 and 443 from client subnets to the internet.
- The only permitted outbound path is from the proxy's address.
- Clients are configured, by environment variables, browser settings or a PAC file, to use the proxy. A PAC file is a small script that tells a browser which proxy to use for each URL.
If the firewall allows direct outbound traffic, a program that ignores proxy settings will simply connect directly. Many command-line tools honor HTTP_PROXY and HTTPS_PROXY, but not all do, and some use a different variable name or ignore it. Blocking direct egress turns "ignored the setting" into "failed loudly", which is easier to fix than a silent bypass.
When clients cannot be configured at all, the network can redirect their traffic to the proxy without their knowledge. That is a transparent deployment, covered in the next chapter.
Common pitfalls
- Rule order mistakes. A broad
allowplaced early overrides later denies. Review rules top to bottom, and test with a request that should be denied. - Missing default deny. Without a final
deny all, behavior depends on defaults you may not remember. - Subdomain surprises.
.example.orgmatchesanything.example.org, including subdomains hosted by third parties on that domain. Useexample.orgwithout the dot for an exact match. - DNS bypass. If clients resolve names themselves and the proxy trusts the address instead of the name, rules can be sidestepped. Match on
dstdomain, and restrict who may reach external DNS. - Unlogged denials. Check that denied requests appear in the log. Repeated denials from one host are often the first sign of malware.
- Proxy as a pivot. Without port and destination restrictions, the proxy can be used to reach internal services. Deny private address ranges as destinations unless you intend access to them.
Exercise
A Squid proxy has these lines in order: http_access allow localnet, then http_access deny blocked_sites, then http_access deny all. A client in localnet requests a domain listed in blocked_sites. What happens, and how do you fix the policy?
Show answer
The request is allowed. Squid uses the first matching line, and allow localnet matches every request from that client, so the deny line is never reached. Move http_access deny blocked_sites above http_access allow localnet, or replace the broad allow with a narrower one such as allow localnet allowed_sites.
Exercise
Your policy is "allow example.org/docs, deny example.org/admin". Why does the proxy fail to enforce this for HTTPS requests, and what two options do you have?
Show answer
With CONNECT, the proxy sees only example.org:443. The path travels inside the encrypted tunnel. Option one is to enforce the path rule at the origin server or a reverse proxy in front of it. Option two is to enable TLS interception on the forward proxy, accepting the certificate-authority, compatibility and privacy costs.
Exercise
A build server has HTTPS_PROXY set, yet one tool still reaches the internet directly. What network change makes the proxy policy reliable, and what do you expect to see after the change?
Show answer
Block direct outbound traffic on ports 80 and 443 from the build server's subnet, and allow it only from the proxy. The tool that ignores the proxy setting will then fail to connect, which exposes it so you can configure it to use the proxy.