Web Proxy / Caching Fundamentals Series

🛡️ A Top 1% Hands-On for Reproducing Squid's Open-Proxy Danger Yourself and Defending With ACL-Based Access Restriction

Introduction

This article is part of the Top 1% Series Complete Article Guide, and the tenth article in the Web Proxy/Caching Series. You can follow along with one of the Ubuntu Server environments set up in the Hands-On Prep Manual.

Prerequisite Knowledge

Getting the Big Picture

This hands-on covers two stages.

graph TB
    subgraph Step1["Steps 1-2: The Open Proxy's Danger"]
        A1["Start a proxy with<br/>no access restriction"]
        A2["Anyone, from any source,<br/>can request a relay"]
        A1 --> A2
    end
    subgraph Step2["Steps 3-4: Defense via ACL"]
        B1["Use acl to explicitly declare<br/>the allowed source network"]
        B2["A relay gets denied from<br/>any other source"]
        B1 --> B2
    end
    Step1 --> Step2

Hands-On Steps

Step 1: Start Squid With Zero Access Restriction Configured

sudo apt install -y squid

Deliberately disable every one of the default access-restriction rules in /etc/squid/squid.conf related to source networks (other than rules like http_access deny !Safe_ports).

http_access allow all
http_port 3128
sudo systemctl restart squid

Step 2: Request a Relay From a Separate Test Network

From a network separate from where this proxy was built (a second test client), attempt to communicate through this proxy.

curl -x http://<the proxy's IP address>:3128 http://example.com/ -o /dev/null -s -w "%{http_code}\n"

Output:

200

A request from an entirely unrelated network, from anyone other than this proxy’s own builder, just got relayed with no restriction whatsoever. This is an open proxy. If this proxy were exposed on the internet, there’s a real danger it could get abused as a stepping stone for a third party to make an unauthorized access against some other server while hiding their own identity (IP address) behind this proxy.

Why an Open Proxy Gets Created Unintentionally

Squid’s configuration takes the form of explicitly adding what to allow, and forgetting to write a restriction on the source can, depending on the default behavior, result in a configuration that unintentionally allows access from the entire world. The typical path to an open proxy is temporarily setting an overly broad allowance, like http_access allow all, for the sake of “just getting it working” during testing, then forgetting to revert it before going into production.

Step 3: Explicitly Declare the Allowed Source Network via ACL

sudo tee /etc/squid/squid.conf << 'EOF'
acl allowed_network src 192.168.1.0/24
http_access allow allowed_network
http_access deny all
http_port 3128
EOF
sudo systemctl restart squid

acl allowed_network src 192.168.1.0/24 is a definition: “identify only traffic from this IP address range under the name allowed_network.” Then http_access allow allowed_network allows only traffic from that range, and http_access deny all explicitly denies everything else.

Step 4: Confirm Access From an Unauthorized Network Gets Denied

curl -x http://<the proxy's IP address>:3128 http://example.com/ -o /dev/null -s -w "%{http_code}\n"

Output:

403

Unlike before, a request from an unauthorized network got denied, as a 403 (Forbidden). Confirm, too, that the same request, sent from a client inside the network range specified in allowed_network, still gets relayed normally.

What a Pro Sees Here (Top 1% Understanding)

Access Control Is Premised on “Closing With a Final Deny-All,” Not Just “Adding Allow Rules”

The biggest lesson from this hands-on is that merely listing the rules you want to allow is never enough to reliably deny access from an unexpected source, without an explicit final deny rule (http_access deny all). Access-control rules get evaluated top to bottom, and the first matching rule applies, so you always need to explicitly define how a source gets handled in the end, when it matches none of your intended allow rules. This shares the same underlying risk structure as DNS amplification defense (response rate limiting) and mail open-relay hardening: “a configuration that opens a service up to third parties without limit gets created easily, regardless of the builder’s actual intent” — a risk structure common across relay-type services in general, whether proxies, DNS, or mail. A top-1% engineer, every time they build a new relay-type service, explicitly confirms “who is this service meant to serve, and is everyone else genuinely denied?”

Common Misconceptions and Pitfalls

Troubleshooting Perspective

  1. Access even from an intended source gets denied: Check whether the IP address range defined in acl actually matches the real source’s IP address.
  2. Behavior doesn’t change despite a configuration change: After changing Squid’s configuration, run systemctl restart squid (or reload) and confirm the change actually took effect.
  3. You suspect abuse of a proxy exposed externally: Check the access log for a large volume or an abnormal pattern of requests from an unexpected source.

Summary

Takeaways to Apply Today

  1. When building a new proxy or any other relay-type service, always build in access-restriction rules from the initial design stage.
  2. When writing access-control rules, always explicitly confirm “how does a source get handled in the end, if it matches none of these rules?”

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).