GrepBoard/Manuals
605 manuals ·

Squid proxy: allow only your subnet, check 403 TCP_DENIED

·Tested on Ubuntu 24.04 · Squid 6.14 (Docker) · curl · 2026-10·Test scope ↓·7 steps

Limit Squid to your subnet with acl src and http_access, keep the default protection rules, and check curl -x (200/403) and TCP_DENIED. Wrong order blocks all.

output
1793078671.617      0 203.0.113.7 TCP_DENIED/403 3388 GET http://192.0.2.20/ - HIER_NONE/- text/html

To open Squid as a proxy for your own network only, define the range with acl … src and put http_access allow after the documentation's default protection rules (unsafe ports, CONNECT to non-443 ports, the cache manager, the proxy itself and link-local addresses) and before http_access deny all. Requests from anywhere else get a 403 and show up in access.log as TCP_DENIED/403. This was verified with two containers (Squid, and an origin server that also acted as the allowed client) plus a non-allowed client outside them.

[1] Add the allowed range and the rules. This is the test configuration minus test-only pid and log path lines. The proxy is 192.0.2.10; the allowed client, which is also the origin server, is 192.0.2.20.

/etc/squid/squid.conf
http_port 3128acl office src 192.0.2.20/32acl SSL_ports port 443acl Safe_ports port 80 443acl CONNECT method CONNECThttp_access deny !Safe_portshttp_access deny CONNECT !SSL_portshttp_access allow localhost managerhttp_access deny managerhttp_access allow localhosthttp_access deny to_localhosthttp_access deny to_linklocalhttp_access allow officehttp_access deny allcache deny allaccess_log stdio:/var/log/squid/access.log

The lines from deny !Safe_ports to deny to_linklocal are the recommended minimum configuration from the official http_access documentation. It notes that deny to_localhost and deny to_linklocal are unnecessary while only deny all follows them, but become critically important once you start allowing external requests below them. Without them, users in the allowed range could reach localhost services on the proxy server itself, or a cloud metadata address (169.254.169.254), through the proxy. localhost, manager, to_localhost and to_linklocal are predefined in Squid, so no acl lines were needed, and squid -k parse reported no errors.

For a real office range, write something like acl office src 192.0.2.0/24. If you use the packaged default configuration, these protection rules are already there; do not remove them. Add only the acl office line and http_access allow office right before the default http_access deny all (after the protection rules). cache deny all is only there to disable caching in the test.

[2] Back up the configuration, check the syntax and reload.

console
$ sudo cp -a /etc/squid/squid.conf /etc/squid/squid.conf.bak$ sudo squid -k parse$ sudo systemctl reload squid

[3] Send a request from the allowed range.

console
$ curl -s -o /dev/null -w 'HTTP %{http_code}\n' -x http://192.0.2.10:3128 http://192.0.2.20/HTTP 200

Even from the allowed range, requests caught by the protection rules must be refused. These target the proxy itself (127.0.0.1), a link-local address, and a CONNECT to a port other than 443:

console
$ curl -s -o /dev/null -w 'HTTP %{http_code}\n' -x http://192.0.2.10:3128 http://127.0.0.1/HTTP 403$ curl -s -o /dev/null -w 'HTTP %{http_code}\n' -x http://192.0.2.10:3128 http://169.254.169.254/HTTP 403$ curl -s -o /dev/null -p -w 'CONNECT %{http_connect}\n' -x http://192.0.2.10:3128 http://192.0.2.20/CONNECT 403

[4] Send a request from outside the allowed range. The response body is Squid's error page.

console
$ curl -s -o /dev/null -w 'HTTP %{http_code}\n' -x http://192.0.2.10:3128 http://192.0.2.20/HTTP 403$ curl -s -x http://192.0.2.10:3128 http://192.0.2.20/ | grep -o '<title>[^<]*</title>'<title>ERROR: The requested URL could not be retrieved</title>

[5] See who was blocked in access.log. The third column is the client address, the fourth the result.

output
1793078671.365      0 192.0.2.20 TCP_MISS/200 1214 GET http://192.0.2.20/ - HIER_DIRECT/192.0.2.20 text/html1793078671.447      0 192.0.2.20 TCP_DENIED/403 3386 GET http://127.0.0.1/ - HIER_NONE/- text/html1793078671.525      0 192.0.2.20 TCP_DENIED/403 3398 GET http://169.254.169.254/ - HIER_NONE/- text/html1793078671.605      0 192.0.2.20 TCP_DENIED/403 3378 CONNECT 192.0.2.20:80 - HIER_NONE/- text/html1793078671.617      0 203.0.113.7 TCP_DENIED/403 3388 GET http://192.0.2.20/ - HIER_NONE/- text/html1793078671.626      0 203.0.113.7 TCP_DENIED/403 3388 GET http://192.0.2.20/ - HIER_NONE/- text/html

HIER_NONE/- means Squid never contacted the origin. Requests from the allowed range (192.0.2.20) were refused too when they targeted the proxy itself, a link-local address or a non-443 CONNECT. To count only blocked addresses:

console
$ sudo awk '$4 ~ /TCP_DENIED/ {print $3}' /var/log/squid/access.log | sort | uniq -c | sort -rn

[6] Check the rule order. http_access lines are read top-down and the first match decides. With http_access deny all moved above allow office, the same test blocked the allowed range too:

output
1793078696.130      0 192.0.2.20 TCP_DENIED/403 3388 GET http://192.0.2.20/ - HIER_NONE/- text/html…1793078696.384      0 203.0.113.7 TCP_DENIED/403 3388 GET http://192.0.2.20/ - HIER_NONE/- text/html…
ConfigurationAllowed range → originAllowed range → 127.0.0.1, 169.254.169.254, CONNECT :80Others
protection rules → allow office → deny all200403403
protection rules → deny all → allow office403403403

The documentation says that if no http_access line matches, the opposite of the last line applies, and recommends ending with deny all for that reason. If the allowed range gets 403, first check that the allow line is not below deny all or another deny. If the target is the proxy itself or a link-local address, the 403 is intended.

[7] If the range is right but requests are still blocked, check which address Squid sees. When access.log's third column shows a NAT or load balancer address instead of the office address, acl src matches against that.

To undo, remove the two added lines (acl office and http_access allow office) or restore the backup from [2] (squid.conf.bak), then run squid -k parse and reload.

#squid#proxy#acl#http-access#ubuntu