Skip to content

fix(readurls): block CGNAT/shared-address and multicast ranges in SSRF guard - #336

Merged
codelion merged 1 commit into
algorithmicsuperintelligence:mainfrom
akushonkamen:fix/323-ssrf-hardening
Oct 10, 2026
Merged

codelion merged 1 commit into
algorithmicsuperintelligence:mainfrom
akushonkamen:fix/323-ssrf-hardening

Conversation

@akushonkamen

Copy link
Copy Markdown
Contributor

Summary

Fills two gaps in #334 (merged in 4088efc) in the readurls SSRF guard. The hardened guard is a strict superset of the previous blocklist (verified), so no previously-blocked address becomes reachable.

Gap 1 — CGNAT / shared address space was reachable. 100.64.0.0/10 (RFC 6598, including Tailscale's 100.100.100.100 and other CGNAT gateway services) was not on the blocklist and passed the old checks. The guard now rejects anything that is not ip.is_global or is multicast, instead of enumerating specific ranges — which also future-proofs it against other special-purpose ranges (RFC 1918/4193, loopback, link-local, documentation ranges, etc. remain covered via is_global).

Gap 2 — empty getaddrinfo results now fail closed. Previously, a resolver returning zero addresses could fall through and be treated as allowed; an empty result now raises and the request is refused.

Known limitation

DNS rebinding remains a TOCTOU risk: the host is checked via getaddrinfo before the fetch, but the underlying HTTP client performs its own resolution and may observe a different answer. This limitation is now documented in the README, which recommends egress filtering for high-security deployments. A complete fix requires a pinned-IP transport layer; happy to follow up if maintainers want it.

Testing

  • tests/test_readurls_ssrf.py: 22 passed (3 new cases covering CGNAT/shared ranges, multicast, and empty-resolution fail-closed behavior)
  • tests/test_ssl_config.py + tests/test_plugins.py: 40 passed (regression)

Refs #323.


Collaboration disclosure: This change was developed with AI assistance (human-reviewed).

- Switch the guard from a private-range deny-list to a global-routability
  allow-list (not is_global), which additionally blocks CGNAT/shared space
  (100.64.0.0/10, e.g. Tailscale) that is neither private nor global
- Keep an explicit multicast check (ipaddress marks globally-routable
  multicast ranges as is_global)
- Fail closed when resolution returns no addresses
- Document the residual DNS rebinding (TOCTOU) limitation in code and README
- Add 3 tests: CGNAT blocked, multicast blocked, empty resolution blocked
@codelion
codelion merged commit 045b33d into algorithmicsuperintelligence:main Oct 10, 2026
6 checks passed
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