Skip to content

fix(utils,crawler,cli): policy callers treat NAT64, 6to4, Teredo and other special-use literals as non-public #1560 - #1561

Closed
nc9 wants to merge 1 commit into
mainfrom
fix/non-public-policy-1560
Closed

nc9 wants to merge 1 commit into
mainfrom
fix/non-public-policy-1560

Conversation

@nc9

@nc9 nc9 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Closes #1560.

Decision: a wider function for the policy callers, the shared narrow function stays a grant

isNonPublicHostname (backed by isPrivateOrReservedHost) answers "is this a private-network host" and is used two ways. Callers that GRANT from it (allowPrivateNetwork: isNonPublicHostname(baseHost) in audit-engine/adapter.ts, the seed redirect's isNonPublicUrl(url), the TLS probe) would WIDEN a grant if the function widened: a start URL http://[64:ff9b::a00:1]/ would then count as "on the private network" and be allowed private-network egress, and the hosted engine would inherit that from its site host. So the shared function is not widened. The callers that DECIDE POLICY ask a different question (can a public visitor or a hosted service reach this?) and now read a wider one:

  • New isNonPublicHostnameForPolicy (packages/utils/src/non-public-host.ts) = isNonPublicHostname plus isSpecialUseIpLiteral (new packages/utils/src/special-use-ip.ts).
  • nonPublicHostLabel and isNonPublicUrl read it, so every caller of the label gets it: cloud handoff and render charge (audit/cloud.ts), publish and register gating (cli/commands/audit.ts, report.ts), the MCP billing note (mcp/billed-audit.ts), the rules runner's skipOnPrivateTarget gate, and a smart audit's not-applicable list (audit/smart-audits.ts, privateTargetRuleIds now exported for the test).
  • The default scheme of parseUserUrl (url.ts) reads it: a special-use literal has no public certificate, so it defaults to http://.
  • The grant keeps the narrow function: new privateNetworkHostLabel and isPrivateNetworkUrl (the old behaviour) are what seed-redirect.ts reads. The egress guards (public-egress.ts: vetEgressTarget, refusedWithoutLookup) are untouched and keep their own address logic; the adapter's allowPrivateNetwork lines and the TLS probe are untouched.

What counts as special-use (isSpecialUseIpLiteral, syntactic, no lookup, whatever IPv4 is embedded): IPv6 NAT64 64:ff9b::/96 and 64:ff9b:1::/48, 6to4 2002::/16, Teredo and the other IETF assignments 2001::/23, documentation 2001:db8::/32 and 3fff::/20, discard 100::/64, site-local fec0::/10, multicast ff00::/8, the deprecated IPv4-compatible ::/96, an IPv4-mapped or -translated address whose IPv4 is special-use, and an ISATAP identifier (::5efe:a.b.c.d) embedding one (plus the loopback, link-local and ULA ranges the narrow function already had); IPv4 0/8, 10/8, 100.64/10, 127/8, 169.254/16, 172.16/12, 192.168/16, 192.0.0.0/24, 192.0.2.0/24, 192.88.99.0/24, 198.18.0.0/15, 198.51.100.0/24, 203.0.113.0/24 and 224.0.0.0/4 upward. A public IPv4 or IPv6 literal (8.8.8.8, 2606:4700::1111, ::ffff:8.8.8.8, 2001:4860:4860::8888) stays public. This PR does not use #1547's isNonPublicHostnameStrict; it is its own helper, under a different name, so the two can land in either order and be reconciled (they should end up as one function).

Tests and fixtures changed

  • Changed fixture: packages/utils/tests/non-public-host.test.ts listed https://203.0.113.10/ as "a public literal IP"; it is documentation (TEST-NET-3), so it moved to the special-use list and the public literal there is now 93.184.216.34. No other test used a documentation address as a classifier input (integrity.test.ts, hotlinked-932, mixed-content use them as page content hosts; seed-base-collapse and tls-certificate only mention them).
  • New packages/utils/tests/special-use-ip.test.ts (86): 32 special IPv6 literals, 9 public ones, 20 special and 19 public IPv4, spellings (expanded, upper case, dotted tail, zone id), malformed input, and that the narrow classifier is unchanged while the policy one is wider.
  • Per caller, each failing first on e86767f: non-public-host.test.ts (labels for 18 special-use URLs, the narrow label does not name them, 96 tests); parse-user-url-local-scheme-812.test.ts (default scheme http for special-use literals, https for public ones); rules/tests/private-target-skip.test.ts (page and site rule gating for NAT64, 6to4, Teredo, site-local, documentation; a public literal still runs them; 9 fail on main); apps/cli/tests/audit/cloud-prefetch-non-public-base.test.ts (both cloud seams set hostUnreachableByCloud; a public literal does not; 10 fail on main); apps/cli/tests/lib/non-public-host.test.ts (12 forms: the label, publish and register decisions, a smart audit's skipped rules; a public literal publishes).
  • Pin for the grant, crawler/tests/start-redirect-resolver.test.ts: a NAT64, 6to4 or documentation start URL is not allowed private-network egress (the guard refuses it with no request) and a LAN start URL still is. It passes on main by design.
  • Mutants (each restored from a clean copy): each of the 23 special-use rules removed one at a time, the label made narrow (fails 9 runner tests and 10 cloud tests), the policy function without the narrow branch, the default scheme made narrow, the smart-audit list made narrow, and the seed redirect made strict each fail a test.
  • Egress guard and other consumers unchanged: public-egress (147), url (13), tls-certificate, seed-base-collapse and the callers' suites pass.

Not done

The hosted API classifier (classifyHostedEgressHost, private repo) mirrors this list entry for entry and should get the same wider verdict; that is a private PR. The AC's "docs state why they do not" part is the docs section below for the grant. Docs (docs/guides/local-audits-cli.mdx) and CHANGELOG updated. Skill change: none.

…other special-use literals as non-public; the grant stays narrow #1560

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Nov 2, 2026

Copy link
Copy Markdown

Reviewed the diff for the new classifier in special-use-ip.ts, non-public-host.ts, seed-redirect.ts and url.ts. I did not run the tests, so test coverage is unchecked.

I found no correctness or security problems. The grant/policy split matches the description. seed-redirect.ts stays on the narrow isPrivateNetworkUrl, so a NAT64 or 6to4 start URL gets no private-network egress. The egress guards are untouched.

  • (low) packages/utils/src/special-use-ip.ts:82 The comment says 64:ff9b:1::/48 is "treated alike", but the check matches first === 0x64 && second === 0xff9b. That covers all of 64:ff9b::/16, including 64:ff9b:1::/48. This is harmless, since the wider match fails safe, but say so in the comment.
  • (low) special-use-ip.ts:79 Any ::a.b.c.d (::/96) counts as special-use, including the compatible form with a public embedded IPv4. This is deliberate and documented. Please make sure the tests pin it.
  • (nit) special-use-ip.ts:74 Precedence in bytes[0]! << 8 | bytes[1]! is correct, but parentheses would match the style elsewhere. The long lines at 81 and 93 will also fail oxfmt if this file is checked.
  • (nit) ipv6Bytes re-implements IPv6 parsing even though isIP has already validated the input. That is fine, but consider a short comment explaining why URL normalisation can't be relied on here.

@nc9

nc9 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Shipped in v0.0.161. The commits were cherry-picked onto the release branch and rebase-merged: e83eb3b.

Closing this PR since the change is on main.

nik

@nc9 nc9 closed this Nov 4, 2026
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.

utils: isNonPublicHostname does not judge NAT64, 6to4, Teredo and other special-use IPv6 literals in policy callers

1 participant