Skip to content

Explicitly deny to_localnet requests in squid.conf.default - #2491

Draft
rousskov wants to merge 2 commits into
squid-cache:masterfrom
measurement-factory:SQUID-1177-deny-to-localnet
Draft

Explicitly deny to_localnet requests in squid.conf.default#2491
rousskov wants to merge 2 commits into
squid-cache:masterfrom
measurement-factory:SQUID-1177-deny-to-localnet

Conversation

@rousskov

Copy link
Copy Markdown
Contributor

This ban is not appropriate for some use cases, but our default
configuration template should prioritize safety over coverage breadth.
This work can be seen as a followup to 2022 commit 6d2f8ed.

The new to_localnet ban appears to use a more complex http_access rule
than existing to to_localhost and to_linklocal bans, but that
additional complexity is misleading: In fact, existing bans should be
interpreted in their http_access allow localhost context. In other
words, existing bans can be viewed as if they were written like this:

http_access deny !localhost to_localhost
http_access deny !localhost to_linklocal

Existing bans exclude localhost requests because a client running on
localhost can send banned requests directly to those protected services,
bypassing Squid. We use the same "do not ban access to what the clients
may be able to access without going through Squid" logic for the new
to_localnet rule, resulting in the localnet clients exclusion:

http_access deny !localnet to_localnet

Unlike the localhost case, we do not want to allow all localnet
clients by default. That caveat necessitates a different rule shape.

XXX: This duplicates "local" address range definitions.
TODO: Add "local", similar to existing "all", "ipv4" and "ipv6" aliases?

Also show how to allow internally-generated requests. Without that or
some other "allow" rule that matches internally-generated requests, our
configuration template bans all AIA requests, effectively disabling
fetching of missing intermediate X.509 certificates. AIA requests are
currently the only known use case of an internally-generated request not
associated with a client-to-Squid connection. Typical src-based
http_access allow rules cannot cover such requests.

This ban is not appropriate for some use cases, but our default
configuration template should prioritize safety over coverage breadth.
This work can be seen as a followup to 2022 commit 6d2f8ed.

The new `to_localnet` ban appears to use a more complex http_access rule
than existing to `to_localhost` and `to_linklocal bans`, but that
additional complexity is misleading: In fact, existing bans should be
interpreted in their `http_access allow localhost` context. In other
words, existing bans can be viewed as if they were written like this:

    http_access deny !localhost to_localhost
    http_access deny !localhost to_linklocal

Existing bans exclude localhost requests because a client running on
localhost can send banned requests directly to those protected services,
bypassing Squid. We use the same "do not ban access to what the clients
may be able to access without going through Squid" logic for the new
`to_localnet` rule, resulting in the `localnet` clients exclusion:

    http_access deny !localnet to_localnet

Unlike the `localhost` case, we do not want to allow all `localnet`
clients by default. That caveat necessitates a different rule shape.

XXX: This duplicates "local" address range definitions.
TODO: Add "local", similar to existing "all", "ipv4" and "ipv6" aliases?

Also show how to allow internally-generated requests. Without that or
some other "allow" rule that matches internally-generated requests, our
configuration template bans all AIA requests, effectively disabling
fetching of missing intermediate X.509 certificates. AIA requests are
currently the only known use case of an internally-generated request not
associated with a client-to-Squid connection. Typical src-based
`http_access allow` rules cannot cover such requests.

@rousskov rousskov left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am marking this PR as a draft because I want to discuss two changes that may necessitate significant PR changes. Please see specific change requests for details.

Comment thread src/cf.data.pre
# Adapt to list your (internal) IP networks.
# It is common to deny access to these addresses, but your needs may vary.
acl to_localnet dst 0.0.0.1-0.255.255.255 # RFC 1122 "this" network (LAN)
acl to_localnet dst 10.0.0.0/8 # RFC 1918 local private network (LAN)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description:

XXX: This duplicates "local" address range definitions.
TODO: Add "local", similar to existing "all", "ipv4" and "ipv6" aliases?

