Skip to content

fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898

Closed

Description

@dan-petty

Problem

Lines cited at dcafadf.

Every outbound HTTP guard checks a host name or a URL string. httpx2 then resolves the name again when it opens the socket, so the checked address is never the dialled one. This issue started as web_fetch only. It now covers every client and every redirect, in two PRs under this one issue:

  • PR A builds the connect-time check and moves the broker, the shared pool, web_fetch and the hand-rolled copies onto it.
  • PR B moves the remaining clients and deletes the old resolve paths.

Measured offline (stub resolver, no sockets):

  • DNS rebinding through web_fetch. The measurement replaced two functions:

    • socket.getaddrinfo answered a public address for the first k lookups of example.com and 169.254.169.254 after that;
    • httpcore2.SyncBackend.connect_tcp was replaced by a recorder.

    The first hop made three checking lookups: egress_policy at src/devops_cli/ai/common_tools.py:372, then the tool's policy and the broker's validate_service_url in the request hook (src/devops_cli/http/broker.py:59-64). Each redirect hop makes two, the hook's policy and the broker's check.

    For k = 0 to 2 the fetch was refused. At k = 3 every check passed, and the recorder was handed the hostname example.com, not an address. The real SyncBackend.connect_tcp passes that name to socket.create_connection (httpcore2/_backends/sync.py:204 in the locked 2.13.0), which resolves it a fourth time; with the stub, that lookup answers 169.254.169.254. The fourth lookup is read from the code, because the recorder replaced it. This issue's earlier version measured the same window with an RFC 1918 answer.

  • Spellings. validate_url(u, allow_private=True) (src/devops_cli/core/validation.py:264-316) refuses the literal http://169.254.169.254/, because its metadata check (:305-310) compares the host text only. It lets these through:

    • http://2852039166/, http://0xa9fea9fe/ and http://0xa9.0xfe.0xa9.0xfe/: glibc's getaddrinfo turns all three into 169.254.169.254 without a DNS query (getaddrinfo(h, 80, flags=socket.AI_NUMERICHOST) returned 169.254.169.254 for each, offline);
    • http://169。254。169。254/: httpx2.URL reads its host as 169.254.169.254.

    Without allow_private, validate_url_egress and _enforce_non_private_ssrf resolve these spellings and refuse them (validation.py:220-226, :251-261). The hole is on the allow-private path, which the broker hook takes whenever private networks are allowed.

  • A name whose answer is 169.254.169.254 passes validate_url with allow_private=True, because its metadata check runs with resolve_dns=False (validation.py:306).

  • validate_url_egress(..., allow_private=True) skips every address check (validation.py:208), so it lets through http://169.254.169.254/ and http://[fd00:ec2::254]/.

Resolve-then-check copies. Each has its own lookup and its own host canonicaliser:

  • core/validation.py:
    • _resolve_host_ips (:120-149) does a lookup in a thread pool;
    • it is used by validate_url_egress (:179-227) and _enforce_non_private_ssrf (:230-261);
    • :250 holds a default-port table.
  • telemetry/waterfall.py:111-162:
    • _is_unsafe_ip tests str(ip).startswith("169.254.") (:114);
    • :130 strips brackets with strip("[]");
    • :139 holds a default-port table;
    • :142 calls getaddrinfo itself.
  • sandbox/probe.py:48-74, with strip("[]") at :57:
    • probe_tcp checks every answer but dials only the first (:100-106);
    • the HTTP probe resolves again at :173, and httpx2 resolves once more at :197.
  • valkey/client.py:91-133 is a fourth copy, in front of raw sockets. 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 replaces that client with Valkey GLIDE (valkey-glide-sync), whose Rust core opens its own sockets, and runs its egress check through this item's resolve-and-check function.

Other defects on the same paths:

  • The async hook blocks the event loop. _async_validate_request (broker.py:87-89) runs the sync check. Its lookup can wait up to DEFAULT_DNS_TIMEOUT_SECONDS, which is 15 s (src/devops_cli/config/defaults.py:306).

  • Jaeger gets the wrong TLS name and Host. waterfall.py:187-191 builds [ip]:port with f-strings and sets Host to parsed.netloc.

    • httpcore2 takes server_hostname from the URL's host, here the IP literal. CPython sends no SNI for an IP literal and checks the certificate against the IP, so an https Jaeger whose certificate names its hostname fails verification.
    • Any userinfo in the configured URL goes out in the Host header.
  • Tool downloads follow redirects unchecked. src/devops_cli/commands/install_tools.py:84, :100 and :190 build httpx2.Client(follow_redirects=True) with no per-hop check.

    • _download checks only the first URL: a startswith("https://") test (:97), then validate_service_url (:99), which the environment flag can widen to private addresses. :84 and :190 check nothing.
    • httpx2's _redirect_url (httpx2/_client.py:497-522) has no scheme check, so https-to-http redirects are followed.
  • Four parsers of one flag disagree. DEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORK is read in four ways:

    • in ("true", "1") at broker.py:31-35;
    • in {"1", "true", "yes", "on"} at validation.py:297-302;
    • the same four words as a tuple at src/devops_cli/ai/client/unified.py:344-352, after the allow_private_network config field;
    • the settings' general bool coercion at src/devops_cli/config/settings.py:1145-1146.

    So =yes is honoured by validation and ignored by the broker. The broker's reading is also frozen at import, because DEFAULT_HTTP_BROKER is built at module load (broker.py:186).

  • A per-request override cannot reach the connection.

    • request and arequest take allow_private_network and pass it as a request extension (broker.py:104-154).
    • Vault uses it at src/devops_cli/security/vault_broker.py:113, :158 and :179, and at src/devops_cli/security/vault_lease.py:56.
    • A pooled connection opened for a permissive request can be reused by a strict one.
  • Fallbacks outside any check. In src/devops_cli/ai/client/base.py:

    • :64-65: if building httpx2.HTTPTransport(limits=..., http2=True) fails, the retry transport wraps httpx2's default transport instead;
    • :73-74 catches any exception from that and returns a plain httpx2.Client;
    • :96-97 does the same for the shared client, returning it without the retry transport.
  • Clients built outside any guard. The Python files under src hold 54 httpx2.Client( / httpx2.AsyncClient( matches (rg -n -g '*.py' 'httpx2\.(Async)?Client\(' src):

    • three in http/pool.py, one of them in its module docstring (:5);
    • two in http/client.py;
    • 49 elsewhere.

    Two more are in a knowledge-base document (src/devops_cli/ai/knowledge_base/devops_cli/libraries/httpx2.md:38 and :56) and are not code. broker.py builds two more clients through its httpx alias. Seven module-level calls skip clients altogether: src/devops_cli/ai/providers/anthropic.py:77, ai/providers/ollama.py:37 and :65, ai/providers/openai.py:62, ai/spend/pricing.py:463 and :472, and k8s/logql.py:365.

  • One service, several rules. The rule depends on the code path, not the service:

    • Prometheus is reached at any address, metadata included, by the pool-load query (src/devops_cli/ai/pool_load.py:45), but devops prometheus needs the flag for a private address (src/devops_cli/commands/prometheus.py:49);
    • the pydantic-ai Ollama model allows private addresses without the flag (src/devops_cli/ai/models/ollama.py:130, :150), while the provider and embedding paths to the same URL need it (ai/providers/ollama.py:36, ai/rag/embeddings.py:520).

    The level key question below lists every caller with its rule today.

  • No test reaches the connect.

    • stub_web (tests/conftest.py:189-222) gives every client a MockTransport.
    • test_web_fetch_tool_blocks_dns_rebinding (tests/test_common_tools.py:176-181) answers the same private address to every lookup. The first check refuses it, so the answer never changes between check and connect.
    • The session guard passes a non-loopback lookup through only when ipaddress parses the host (tests/conftest.py:76-82, used at :127), so 2852039166 fails with gaierror in tests instead of resolving as glibc resolves it.

Acceptance criteria

Deliverable

  • One vetting network backend on httpcore2's public network-backend API (httpcore2.NetworkBackend and AsyncNetworkBackend). httpcore2 2.13.0 is already locked as httpx2's transport. Its connect_tcp:
  • TLS stays on the hostname. httpcore2 builds server_hostname from the origin host (httpcore2/_sync/connection.py:136 in the locked 2.13.0), so SNI and certificate checks still use the name.
  • One factory, built on the existing new_http_client and new_async_http_client (src/devops_cli/http/client.py:55-75).
    • It owns verify, cert, http2, limits and retry wrapping, because httpx2 ignores those options on a client given transport=.
    • Sync: it builds an httpx2.HTTPTransport and replaces its _pool with httpcore2.ConnectionPool(..., ssl_context=httpx2.create_ssl_context(...), network_backend=<sync vetting backend>).
    • Async: it builds an httpx2.AsyncHTTPTransport and replaces its _pool with httpcore2.AsyncConnectionPool(..., network_backend=<async vetting backend>). httpx2 builds these two pools at httpx2/_transports/default.py:152 and :295. See the _pool key question.
    • The retry transport wraps that transport through its existing wrapped= argument (src/devops_cli/ai/retries/__init__.py:96-100).
  • Three policy levels, chosen per client: public-only, loopback-allowed and private-allowed.
  • PR A delivers:
    • the policy module, with one public resolve-and-check function that both backends, stub_web and the pre-flight callers share; both backends; and the factory;
    • the session guard's literal test (tests/conftest.py:76-82, used at :127), described under "Old vs new". 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's tests rely on it too;
    • the broker: one client per level, the flag read lazily from Settings.ai.allow_private_network, and the per-request extension deleted. Vault takes the private-allowed client. telemetry/memory_profiler.py:263 moves to the private-allowed client;
    • http/pool.py: get_shared_client and get_shared_async_client take a level, which becomes part of the pool key. Their callers (ai/client/base.py:95-97, k8s/service_http.py:53-55 and :64) pass theirs. The module docstring's example (:5) shows the factory, not httpx2.Client(;
    • web_fetch on the public-only client. Its hop hook keeps only the scheme and domain-list checks; the address check moves to the backend;
    • stub_web, waterfall, probe and install_tools;
    • removal of the three ad-hoc flag parsers.
  • Not in scope: the import httpx fallbacks at http/broker.py:9-12 and telemetry/memory_profiler.py:247-250. fix(deps): pyproject.toml declares every package src imports, and a deptry step in devops ci keeps it that way #1120 deletes them, whichever of the two items lands first. Until it does, PR A leaves those lines alone, and both files keep calling httpx2 through the httpx alias.
  • PR B delivers:
    • the remaining raw clients moved to the factory at the table's levels;
    • pre-flight address checks removed, except those listed under the pre-flight key question;
    • the old resolve paths deleted.

Kept from this issue's earlier version (criteria 1 to 8, adapted to this design)

  • Rebinding (criterion 1). A test drives web_fetch_tool().execute(url="https://example.com/") without stub_web.
    • It is parametrised over k = 0 to 4, and over the second answer: 169.254.169.254, 127.0.0.1, and an RFC 1918 address.
    • A stub resolver answers 93.184.215.14 (the public_dns fixture's public address) for the first k lookups of example.com, and the second answer after that.
    • The inner backend is a recorder that returns an httpcore2.MockStream.
    • For every k, no connection attempt goes to the second answer, and the inner backend receives 93.184.215.14 or nothing, never a hostname.
    • The test fails on the current code at k = 3.
  • Redirect to a second hostname (criterion 2). A redirect from https://example.com/start to https://example.org/ is pinned the same way. A second hostname is the point of the row; example.org is used because AGENTS.md:36 rules out subdomains of example.com. Its connection never goes to the second answer, for any k.
  • One hostname per connection (criterion 3). example.com redirects to example.org, and both answer 93.184.215.14. The backend is still asked for a second connection, and its start_tls receives server_hostname="example.org".
  • The environment does not widen web_fetch (criterion 4). With DEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORK=true and ai.allow_private_network: true, the three criteria above still hold. web_fetch uses the public-only client whatever the environment says, as _validate_fetch_hop promises (common_tools.py:345-348).
  • Mixed and failed answers (criterion 5).
    • An answer holding 93.184.215.14 and an RFC 1918 address together is refused, with no connection attempt.
    • A resolver error surfaces as httpx2.ConnectError: the backend re-raises the OSError as httpcore2.ConnectError.
    • An IP-literal host is classified without a DNS query.
    • [fe80::1%25eth0] fails closed.
    • If the first vetted address refuses the connection, the next one is tried, and the last error is raised.
  • TLS (criterion 6). For an https URL:
    • start_tls receives server_hostname="example.com";
    • the SSL context has check_hostname=True and verify_mode=CERT_REQUIRED;
    • the request's Host header is example.com;
    • response.url is https://example.com/.
  • Refusals (criterion 7).
    • A refusal raises SSRFBlockedError. That is not an httpx2 TransportError, so the tenacity retry transport (src/devops_cli/ai/retries/__init__.py:51) attempts the request only once.
    • With fix(ai): web_fetch reports a failed fetch as a tool failure, not as page text #894 in place, the refusal reaches the runner's error result (src/devops_cli/ai/agents/runner.py:167-174). A test asserts this for k = 3.
    • A refusal never comes back as page content.
  • Classification (criterion 8). The backend classifies with fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897's predicates, the same ones every other check uses. An answer of 64:ff9b::a9fe:a9fe is refused before any connect, at every level.
  • Criteria 9 and 10 are dropped. They kept every other client on httpx2's default transport and banned httpcore2 imports from src, and this design moves every client onto an httpcore2 network backend that src imports directly.

New criteria

  • Old vs new at the connect. These run with httpcore2.MockBackend as the inner backend and a stubbed resolver.
    • The stub resolves numeric spellings as glibc does. The session guard's literal test (tests/conftest.py:76-82, used at :127) becomes "the original getaddrinfo(host, None, flags=socket.AI_NUMERICHOST) succeeds". AI_NUMERICHOST never queries DNS, so 2852039166, 0xa9fea9fe and 0xa9.0xfe.0xa9.0xfe resolve to 169.254.169.254 in tests as they do in production.
    • Every refusal below is SSRFBlockedError raised by the backend's classification, with no connect reaching the inner backend. A ConnectError or gaierror fails the row.
    • The integer, hex, dotted-hex and ideographic-dot spellings of 169.254.169.254 are allowed today by validate_url with allow_private=True, and refused afterwards at every level.
    • A name answering 169.254.169.254 is allowed today by validate_url with allow_private=True, and refused afterwards at every level.
    • NAT64-, 6to4- and Teredo-wrapped 169.254.169.254 under private-allowed are allowed today by validate_url with allow_private=True, and refused afterwards.
    • Answers of 169.254.169.254, fd00:ec2::254 and fd20:ce::254 under private-allowed are refused. Today validate_url_egress(allow_private=True) lets them through.
    • Loopback, RFC 1918 and CGNAT (100.64.0.0/10) answers are allowed only at the levels that allow them.
  • Link-local host gateway (pins the link-local key question). A stub answers 169.254.1.2 for example.com; the address is the point of the row, not the name.
    • Under the proposed answer it is refused at public-only and loopback-allowed and allowed at private-allowed. 169.254.169.254, 169.254.170.2 and fd00:ec2::254 stay refused at private-allowed.
    • Under the alternative it is refused at every level, and docs/DEVCONTAINER_USAGE.md:252-255 and :424-461 are updated.
  • Level table. One parametrised test builds each caller's client in the table below, with and without ai.allow_private_network, and asserts its level. Each row marked "narrower" or "wider" has a case that fails on the current code.
  • Redirect to metadata. A redirect to a name that resolves to 169.254.169.254 is refused at hop 2, and no connection is left in the pool.
  • Async. With a resolver stub that blocks for 0.5 s, a concurrent task keeps running during the lookup. The broker's async hook does no lookup at all.
  • Isolation. The broker keeps one client per level, and the shared pool keys include the level. A connection opened by a private-allowed client is never reused by a public-only one.
  • Pinned seam. A test asserts that the factory's sync transport _pool is an httpcore2.ConnectionPool and its async transport _pool an httpcore2.AsyncConnectionPool, each holding the vetting backend. An httpx2 upgrade that changes either then fails the test, instead of silently dropping the check.
  • Proxies. A test pins the proxy decision (see the proxy key question).
  • Jaeger. query_jaeger_trace requests the configured hostname URL through a loopback-allowed factory client. For an https Jaeger, start_tls receives the hostname, and no Host header carries userinfo. An RFC 1918 Jaeger is still refused, with or without the flag, as tests/test_sandbox_traces.py:385-393 pins today.
  • Tool downloads. A request hook on request.url.scheme refuses an install_tools redirect from https to http at hop 2. The same hook replaces the startswith("https://") test at install_tools.py:97, and the public-only client replaces validate_service_url at :99.
  • Fail closed. A factory error raises. base.py:64-65, :73-74 and :96-97 no longer fall back to a transport or client built outside the factory.
  • The flag is read once. Settings.ai.allow_private_network is the only source, read when a client is built, not at import.
  • Dependency. Once src imports httpcore2, httpcore2==2.13.0 is declared in pyproject.toml next to httpx2==2.13.0. fix(deps): pyproject.toml declares every package src imports, and a deptry step in devops ci keeps it that way #1120's dependency check enforces the declaration once it lands.
  • Review guidance. AGENTS.md:416, src/devops_cli/ai/review/common_hallucinations.json:511 and .devops/review.md:20-23 say that internal connectors "configure allow_private_network=True". They are rewritten to say which level each connector gets (private-allowed or configured, as in the table), that metadata addresses are refused at every level, and that SSRF findings still apply to public-only callers.
  • No construct left after PR A:
    • rg -n 'ALLOW_PRIVATE_NETWORK_ENV|"DEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORK"' src prints only lines under src/devops_cli/config/. This removes validation.py:18, :37 and :297, broker.py:34, unified.py:27, :163 and :347, and the ALLOW_PRIVATE_NETWORK_ENV alias at ai/client/network.py:21 and :34 with its re-export at ai/client/__init__.py:17 and :39;
    • rg -n '"allow_private_network"|allow_private_network=True' src/devops_cli/http src/devops_cli/security prints nothing;
    • rg -n '_resolve_safe_jaeger_target|_resolve_safe_socket_addr|_is_unsafe_ip|startswith\("https://"\)' src/devops_cli/telemetry/waterfall.py src/devops_cli/sandbox/probe.py src/devops_cli/commands/install_tools.py prints nothing.
  • No construct left after PR B:
  • Markers, 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:
  • Tests updated:
    • tests/test_validation.py:162-231 and :460-514;
    • tests/test_sandbox_policy_properties.py:39-40 and :269-315, where the per-site agreement collapses to one policy;
    • tests/test_sandbox_traces.py:385-393, which moves to the backend at the loopback-allowed level;
    • tests/test_http_broker.py:58-122 (the per-request override, deleted with it), :125-200 and :230-247;
    • tests/conftest.py:189-222: stub_web calls the shared resolve-and-check function, because a MockTransport never reaches connect_tcp. Two or three wiring tests use a MockBackend inner backend instead;
    • tests/conftest.py:76-82 and :127: the literal test described under "Old vs new";
    • tests/test_pydantic_ai_ollama.py:96, which patches _resolve_host_ips;
    • tests/test_sandbox_probe.py:115-124 and :575-594;
    • tests/test_k8s_service_proxy.py:273-289, which patches validate_url_egress;
    • tests/test_ollama_dynamic_leasing.py:90-112, which imports the ALLOW_PRIVATE_NETWORK_ENV alias.
  • Release.
    • changelog.d/898.md has the entry under ### Security. It names:
      • the proxy change;
      • every table row marked "narrower" or "wider";
      • the metadata refusal for callers that allowed any address;
      • the link-local answer.
    • PR B adds to the fragment, or recreates it if a release cut has already merged PR A's fragment.
    • CHANGELOG.md and docs/ROADMAP.md are not edited.
  • Offline and fast.
    • Tests never touch the network. The session guard (tests/conftest.py:125-163) still applies, and anyio's lookup goes through the patched socket.getaddrinfo.
    • web_fetch's lookups fall from 4 to 1 on the first hop and from 3 to 1 on each redirect hop.
    • uv run devops ci passes.
  • Pending a person: (optional) start a listener on 127.0.0.1:8000, then call web_fetch 50 times on http://7f000001.5db8d822.rbndr.us:8000/. That public rebinding name answers 127.0.0.1 or 93.184.216.34 at random. Before PR A some calls usually reach the listener; after it, none do.
  • Pending a person: file an upstream feature request for a network_backend= argument on httpx2.HTTPTransport and AsyncHTTPTransport (see the _pool key question).
  • Pending a person: answer the proxy and link-local key questions before PR A is merged.

Key questions

  • Swap httpx2's private _pool, write a project-owned transport, or keep the earlier URL-rewrite design? Proposed: swap _pool for a public httpcore2.ConnectionPool(..., network_backend=...) (async: httpcore2.AsyncConnectionPool), pinned by the seam test.

    • HTTPTransport.__init__ takes no network_backend in 2.13.0 (httpx2/_transports/default.py:132-145). The upstream code has none, and no upstream issue asks for it.
    • A project-owned BaseTransport would re-implement httpx2's exception mapping, because map_httpcore_exceptions is not exported.
    • The earlier URL rewrite has three drawbacks:
      • it needs one inner transport per (scheme, hostname, port) to keep certificates per hostname;
      • it relies on the sni_hostname extension;
      • it covers only the clients that are handed it.
    • The backend sees every connection any pool opens, redirects included, and leaves pooling, SNI and HTTP/2 :authority to httpcore2.
  • Do guarded clients honour HTTP_PROXY / HTTPS_PROXY / ALL_PROXY? Proposed: no (owner decision).

    • httpx2 already ignores environment proxies for a client given transport= (httpx2 2.13.0, httpx2/_client.py:659).
    • A proxy would become the vetted peer instead of the destination.
    • httpcore2.HTTPProxy(network_backend=) vets the proxy, not the destination, so it is not an alternative.
    • Cost: a workstation that reaches the internet only through a proxy loses outbound HTTP from devops-cli. The changelog says so, and a test pins the decision.
  • Which level does each client get? Proposed: each caller keeps the address classes it reaches today, minus metadata, with three exceptions:

    "Configured" means loopback-allowed, or private-allowed when ai.allow_private_network is set. "The flag" below covers both ai.allow_private_network and DEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORK, which validate_url also reads today.

    Caller Today After
    web_fetch (ai/common_tools.py:354, :372) public only; the flag is ignored public-only (same)
    Tool downloads (commands/install_tools.py:84, :99-100, :190) :99: public, or private with the flag; :84 and :190: no check public-only (narrower: the flag no longer widens)
    Docs crawler (ai/library/docs_ingester.py:231, :244, :253) public, or private with the flag public-only (narrower)
    Fixed public APIs: GitHub (github/client.py:178, github/graphql.py:720, github/ssh.py:151), Cloudflare (cloudflare/client.py:287), OSV, Shodan InternetDB and Cloudflare Radar (security/vulnerability_lookup.py:185, :307, :377), DuckDuckGo and Tavily (ai/common_tools.py:419, :470), the harness docs fetch (ai/harness/docs.py:88), the default pricing registry (ai/spend/pricing.py:472) no address check public-only (narrower: a non-public answer for these names is refused)
    devops ai cost --source URL (ai/spend/pricing.py:463) no address check configured (narrower: a private source needs the flag)
    AI client base URL (ai/client/network.py:379, ai/providers/__init__.py:96), Ollama provider and embeddings (ai/providers/ollama.py:36, :57; ai/rag/embeddings.py:520, :539, :686, :811), Qdrant (ai/rag/qdrant.py:180, pre-flight only) configured; the metadata literal refused configured (same)
    pydantic-ai Ollama model (ai/models/ollama.py:130, :150, via ai/pydantic_ai_bridge.py:166) private without the flag; names answering link-local refused (:34-37, :70) configured (narrower: a private Ollama needs the flag on this path too)
    Anthropic and OpenAI providers' own checks (ai/providers/anthropic.py:43, ai/providers/openai.py:42) public, or private with the flag configured (wider: loopback without the flag)
    AI gateway and backend probes (ai/gateway.py:249, :375, :532) public only without the flag; any address, metadata included, with it configured (wider: loopback without the flag; metadata refused with it)
    Benchmark endpoints (commands/benchmark.py:75, ai/benchmark/runner.py:227, ai/benchmark/embedding_runner.py:290) --servers accepts private; the runners then refuse loopback and private without the flag configured, through the AI client (wider: loopback without the flag)
    Grafana (commands/grafana.py:66, k8s/credentials.py:331, :449), ArgoCD (argo/fleet.py:48, argo/gitops.py:358, commands/argo.py:170, k8s/credentials.py:236, :418), devops prometheus and other Prometheus commands (commands/prometheus.py:49, argo/rollouts.py:91, commands/ai_gateway.py:547) public, or private with the flag configured (wider: loopback without the flag)
    Jaeger (telemetry/waterfall.py:176-182) loopback and public; RFC 1918 and link-local refused; the flag is ignored loopback-allowed (same)
    Sandbox metrics scrape (sandbox/metrics.py:410-417) loopback names and public; the flag is ignored loopback-allowed (same)
    Loki (k8s/logql.py:352), Prometheus pool load (ai/pool_load.py:45), cluster-service direct URLs (k8s/service_http.py:63) any address, metadata included private-allowed (metadata refused)
    Kubernetes API-server proxy (k8s/service_http.py:53-55) no address check private-allowed, with the API server's TLS context passed through the factory (metadata refused)
    OTLP exporter and connection probe (telemetry/tracer.py:1169, :1202) no address check private-allowed (metadata refused)
    Vault (security/vault_broker.py:113, :158, :179; security/vault_lease.py:56) private; the metadata literal refused private-allowed (same, now checked at the connect)
    Sandbox HTTP probe (sandbox/probe.py:162-173, :197, :346) private; link-local and metadata refused private-allowed (wider only if the link-local answer allows host gateways)
    Memory profiler (telemetry/memory_profiler.py:263) private private-allowed (ASGI transport, no socket)
  • Are link-local host gateways refused? (owner decision)

    • Measured: in a rootless Podman (pasta) devcontainer, getent hosts host.containers.internal host.docker.internal returns 169.254.1.2, a link-local address.
    • docs/DEVCONTAINER_USAGE.md:252-255 recommends http://host.docker.internal:11434 for Ollama, with the flag set. :424-461 recommends host.docker.internal for the API server (https://host.docker.internal:6443 at :426).
    • Today, a name answering a link-local address passes validate_url with allow_private=True, validate_url_egress(allow_private=True) and the k8s proxy client, which has no check. The pydantic-ai Ollama model, the sandbox probe, Jaeger and the Valkey client (src/devops_cli/valkey/client.py:122) refuse it. 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's Valkey check follows whichever answer is chosen.
    • Under Docker Desktop and Docker's host-gateway mapping, these names answer private, not link-local, addresses and are unaffected either way.

    Proposed: public-only and loopback-allowed refuse every link-local address. Private-allowed refuses metadata addresses (fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897's classifier, which lists 169.254.169.254, 169.254.170.2, 169.254.170.23, fd00:ec2::254 and the other provider addresses) and allows other link-local addresses.

  • Is there an off-the-shelf alternative? Proposed: none fits.

    • safehttpx: async GET only. It falls back to DNS-over-HTTPS at dns.google, which bypasses split-horizon DNS for private zones, and it treats 100.64.0.0/10 as public.
    • advocate: last released in 2020, and it needs requests with urllib3<2.
    • httpx-secure: targets httpx, not httpx2.
    • Smokescreen: a proxy to run, not a library.
    • pydantic-ai's safe_download: in a private module (pydantic_ai/_ssrf.py, __all__ = ['safe_download']) and async only.
    • httpcore2's network-backend API is the maintained seam.
  • Which callers keep a pre-flight check? Proposed: only those whose dialler is not an httpx2 client, or that dial nothing. Each names its time-of-check gap in a docstring and calls the policy module's one public resolve-and-check function, the same one the backend and stub_web use:

  • What about boolean coercion of the flag? Today DEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORK=bogus silently becomes False through settings.py:1141-1146. Proposed: refactor(config): a settings field is the one declaration, and the option, env and config-show registries become views of it #1000 makes it strict. This item only reads the setting.

  • What about get_pr_diff's redirect rule (src/devops_cli/github/client.py:170-186)? Proposed: not here. That rule is about the Authorization header and a host allowlist, not addresses.

  • Does "every HTTP client" include model and embedding traffic, which refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 says it "does not move onto the broker"? Proposed: yes for the connect-time check, no for the broker. PR B gives the AI clients their client from this item's factory, so their connections are checked against the address dialled; refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001's adapters take that client and stay off the broker, so refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001's statement stays true. A comment on refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 records this.

  • Does PR B take this issue's v0.2.29 slot? Proposed: no. PR A keeps the slot; PR B follows under this issue wherever the roadmap tooling places it. A person confirms.

Strategic alignment

Update 2026-10-08: delivered scope (PR A) and corrected premises

Activity

  1. added
    type/security
    scope/security
    priority/p2-medium
    on Oct 1, 2026
  2. added a commit that references this issue on Oct 1, 2026
  3. added
    priority/p1-high
    scope/ai
    and removed
    priority/p2-medium
    on Oct 2, 2026
  4. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Grooming (2026-10-02): Priority p2-medium → p1-high.

    Checked against the code at the release/v0.2.25 tip.

  5. added this to the v0.2.29 milestone on Oct 2, 2026
  6. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Placed in v0.2.29 on 2026-10-02. v0.2.29 holds P1 work that has to land before v0.3.0, which v0.2.25 to v0.2.28 had no room for. Backlog P1 items were ranked by Value, then Effort, with defects and security fixes first at a tie. This item ranked in the top ten, and two of the release's twelve slots stay open for P1 items that surface before then.

  7. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Refined to Ready on 2026-10-02 for v0.2.29. The body was checked claim by claim against release/v0.2.25 at 9c879ae, and a second agent then tried to refute it; every major objection was resolved in a revision. Cited lines were updated for code that moved, and the scope was corrected where merged work changed it. Acceptance criteria were tightened so each fails on the current code, and every key question now has a proposed answer.

  8. changed the title [-]fix(security): web_fetch connects to the address its egress check approved[/-] [+]fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect[/+] on Oct 3, 2026
  9. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Owner decisions, 2026-10-08, clearing this item's merge gate (PR #1382 implements both):

    • Link-local: confirmed as proposed. Public-only and loopback-allowed clients refuse every link-local address. Private-allowed clients refuse only metadata addresses and admit other link-local addresses, such as rootless Podman's host gateway at 169.254.1.2.
    • Proxies: confirmed as proposed. Clients that go through the egress check ignore HTTP_PROXY, HTTPS_PROXY and ALL_PROXY. A workstation that reaches the internet only through a proxy loses outbound HTTP from these clients, and the changelog says so.
  10. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1382, merged into release/v0.2.29 as 99566ea.

    Closes #898

    This delivers the "PR A" scope only. The rest of the clients, the pre-flight deletions, the docs crawler and github/client.py move to #1381, because readiness requires a PR to close exactly one issue.

    • Connect-time check: devops_cli.http.egress vets every address the factory-built clients are about to dial, at the connect and on each redirect hop, through an httpcore2 network backend (sync and async). It does one lookup per hop, so a rebound DNS answer is refused instead of slipping in between the check and the dial.
    • Factory: devops_cli.http.client builds clients at four levels: public-only, loopback-allowed, private-allowed and configured. Configured follows ai.allow_private_network. Metadata addresses are refused at every level, and scoped IPv6 is refused everywhere.
    • Moved onto it: the broker, the shared pool, web_fetch, Jaeger, the sandbox probe, tool downloads, and the existing factory callers (DuckDuckGo, Tavily, the harness docs fetch and Statuspage, now public-only). Each keeps its caller timeout across every phase. Retries are opt-in, so only the AI clients keep the tenacity transport.
    • Narrower and wider: the changelog lists every row that changes. validate_url's environment reader no longer widens hard-coded allow=False checks such as the docs crawler.
    • Docs: the review guidance and docs name only the factory-built clients as checked at the connect, until fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381 moves the rest.
    • Tests: offline only, using Scri…

    60 file(s) changed.

    How it was verified

    Check runs at b76f56e:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • DevContainer Image: skipping
    • Static Analysis: pass
    • Analyze (actions): pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-898-connect-time-egress-check.md:

    • One vetting network backend on httpcore2's NetworkBackend and AsyncNetworkBackend: one lookup, SSRFBlockedError on any unsafe answer, each vetted IP literal dialled in turn (test_each_vetted_address_is_dialled_in_turn_and_the_last_error_raised).
    • TLS stays on the hostname: start_tls receives server_hostname="example.com", the context has check_hostname=True and CERT_REQUIRED, Host is example.com and response.url is https://example.com/ (test_tls_and_the_host_header_keep_the_hostname).
    • One factory owning verify, http2, limits and opt-in retries, with the pinned seam (test_the_factory_swaps_httpx2s_pool_for_a_vetting_httpcore2_pool).
    • Three levels, metadata refused at every level, link-local per the proposed answer (test_each_level_admits_only_its_address_classes, test_link_local_host_gateways_are_admitted_only_at_the_private_level).
    • Rebinding (criterion 1): web_fetch without stub_web, k = 0 to 4 against 169.254.169.254, 127.0.0.1 and 10.0.0.1, with the environment flag set; the dial receives 93.184.215.14 or nothing, never a hostname (test_web_fetch_never_dials_a_rebound_answer).
    • Redirect to a second hostname (criterion 2) for every k (test_web_fetch_never_dials_a_rebound_redirect_hop), and one hostname per connection (criterion 3) with start_tls names example.com then example.org (test_web_fetch_opens_one_connection_per_hostname_with_its_own_tls_name).
    • The environment does not widen web_fetch (criterion 4): the rebinding and redirect rows run with DEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORK=true and ai.allow_private_network: true.
    • Mixed and failed answers (criterion 5): a mixed answer is refused with no dial, a resolver error surfaces as httpx2.ConnectError, a literal is classified without a DNS query, [fe80::1%25eth0] and scoped answers fail closed, and a refused address moves the dial on to the next.
    • Refusals (criterion 7): SSRFBlockedError is attempted once under the retry transport and reaches the runner's error result, never page text.
    • Classification (criterion 8): 64:ff9b::a9fe:a9fe and every other metadata spelling are refused at every level before any dial.
    • Old vs new at the connect: integer, hex, dotted-hex and ideographic spellings, a name answering metadata, NAT64, 6to4, Teredo and mapped forms, and fd00:ec2::254, fd20:ce::254 and 169.254.170.2 answers are refused at every level; loopback, RFC 1918, CGNAT and unique-local answers only at their levels.
    • Level table for the callers this item moves, with and without the flag, read from what reaches the dial (test_each_caller_dials_at_its_level, 14 callers); the memory profiler makes no lookup or dial (test_the_memory_profiler_exercises_its_pool_without_a_lookup_or_a_dial); the narrower tool-download row is test_download_refuses_a_private_answer_whatever_the_flag.
    • Redirect to metadata refused at hop 2 with nothing pooled for it (test_a_redirect_to_a_name_answering_metadata_is_refused_at_hop_two).
    • Async: a 0.5 s blocking resolver leaves a concurrent task running, a slow lookup times out as ConnectTimeout, and the broker's async hook makes no lookup.
    • Isolation: a private-level connection is never reused by a public-level request, through the broker and the pool keys.
    • Proxies pinned, Jaeger queried at its hostname at the loopback level (TLS name and Host without userinfo, RFC 1918 refused with or without the flag), tool downloads refuse an https-to-http hop.
    • Fail closed: the AI client raises when its client cannot be built, here because SSL_CERT_FILE names a missing CA bundle (test_an_ai_client_raises_when_its_client_cannot_be_built).
    • Caller timeouts kept: the probe's --timeout and Jaeger's timeout bound the connect (test_the_probe_timeout_bounds_every_connect, test_the_jaeger_timeout_bounds_the_connect).
    • The flag is read when a client is built, from ai.allow_private_network only (test_the_configured_level_is_read_from_the_settings_when_a_client_is_built).
    • Dependency: httpcore2==2.13.1 (and anyio==4.15.1) declared.
    • Review guidance rewritten in AGENTS.md, .devops/review.md and common_hallucinations.json.
    • No construct left after this change: rg -n 'ALLOW_PRIVATE_NETWORK_ENV|"DEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORK"' src prints only config/env.py; rg -n '"allow_private_network"|allow_private_network=True' src/devops_cli/http src/devops_cli/security prints nothing; rg -n '_resolve_safe_jaeger_target|_resolve_safe_socket_addr|_is_unsafe_ip|startswith\("https://"\)' over waterfall, probe and install_tools prints nothing.
    • Release: changelog.d/898.md under ### Security names the proxy change, the narrower and wider rows, metadata refusal for clients that reached any address, and the link-local answer; CHANGELOG.md and docs/ROADMAP.md are untouched.
    • Offline and fast: every new test stubs the resolver and the dial, opens no socket and makes no DNS query. Run with -n0, each test this item adds or rewrites has a call phase under 1 s; the longest is test_the_async_lookup_runs_off_the_event_loop at 0.5 s, its blocking resolver stub. uv run devops ci passes.
    • Remaining raw clients onto the factory, pre-flight removal, deleting _resolve_host_ips and _enforce_non_private_ssrf, the documentation crawler and github/client.py: fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381.
    • Markers (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) are not in this release; the conditional criterion does not apply.
    • Pending a person: answer the link-local and proxy key questions on fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 before this pull request merges; the Decisions above implement the proposed answers.
    • Pending a person: (optional) start a listener on 127.0.0.1:8000, then call web_fetch 50 times on http://7f000001.5db8d822.rbndr.us:8000/; no call should reach the listener.
    • Pending a person: file an upstream feature request for a network_backend= argument on httpx2's HTTPTransport and AsyncHTTPTransport.
  11. added a commit that references this issue on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/aiscope/securitytype/security

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions