Skip to content

network: normalize allowlist paths and block unspecified/CGNAT ranges - #853

Merged
ewhauser merged 2 commits into
mainfrom
network/fix-allowlist-dot-segments-private-ranges
Oct 19, 2026
Merged

ewhauser merged 2 commits into
mainfrom
network/fix-allowlist-dot-segments-private-ranges

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Fixes two sandbox network-policy bypasses in network/network.go.

1. Allowlist path-prefix bypass via dot segments

urlAllowed / allowListPathMatches compared EscapedPath() as a raw prefix, and the original unnormalized URL was sent. With AllowedURLPrefixes=["https://api.example.com/v1/"], https://api.example.com/v1/../admin (or %2e%2e variants) passed the check and went out unnormalized, so the server resolved it to /admin.

Now:

  • RFC 3986 remove_dot_segments runs on the escaped path before matching, and the normalized *url.URL that was checked is the one assigned to the outgoing http.Request (/v1/a/../b is checked and sent as /v1/b; Response.URL reports the normalized URL).
  • Paths that would still hold a ./.. segment after a server percent-decodes (%2e%2e, .%2e), splits on encoded or backslash separators (..%2f, ..%5c, ..\), or strips ; path params (..;, the Tomcat-style trick) are denied rather than normalized.
  • Allowlist prefixes get the same normalization. A prefix with an encoded dot segment is an invalid config.
  • Redirect targets go through the same check, so Location: /v1/%2e%2e/admin now returns RedirectNotAllowedError.

2. isPrivateIP gaps

It missed unspecified addresses (0.0.0.0, ::), which connect to localhost on Linux and macOS, plus CGNAT 100.64.0.0/10 and other non-public ranges. It now uses net/netip and covers:

  • unspecified, 0.0.0.0/8
  • loopback, private, link-local, multicast
  • 100.64.0.0/10, 192.0.0.0/24, TEST-NETs, 198.18.0.0/15, 240.0.0.0/4
  • ::/96, ::ffff:0:0:0/96, 64:ff9b:1::/48, 100::/64, 2001:db8::/32, fec0::/10
  • NAT64 64:ff9b::/96 and 6to4 2002::/16 when the embedded IPv4 address is non-public

IPv4-mapped addresses are classified by their IPv4 form. Both the preflight checkPrivateHost (lexical and DNS-resolved) and the dial-time dialContext checks use it. Literal-IP detection in the preflight now uses netip.ParseAddr, which also handles zoned IPv6 literals.

Behavior note: with DenyPrivateRanges, hosts that resolve into 198.18.0.0/15 are now blocked. This includes the "fake-IP" DNS mode used by some local proxies (Clash, Surge).

SPEC

Updated the network policy section in SPEC.md (§12) to describe path normalization and ambiguous-segment denial, and to list the full set of blocked ranges.

Testing

New regression tests in network/network_test.go use the WithDoer/WithResolver fakes plus a recording doer that checks what is actually sent:

  • dot-segment escapes are denied, both direct and through redirects
  • benign dot segments are normalized before sending
  • allowlist prefixes are normalized
  • an isPrivateIP table
  • 0.0.0.0, :: and 100.64.0.1 are blocked lexically, after DNS, and at dial time

All of these failed before the fix and pass after it.

  • go test ./network/... ./internal/builtins/... ./internal/runtime/... passes (with the pinned diff/ripgrep oracles).
  • A 20s run of FuzzHTTPClientPolicy passes.
  • make lint reports 0 issues.

Apply RFC 3986 remove_dot_segments before allowlist matching and send
the normalized URL, denying paths that still decode to dot segments
(%2e%2e, ..%2f, ..%5c, ..\, ..;). Redirect targets get the same check.

Extend DenyPrivateRanges to unspecified addresses (0.0.0.0/8, ::),
shared/CGNAT 100.64.0.0/10, multicast, other IANA non-public ranges,
and NAT64/6to4 addresses embedding a non-public IPv4 destination, for
both the preflight and dial-time checks.
@ewhauser
ewhauser enabled auto-merge (squash) October 19, 2026 03:42
@ewhauser
ewhauser merged commit eb8c6cd into main Oct 19, 2026
16 checks passed
@ewhauser
ewhauser deleted the network/fix-allowlist-dot-segments-private-ranges branch October 19, 2026 06:21
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.

1 participant