These duplication problems and the elevated difficulty of addressing them were the reasons these changes were explicitly excluded from our earlier related work in #1161. Assuming we are still in agreement regarding this overall direction, we have two primary options here:

  1. Merge this PR with/despite this duplication of localnet address ranges. Follow up with a PR that adds a "local" alias, similar to existing "all", "ipv4" and "ipv6" aliases? That followup PR should also document "all", "ipv4", and "ipv6" aliases, I guess. Adding support for a "local" alias will not be trivial because existing alias-handling code cannot handle multiple distinct address ranges.
  2. Do the opposite: Post a PR that adds a "local" alias first. Then update this PR to use that alias to define to_localnet.

What is your preference? CC: @kinkie, @yadij.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I think we should make to_linklocal a pre-define, unlike localnet the admin does not need to remove entries. They shoudl make a different ACL and allow X instead.

Possibly with small sub-defines for the ipv4_linklocal, ipv6_linklocal, ipv4_cgn, rfc1918, rfc1122, etc

@yadij yadij Sep 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "broadcast" ranges should also be prohibited as part of to_localnet. These are not relevant to the received (from-localnet), but can be for the outgoing to_localnet traffic.

For pre-define that would be ipv4_broadcast (255.255.255.255) and ipv6_broadcast (FFFF:...).

Comment thread src/cf.data.pre
Comment on lines +2016 to +2017
# acl internallyGenerated transaction_initiator internal
# http_access allow internallyGenerated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule addition can be moved into a dedicated followup PR. AIA issues were the last straw that triggered creation of this long anticipated PR, and adding this AIA rule affects other comments in this section, so merging this work into this PR is borderline OK IMO, but please let me know if I should separate the two changes/concerns.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay with me, though it does seem to expand the scope. So title should be something more like "Improve default http_access security policy"

Comment thread src/cf.data.pre

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
# INSERT YOUR OWN RULE(S) HERE TO ALLOW PERMITTED TRANSACTIONS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted this line because Squid-generated transactions, like those AIA requests, are not "FROM YOUR CLIENTS".

I also wanted to de-emphasize the "from" aspect of access control. These rules are also about "to" or "destination" controls, even though our examples do not illustrate that concern directly.

This comment annotates changes without requesting any discussion affecting this PR "draft" status.

* `foo` quotes code or configuration
* "bar" uses quotes for standard English language purposes

@yadij yadij left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole issue smells like overriding admin misconfiguration to me.

FTR; The default policy is currently to block always-dangerous, allow only admin allowed traffic, then to block *all (including to-LAN traffic).

To do this properly without breaking admin rules - the deny to_localnet should ideally come after admin preferences so they can allow local servers through, but then it is redundant with deny all.

Comment thread src/cf.data.pre

# For example, to allow access from your local networks, you may uncomment the
# following rule (and/or add rules that match your definition of "local"):
# Uncomment to allow access from "local" networks to any destination that was

@yadij yadij Sep 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Uncomment to allow access from "local" networks to any destination that was
# Uncomment to allow access from local network (LAN) to any destination that was

Comment thread src/cf.data.pre
# missing intermediate X.509 certificates) to any destination that was not
# banned earlier (e.g., all `to_localnet` destinations were banned for such
# requests).
# acl internallyGenerated transaction_initiator internal

@yadij yadij Sep 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this can be a pre-define. Which would allow adding AIA as an exception to the proposed deny ... to_locanet addition earlier.

Comment thread src/cf.data.pre
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
# Define what "from your local network" means.
# Adapt to list your (internal) IP networks.

@yadij yadij Sep 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are editing these lines please fix the long-standing documentation issue that we did not use the well-known LAN term in this text.

Suggested change
# Adapt to list your (internal) IP networks.
# Adapt to list your (internal) IP networks (LAN).

Comment thread src/cf.data.pre
# Protect services running inside your "local" networks. These services often
# assume that only "local" users can access them. This rule also denies
# internally-generated AIA requests for missing intermediate X.509
# certificates when those requests target "local" services.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule is a bit dangerous and slightly non-intuitive due to the ! usage.

Suggested change
# certificates when those requests target "local" services.
# Protect services running inside your local network (LAN). These services often
# assume that only LAN users can access them. This rule also denies
# internally-generated AIA requests for missing intermediate X.509
# certificates when those requests target LAN services.

or if internallyGenerated becomes a pre-define:

Suggested change
# certificates when those requests target "local" services.
# Protect services running inside your local network (LAN). These services often
# assume that only LAN users can access them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants