Repository navigation
Description
Problem
Lines cited at dcafadf.
At 132ecc5, ai/mcp/server.py:2895-2896 is at :2918-2919, and config/constants.py:2296-2299 and :2505 are at :2297-2300 and :2539; no other cited line moved.
Every "today" result below was measured offline at dcafadf, in a network namespace with no network (Python 3.14.7, glibc 2.43, httpx2 2.13.0, pydantic-ai 2.35.0).
The egress guards answer IP questions with string prefixes, literal host sets and hand canonicalisation. Their metadata check misses spellings and provider addresses that the client still dials. The NAT64 gap (found in #860's review) was first filed here. The Azure WireServer gap was filed as #989. This rewrite covers both, along with the rest of the same construct family.
Confirmed holes
- Numeric metadata spellings pass the metadata check.
validate_url(u, allow_private=True)allowshttp://2852039166/,http://0xa9fea9fe/,http://0xa9.0xfe.0xa9.0xfe/andhttp://169。254。169。254/. glibc dials the first three as 169.254.169.254, and httpx2 reads the fourth as 169.254.169.254. The broker's own hook (http/broker.py:53-64, viavalidate_service_url) runs this check whenever private networks are allowed. - NAT64 and IPv4-compatible wrappers count as public.
is_non_public_ip(core/validation.py:108-117) isnot addr.is_global. Python 3.14 reports64:ff9b::/96(RFC 6052) and::/96(RFC 4291) as global, sovalidate_url_egress(u, purpose="web_fetch", allow_private=False)allowshttp://[64:ff9b::a9fe:a9fe]/,http://[64:ff9b::7f00:1]/andhttp://[::127.0.0.1]/. The web_fetch per-hop veto (_validate_fetch_hop,ai/common_tools.py:340-354) therefore sends them. On a NAT64/DNS64 network, including one with a host CLAT, the first reaches the metadata service.- The stdlib already unwraps IPv4-mapped addresses (
ip_address("::ffff:169.254.169.254").is_link_localis True). - It already treats
64:ff9b:1::/48, 6to4 and Teredo as non-global. - Under
allow_private=True, however,http://[64:ff9b::a9fe:a9fe]/,http://[64:ff9b:1::a9fe:a9fe]/andhttp://[2002:a9fe:a9fe::1]/all pass the metadata check.
- The stdlib already unwraps IPv4-mapped addresses (
- Azure WireServer (fix(security): ssrf guards admit azure's wireserver metadata address 168.63.129.16 #989). 168.63.129.16 is a public address that every Azure VM can reach, and it serves instance metadata and the guest agent. No list here contains it:
- web_fetch's check allows it as public;
validate_configured_service_urlallows it with or withoutallow_private;- a sandbox
public_whitelistentry of168.63.129.16or168.63.0.0/16is emitted as an ipBlock; - a name whose DNS answer is 168.63.129.16 passes
validate_url_egressandvalidate_urlunder bothallow_privatevalues. This item checks that answer where the guards already resolve the name, which is underallow_private=False. Underallow_private=Trueneither guard resolves the name, and the answer is fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898's connect-time check.
validate_url_egresshas no metadata check underallow_private=True. The whole check is theif not allow_private:block (validation.py:208-226). It allowshttp://169.254.169.254/,http://[fd00:ec2::254]/andhttp://metadata.google.internal/. Callers:k8s/service_http.py:63,k8s/logql.py:352,ai/pool_load.py:45.- Missing provider entries:
fd00:ec2::23(AWS EKS Pod Identity),fd20:ce::254(GCP, IPv6-only instances) andmetadata.goog. GCP documentsmetadata.goognext tometadata.google.internal(docs.cloud.google.com/compute/docs/metadata/querying-metadata). All three passvalidate_url(allow_private=True)today.
The hand-rolled constructs behind these holes
- Prefix tests:
startswith("169.254.")atvalidation.py:80,:86,:93and:103. A fifth copy,telemetry/waterfall.py:114, goes with fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898. - String sets:
_LOOPBACK_AND_LOCAL_HOSTS(validation.py:42-44), used at:157and:216;CONST_CLOUD_METADATA_HOSTSandCONST_CLOUD_METADATA_IPS(config/constants.py:2296-2299);CONST_LOCAL_HOSTNAMES(constants.py:2505), read atai/spend/pricing.py:91andcommands/k8s/networking.py:267,:296,:423and:440-441;- loopback literals at
networking.py:328,ai/mcp/server.py:2895-2896andsandbox/metrics.py:398(loopback hosts there skip the egress check at:410-411).
- Hand canonicalisation:
.strip().lower().strip("[]").rstrip(".")atvalidation.py:83,:154and:330. - CIDRs built as text.
cloudflare/client.py:164-174buildsf"{clean}/32"(:170). It keeps2001:DB8::1as typed and accepts a zone id (fe80::1%eth0/128). - Exception text as control flow:
sandbox/models.py:182and:225. - A wrong host-gateway mapping.
sandbox/models.py:213-214mapshost.docker.internal(andlocalhost) to127.0.0.1/32, and:129-132accepts both names in the local whitelist.- The host gateway is not the pod's loopback.
- A
127.0.0.1/32ipBlock does nothing, because NetworkPolicy never polices pod loopback. - Resolving the name on the workstation is no fix either: in a rootless Podman container,
/etc/hostsmaps it to 169.254.1.2, a link-local address the metadata guard refuses.
- RFC tables:
security/reference_extractor.py:74-102, checked at:134-156and:230-260.
Pitfalls the replacement must avoid (measured)
is_link_localalone is looser for networks.ip_network("169.254.0.0/15").is_link_localis False. Today only the string prefix refuses that network as a sandboxpublic_whitelistentry. A bareis_link_localswap would emit an ipBlock that covers the metadata service.- pydantic does not report the host httpx2 dials. For
http://example.com\@169.254.169.254/, pydanticAnyHttpUrl.hostisexample.com, whilehttpx2.URL(...).hostis169.254.169.254, the address the request goes to. urllib agrees with httpx2, so today's guard refuses this URL; a pydantic-based guard would admit it. is_globaldoes not implynot is_reservedornot is_multicast.64:ff9b::a00:1(the NAT64 form of an RFC 1918 address) and4000::1are global and reserved, and224.0.0.1is global and multicast.is_public_ipgates Shodan InternetDB lookups (security/vulnerability_lookup.py:315,ai/tools/builtin_tools.py:460). Dropping those terms would send wrapped internal addresses to a third party.
Dropped from this issue's earlier proposal: the hand-written embedded_ipv4 helper and the constants-held CONST_IPV4_EMBEDDING_IPV6_PREFIXES set. pydantic-ai is already pinned, and its maintained classifier decodes the NAT64 (both prefixes), IPv4-compatible, 6to4, Teredo and ISATAP forms, so a local copy would be one more of the constructs this item removes. The earlier body cited AGENTS.md:21-24 as permission for that set; #1107 rewrites those lines.
Replacement: library per construct
- Host text comes from the parser of the client that sends:
- for URLs,
httpx2.URL(url).host; httpx2 2.13.0 is a direct dependency (pyproject.toml:19); - for bare host strings (the MCP bind host, sandbox whitelist entries), the order of parsing is fixed:
- first
ipaddress.ip_address(h), so a single address keeps the address predicates; - then
ipaddress.ip_network(h, strict=False); a string that parses is a network and is classified by key question 3; - only what is left goes through
httpx2.URL(scheme="http", host=h).host, thenip_address, thengetaddrinfo(AI_NUMERICHOST), thendns.name.
- first
- Why networks come before httpx2: sandbox entries are often CIDRs, and
_validate_public_whitelist_itempasses CIDR text such as169.254.0.0/15to the predicates today. Measured:httpx2.URL(scheme="http", host="169.254.0.0/15").hostis169.254.0.0%2F15, which is neither anip_addressnor anAI_NUMERICHOSTliteral. It would be compared as a name, the metadata predicate would answer False, and168.63.0.0/16would be refused by nothing. - Both httpx2 forms strip brackets, lowercase, and map ideographic dots. Neither is pydantic (see the pitfalls above).
- for URLs,
- Addresses:
ipaddress.ip_address(host). If that fails, usesocket.getaddrinfo(host, None, flags=socket.AI_NUMERICHOST). That call never queries DNS, and it returns the address glibc dials for2852039166,0xa9fea9fe,0251.0376.0251.0376and127.1. Asocket.gaierrormeans the host is a name. - Names:
localhostand the metadata names are compared withdns.name.from_text()equality, which handles case and the trailing dot.- Host text that
dns.name.from_text()rejects with adns.exception.DNSExceptionis not a DNS name. httpx2 accepts some of it; measured:a..braisesEmptyLabel, and a 64-character label raisesLabelTooLong. The loopback predicate answers False for such text (no loopback exemption), andvalidate_urlandvalidate_url_egressrefuse it as an invalid host, so it never reaches a name comparison. Both URL checks allow it today underallow_private=True(measured). - Declare
dnspython==2.8.0directly. It is already locked via email-validator, it is ISC-licensed, and its repository is active (commits on 2026-10-03). - The metadata names (
metadata,metadata.google.internal,metadata.goog) are published by the cloud vendor, and no maintained library lists them. They stay one constant ofdns.name.Nameobjects, with the source cited.
- Classification uses the stdlib
is_loopback,is_link_local,is_global,is_reserved,is_multicastandis_unspecified, plus the classifier from key question 1:- Metadata means
is_link_local, or the classifier's metadata test, or a metadata name. - Non-public means
not is_global, or the classifier's private test. This combination only ever tightens today's result. - Networks follow key question 3.
- Metadata means
validate_url_egressandvalidate_url:- Both parse with httpx2.
- Both run the metadata predicate on the host before the
allow_privatebranch. - Every DNS answer they already resolve is checked against both predicates, so no new lookup is added.
- One loopback predicate, today's
_is_loopback_host(validation.py:328-336) rebuilt on the above, replaces:- the MCP bind set (
server.py:2895-2896); networking.py:267,:296,:328and:440-441;pricing.py:91;sandbox/metrics.py:398-411.
- the MCP bind set (
- Cloudflare:
ipaddress.ip_network(clean, strict=False).with_prefixlen, refusing any address with ascope_id. Every run already sends the full policy payload:create_or_update_access_policyPUTs when a policy of that name exists (client.py:731-738) and POSTs a new one otherwise (:739-744). Canonical text therefore adds no extra step. - sandbox/models.py: parse inside the
tryand classify after it, so no branch readsstr(exc). - reference_extractor: key question 4.
Delivery: two PRs.
- PR1: predicates, constants, consumers and the conftest change.
- PR2: the reference_extractor reclassification and the sandbox host-gateway change. Both need owner decisions on output and behaviour. PR2 lands after fix(security): network references come from url and ip syntax, not identifier-prefix and property-suffix lists #431, which edits
reference_extractor.py.
Acceptance criteria
- Old-vs-new table test (offline, parametrised,
DEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORKunset; "today" measured at dcafadf):
| Input | Call | Today | After |
|---|---|---|---|
http://2852039166/, http://0xa9fea9fe/, http://0xa9.0xfe.0xa9.0xfe/, http://169。254。169。254/ |
validate_url(allow_private=True) |
allowed | refused (metadata) |
http://[64:ff9b::a9fe:a9fe]/, http://[64:ff9b:1::a9fe:a9fe]/, http://[2002:a9fe:a9fe::1]/ |
validate_url(allow_private=True) |
allowed | refused (metadata) |
http://168.63.129.16/, http://[fd20:ce::254]/, http://[fd00:ec2::23]/, http://metadata.goog./ |
validate_url(allow_private=True) and validate_configured_service_url(allow_private=True) |
allowed | refused (metadata) |
http://168.63.129.16/ |
validate_configured_service_url() (default allow_private=False) |
allowed | refused (metadata) |
http://example.com\@169.254.169.254/ |
validate_url(allow_private=True) |
refused | refused |
http://a..b/, and a URL whose first label is 64 characters ("x" * 64 + ".example.com"; the subdomain length is the point of this row) |
validate_url(allow_private=True) and validate_url_egress(allow_private=True) |
allowed | refused (invalid host) |
http://169.254.169.254/, http://[fd00:ec2::254]/, http://metadata.google.internal/ |
validate_url_egress(allow_private=True) |
allowed | refused |
http://[64:ff9b::a9fe:a9fe]/, http://[64:ff9b::7f00:1]/, http://[::127.0.0.1]/, http://168.63.129.16/ |
validate_url_egress(purpose="web_fetch", allow_private=False) |
allowed | refused |
http://example.com/ with getaddrinfo patched to answer 168.63.129.16 |
validate_url_egress and validate_url, allow_private=False |
allowed | refused |
http://[64:ff9b::808:808]/, http://8.8.8.8/ |
validate_url_egress(allow_private=False) |
allowed | allowed |
host 127.0.0.2, ::ffff:127.0.0.1, LOCALHOST. |
run_mcp_server(transport="sse") |
refused as non-loopback | binds |
existing http://192.0.2.10:3000, detected http://127.0.0.2:3000 |
_should_update_url |
overwrites | keeps the existing URL |
169.254.0.0/15 |
sandbox public_whitelist |
refused | refused (via overlaps) |
168.63.129.16, 168.63.0.0/16 |
sandbox public_whitelist |
ipBlock emitted | refused |
0.0.0.0/0, ::/0, 128.0.0.0/1, 160.0.0.0/4 |
sandbox public_whitelist |
ipBlock emitted | refused (overlaps link-local) |
8.0.0.0/5 |
sandbox public_whitelist |
ipBlock emitted | ipBlock emitted (stays with #702) |
2001:DB8::1 / fe80::1%eth0/128 |
Cloudflare bypass IPs | 2001:DB8::1/128 / accepted |
2001:db8::1/128 / refused |
- Classifier rows.
test_is_non_public_ip(tests/test_validation.py:27-38) keeps its tuple-equality form.- These become non-public; each is public today:
64:ff9b::a9fe:a9fe,64:ff9b::7f00:1,::127.0.0.1,64:ff9b::a9fe:0/112,64:ff9b::/96and64:ff9b::/95. - These stay public:
64:ff9b::808:808,64:ff9b::808:0/112and::ffff:8.8.8.8. - These stay non-public:
64:ff9b:1::808:808,2002:a9fe:a9fe::,2001:0:a9fe:a9fe::,::and::1.
- These become non-public; each is public today:
- Metadata predicate.
test_is_cloud_metadata_host_superset(tests/test_validation.py:412-448):- gains
64:ff9b::a9fe:a9fe(as a string and asipaddress.ip_address),2852039166,168.63.129.16,fd20:ce::254andmetadata.goog, all True; - gains
64:ff9b::808:808, False; - keeps its bracketed and trailing-dot rows True.
- gains
- web_fetch never sends these hops.
test_web_fetch_tool_never_requests_a_private_redirect_hop(tests/test_common_tools.py:95-114) gains anat64-metadatahop (http://[64:ff9b::a9fe:a9fe]/latest/meta-data/) and awireserverhop (http://168.63.129.16/machine?comp=goalstate). For each, onlyhttps://example.com/startis requested and the result has no# Final. - The broker keeps its own veto.
test_http_broker_keeps_its_own_veto_under_a_request_egress_policy(tests/test_http_broker.py:171-187) is parametrised over_LINK_LOCALand the NAT64 metadata hop, underHttpClientBroker(allow_private_networks=True)andDEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORK=true.client.sendraisesSSRFBlockedError, andstub_web.requested == [_START]. - Sandbox oracle.
_METADATA_ORACLE_TARGETS(tests/test_sandbox_policy_properties.py:254-266) gains2852039166,0xa9fea9fe,64:ff9b::a9fe:a9fe,168.63.129.16,fd20:ce::254andmetadata.goog.:269-315passes for each target, andtest_property_resolve_hosts_emit_correct_prefix_lengths(:180) keeps passing. - Contract test for the classifier. One test drives the classifier rows above through the single import site of key question 1, and asserts that the link-local networks read there are exactly
169.254.0.0/16andfe80::/10. If a pydantic-ai bump moves or changes the classifier, the test fails by name. - Test DNS guard. The guard (
tests/conftest.py:125-133) passesgetaddrinfocalls that carryAI_NUMERICHOST, whether the flags come positionally or by keyword. It still refuses every other non-literal lookup, and a test covers both cases. - Valkey guard. A first test for
_should_update_valkeyshows that, withvalkey.urlunset, an existing remotevalkey.hostofexample.comis kept when the detected URL's host is127.0.0.2; today it is overwritten (measured). Withvalkey.urlset toredis://example.com:6379,_should_update_urlalready returns False today and the entry is kept, so that case is not the regression row. Thesplit(":")[0]host read (networking.py:436) and the writer at:486-490are left to fix(valkey): one validated URL names every Valkey endpoint, valkey-py dials an address that one check vetted, and the unused cache layer goes #1113. - No construct left:
rg -n 'startswith\("169\.254\.|strip\("\[\]"\)|_LOOPBACK_AND_LOCAL_HOSTS|_ALLOWED_LOCAL_HOSTS|CONST_LOCAL_HOSTNAMES|CONST_CLOUD_METADATA_(HOSTS|IPS)' srcprints onlytelemetry/waterfall.py:114,:130,sandbox/probe.py:57andsandbox/models.py:82. fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 and fix(security): URL and host:port reads use the sending client's parser, so key trust, crawls, probes and settings act on the host actually dialled #1112 remove those.rg -n '"(localhost|127\.0\.0\.1|::1)", "(localhost|127\.0\.0\.1|::1)"' src/devops_cli/core src/devops_cli/config/constants.py src/devops_cli/commands/k8s/networking.py src/devops_cli/ai/mcp/server.py src/devops_cli/ai/spend/pricing.py src/devops_cli/sandbox/metrics.pyprints nothing.rg -n 'in str\(exc\)' src/devops_cli/sandbox/models.pyprints nothing after PR1.rg -n -g '*.py' 'ff9b|168\.63\.129\.16|fd20:ce|169\.254\.0\.0/16|fe80::/10' srcprints nothing.- Once feat(ci): hand-rolled URL and address parsing fails
devops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107 has landed, nonet-ip-literal,net-address-list,net-normalise,net-cidr-buildornet-scheme-affixmarker is left in this item's files, and the suppression ceiling is lowered by the count removed.
- Tests updated:
- tests/test_validation.py:
:83-84,:234-260and:290-302; - tests/test_cloudflare_commands.py:638-653;
- tests/test_mcp.py:138-143;
- tests/test_k8s_networking.py (the
_should_update_urlrows); - PR2: tests/test_sandbox_networking.py:174-197 and tests/test_reference_extractor.py:1019-1031 and
:1093.
- tests/test_validation.py:
- Offline. Every address above is a literal or a patched
getaddrinfoanswer. Redirect tests answer from thestub_webfixture (tests/conftest.py:190), and no test makes an unpatched non-numeric lookup. - Release.
uv run devops cipasses within the 5-minute budget.- A
changelog.d/897.mdfragment names:- the newly refused metadata spellings and provider addresses;
- sandbox
public_whitelistCIDRs that overlap link-local space (0.0.0.0/0,::/0,128.0.0.0/1,160.0.0.0/4) or hold a metadata address (168.63.0.0/16), which are now refused instead of emitted as ipBlocks; - host text that is not a valid DNS name (
a..b) refused as an invalid host; - the MCP bind accepting any loopback form;
- Cloudflare's canonical CIDR output.
- CHANGELOG.md and docs/ROADMAP.md are not edited.
- Pending a person: ask pydantic/pydantic-ai upstream to export
is_cloud_metadata_ip,is_private_ipand the metadata address sets from a public module.
Key questions
- Where does the metadata and IPv6-wrapper classification come from?
- Decided (owner, 2026-10-03): fixes use reputable libraries and tools, never new hand-rolled parsers, prefix tests, regex validators or literal address sets. That rules out decoding the IPv6 wrappers here and keeping a local list of provider addresses.
- Proposed: pydantic-ai's
pydantic_ai._ssrf.is_cloud_metadata_ipandis_private_ip, imported at one site incore/validation.py. - Why this classifier:
- pydantic-ai is a direct, exact-pinned dependency (pyproject.toml:37, 2.35.0), maintained by the Pydantic team, and both functions are on upstream main.
- Measured offline:
is_cloud_metadata_ipflags64:ff9b::a9fe:a9fe,64:ff9b:1::a9fe:a9fe,2002:a9fe:a9fe::1,::a9fe:a9fe, the Teredo form2001::5601:5601,fd20:ce::254and168.63.129.16.is_private_ipflags64:ff9b::7f00:1and::127.0.0.1. Both keep8.8.8.8and64:ff9b::808:808public. - Its metadata list (169.254.169.254, 169.254.170.2, 169.254.170.23, 168.63.129.16, 100.100.100.200, 192.0.0.192, 169.254.42.42, fd00:ec2::254, fd00:ec2::23, fd20:ce::254, fd00:42::42) settles fix(security): ssrf guards admit azure's wireserver metadata address 168.63.129.16 #989's comparison criterion without a local list.
- Networks: key question 3 reads the same module's
_CLOUD_METADATA_IPV4,_CLOUD_METADATA_IPV6and_PRIVATE_NETWORKS, from the same import site. - Cost: the module is private (
__all__ = ['safe_download']). Mitigations:- the exact pin, so a pydantic-ai bump is a deliberate change that runs the contract test;
- one import site;
- the contract test;
- the upstream export request (Pending a person, above).
- If a bump moves or changes the classifier: the contract test fails by name, and the pin stays until the upstream export is available. Hand-written decoding or a local address list is not the fallback, under the decided rule above.
- Which parser supplies the host? Proposed: httpx2.URL, the client that sends, never pydantic (the backslash case above). A bare host string is tried as an
ipaddressaddress, then as anipaddressnetwork; only what is neither goes throughhttpx2.URL(scheme="http", host=h)(see "Host text" above). - How are networks classified? Proposed: a network is metadata if it overlaps a link-local network or contains a metadata address. A network is non-public if
not net.is_global, or if either end address is non-public under the address predicate.- Why a network rule of its own: the classifier functions take one address.
- The link-local networks are read, not written: they are the members of pydantic-ai's
_PRIVATE_NETWORKSwhoseis_link_localis True, taken at key question 1's import site. Measured on 2.35.0:169.254.0.0/16andfe80::/10, the RFC 3927 and RFC 4291 ranges. The stdlib holds the same two ranges only in its private_constants. - The end rule satisfies the
64:ff9b::a9fe:0/112,64:ff9b::/95and64:ff9b::808:0/112rows. - The overlap rule changes four sandbox
public_whitelistresults.0.0.0.0/0,::/0,128.0.0.0/1and160.0.0.0/4each overlap link-local space, so they become refused; all four are emitted as ipBlocks today (measured).0.0.0.0/0,::/0and128.0.0.0/1also fail the end rule (0.0.0.0,255.255.255.255and::are non-public), and160.0.0.0/4is refused by the overlap alone. - A range whose ends are both public, that does not overlap link-local space and that holds no metadata address, but that contains private space, stays feat(telemetry): sandbox egress port scoping, collector lane & in-container trace context #702's. Example:
8.0.0.0/5, which holds an RFC 1918 block and is still emitted after this item.
- What about reference_extractor's classification shift? (owner decision; PR2) Proposed:
- Accept the stdlib classes, keeping
not is_reservedandnot is_multicastinis_public_ip. - Keep one closed constant of
ip_networkobjects for the documentation and benchmarking ranges (RFC 5737, RFC 3849, RFC 9637, RFC 2544, RFC 5180), with the RFCs cited. The stdlib folds these ranges intois_private, and no library tells a documentation address from an RFC 1918 one. This is the one address constant the item would keep, so it is weighed against the rule decided in key question 1. - What shifts: without the tables, 0.0.0.0/8, 100.64/10, 192.0.0/24, 198.18/15, 240/4, 255.255.255.255, 100::/64, 2002::/16 and parts of 2001::/23 change report class. The RFC list in the message at
ai/tools/builtin_tools.py:456changes with them.
- Accept the stdlib classes, keeping
- What happens to
host.docker.internalandlocalhostin the local whitelist? (owner decision; PR2) Proposed:- Refuse
host.docker.internalwith a message asking for an IP or CIDR. localhostemits no ipBlock, because pod loopback is never policed.- No DNS lookup is added to the policy builder.
- Refuse
- Does fix(security): ssrf guards admit azure's wireserver metadata address 168.63.129.16 #989 close? Yes: it is closed as merged into this item (consolidation, 2026-10-03). Its cases are rows of the table above, and its comparison criterion is met by key question 1's classifier.
Strategic alignment
- Priority P1. It closes confirmed metadata bypasses on every guarded path: the broker hook, web_fetch, the
allow_privatecallers and sandbox policies. Its predicates are consumed by:- fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 (connect-time check);
- fix(security): local names come from the public suffix list, and domains match on DNS labels, not string suffixes #887 (local names);
- fix(security): URL credential masking uses urllib and httpx2, so passwords containing '@' and non-http schemes are masked and IPv6 hosts stay intact #1109 (telemetry endpoint masking);
- fix(valkey): one validated URL names every Valkey endpoint, valkey-py dials an address that one check vetted, and the unused cache layer goes #1113 (Valkey peer check).
- Proposed milestone: v0.2.27 (this issue's existing slot).
- Order:
- After feat(ci): hand-rolled URL and address parsing fails
devops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107, whose markers give this item a checkable finish line. - PR1 lands before fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 and fix(security): local names come from the public suffix list, and domains match on DNS labels, not string suffixes #887.
core/validation.pyis shared in that order, andcommands/k8s/networking.pyis edited here first. - PR2 lands after fix(security): network references come from url and ip syntax, not identifier-prefix and property-suffix lists #431 (v0.2.26).
- Use changelog.d fragments only.
- After feat(ci): hand-rolled URL and address parsing fails
- Size: medium. About 12 source files and 8 test files, in two PRs.
- Lines owned elsewhere:
waterfall.py:114,:130,probe.py:57and the per-request DNS questions: fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898. That includes a name whose answer is a metadata address underallow_private=True, and rebinding.- the
.endswith(".local")clauses atvalidation.py:157and:216, and the suffix lists: fix(security): local names come from the public suffix list, and domains match on DNS labels, not string suffixes #887. sandbox/models.py:62-82: fix(security): URL and host:port reads use the sending client's parser, so key trust, crawls, probes and settings act on the host actually dialled #1112.sanitizer.py:343-366, including its loopback tuple at:352, rewritten on this item's predicate: fix(security): URL credential masking uses urllib and httpx2, so passwords containing '@' and non-http schemes are masked and IPv6 hosts stay intact #1109.- the TLS SAN defaults and AGENTS.md:21-24: feat(ci): hand-rolled URL and address parsing fails
devops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107.
- Absorbs fix(security): ssrf guards admit azure's wireserver metadata address 168.63.129.16 #989.
- Related: fix(security): network references come from url and ip syntax, not identifier-prefix and property-suffix lists #431, feat(telemetry): sandbox egress port scoping, collector lane & in-container trace context #702, fix(ai): web_fetch vetoes every redirect hop, reports failures as failures and renders pages as untrusted text #860 (the review that found the NAT64 gap).
Readiness check (2026-10-04)
Checked at the release/v0.2.26 tip (b61e5a0):
pyproject.tomlstill pins httpx2 2.13.0 (:19) and pydantic-ai 2.35.0 (:37), and dnspython 2.8.0 is still locked.pydantic_ai/_ssrf.pystill hasis_cloud_metadata_ip(:254),is_private_ip(:271),_PRIVATE_NETWORKS(:35) and_CLOUD_METADATA_IPV4/_IPV6(:105/:117), with__all__ = ['safe_download'].- The "No construct left" searches print the same sites as before.
Moved lines
config/constants.py:CONST_CLOUD_METADATA_HOSTS/_IPSare at:2250-2253andCONST_LOCAL_HOSTNAMESat:2526.ai/mcp/server.py: the MCP bind set is at:2994-2995(run_mcp_server).core/validation.py:- The
if not allow_private:block is now:208-228, because feat(cli): extend the ruff rule set to the correctness families #420 addedfrom None. _is_loopback_hostis at:330-338, and its canonicalisation is on:332.- Other validation lines are unchanged.
- The
tests/conftest.py:stub_webis at:198. The DNS guard is still:125-133.tests/test_common_tools.py: the redirect-hop test is at:100.tests/test_sandbox_policy_properties.py: the oracle test is at:270.security/sanitizer.py: the loopback tuple that fix(security): URL credential masking uses urllib and httpx2, so passwords containing '@' and non-http schemes are masked and IPv6 hosts stay intact #1109 owns is at:373.security/reference_extractor.pywas rewritten by fix(security): network references come from url and ip syntax, not identifier-prefix and property-suffix lists #431 (merged, v0.2.26):- The RFC tables are at
:45-74. - They are read by
is_example_or_reserved_ip(:115),is_public_ip(:199) andis_private_or_local_ip(:219).
- The RFC tables are at
ai/tools/builtin_tools.py:456and:460are unchanged.
Rule alignment: one issue = one PR. The two-PR delivery above conflicts with this rule; the readiness check requires each PR body to close exactly one issue. This issue is delivered by the former PR1 only. The former PR2 scope moves to a separate issue, which the owner files and which lands after this one. That scope is:
- the reference_extractor reclassification;
- the
host.docker.internal/localhostlocal-whitelist change; - key questions 4 and 5;
- the PR2 test rows in
tests/test_sandbox_networking.pyandtests/test_reference_extractor.py.
Dependencies.
- fix(security): network references come from url and ip syntax, not identifier-prefix and property-suffix lists #431 is merged.
- feat(ci): hand-rolled URL and address parsing fails
devops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107 is open with no milestone, so "after feat(ci): hand-rolled URL and address parsing failsdevops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107" cannot hold in v0.2.27. The marker criterion is already conditional ("Once feat(ci): hand-rolled URL and address parsing failsdevops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107 has landed").
Open owner decisions. The Status stays unchanged until these are answered:
- Approve the PR2 split above.
- Accept importing the private
pydantic_ai._ssrfmodule (key question 1, still marked proposed). - Confirm that this item does not wait for feat(ci): hand-rolled URL and address parsing fails
devops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107.
Amended criterion
- The delivering PR closes fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897 only. It changes neither
security/reference_extractor.pynor thehost.docker.internal/localhosthandling insandbox/models.py:129-132and:213-214. The "PR2" rows of "Tests updated" belong to the split issue.
Owner decisions (2026-10-04)
The owner accepted the recommendations for the open decisions in the readiness check above.
- Split approved. fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897 is delivered by the former PR1 only. The former PR2 scope (the reference_extractor reclassification, the
host.docker.internal/localhostlocal-whitelist change, key questions 4 and 5, and the PR2 test rows) moved to fix(security): reference_extractor classifies addresses with ipaddress, and the sandbox local whitelist stops mapping host.docker.internal to pod loopback #1174, which lands after this item. The PR2 parts above are superseded by fix(security): reference_extractor classifies addresses with ipaddress, and the sandbox local whitelist stops mapping host.docker.internal to pod loopback #1174. - Key question 1 accepted. Import pydantic-ai's private
_ssrfhelpers (is_cloud_metadata_ip,is_private_ip,_PRIVATE_NETWORKS) at one site incore/validation.py, with the exact pydantic-ai pin, the contract test and the upstream export request. - The order after feat(ci): hand-rolled URL and address parsing fails
devops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107 is soft. This item does not wait for feat(ci): hand-rolled URL and address parsing failsdevops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107; the marker criterion stays conditional ("Once feat(ci): hand-rolled URL and address parsing failsdevops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107 has landed").
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(release): v0.2.24 (#905)
[-]fix(security): egress checks classify NAT64 and IPv4-compatible IPv6 by their embedded IPv4 address[/-][+]fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library[/+]fix(security): egress guards refuse cloud metadata in every numeric, …
dan-petty-bot commentedon Oct 5, 2026
What changed
#1239, merged into
release/v0.2.27as 13808c0.21 file(s) changed.
How it was verified
Check runs at cbfd776:
Acceptance Criteria of
docs/agent/tasks/task-897-egress-guards-cloud-metadata.md:169.254.0.0/16), IPv6 link-local (fe80::/10), NAT64 metadata (64:ff9b::169.254.169.254), 6to4, Teredo, dword/hex/octal representations, fullwidth dot encodings, and provider metadata hostnames.ipaddressandpydantic_ai._ssrfwithout ad-hoc string prefixing or partial keyword subsets.is_loopback_hostrecognizeslocalhost,127.0.0.1,::1,127.0.0.2,::ffff:127.0.0.1,LOCALHOST.without DNS resolution._normalize_ip_cidrrejects scoped IP addresses (fe80::1%eth0/128) and normalizes case.changelog.d/897.mdis provided.uv run devops cipasses on this branch.feat(release): v0.2.27 (#1257)