Repository navigation
Description
Problem Description
Part 5 of #1381, the last part. The owner approved the split of #1381 into five parts on 2026-10-28.
Parts 1 to 4 move the HTTP clients to the egress-checked factory (devops_cli.http.client), and #1319 moves the telemetry clients. After them, two pre-flight resolve paths in core/validation.py remain: _resolve_host_ips and _enforce_non_private_ssrf. They resolve a host name before the dial, and the dialler resolves it again. This part deletes them. The callers that #898 keeps as pre-flight checks then call vet_addresses (devops_cli.http.egress) at their level, and each one names its time-of-check gap in a docstring. This part also adds the rg checks of #1381 as checks that fail when the problem comes back, and it updates the documents.
Scope, with lines on origin/main d739a47 and the level from the #898 level table.
1. Delete the pre-flight resolve paths (core/validation.py).
_resolve_host_ips(:411) and_enforce_non_private_ssrf(:599) go.- The DNS branches that call them go:
is_cloud_metadata_host(:335,:378),is_loopback_or_private_host(:443,:465),_validate_hostname_egress(:534,:550) undervalidate_url_egress(:560), andvalidate_url(:644,:691). Theresolve_dnsparameters go with them. - A validator that has no caller after the moves goes, with no shim:
validate_url_egress,validate_url,validate_service_url(:696),validate_configured_service_url(:706), and the re-exports inhttp/validation.pyandhttp/__init__.py:8,:18. A scheme and syntax check without a lookup can stay where a command needs an early error.
2. Change the kept pre-flight checks to vet_addresses. These callers stay because their dialler is not an httpx2 client, or because they dial nothing (#898, pre-flight key question).
| Caller | Check today | Level |
|---|---|---|
| Qdrant: qdrant-client dials through httpx and grpcio | ai/rag/qdrant.py:215, validate_configured_service_url |
configured (same) |
devops k8s apply with a manifest URL: kubectl dials it |
commands/k8s/cluster_context.py:197, validate_url_egress |
public (same) |
Container engine tcp:// endpoint: docker-py dials it through requests |
docker/engine.py:368, validate_service_url in _check_endpoint_egress (:358) |
public, or private with the flag (same: the rule that #1108 keeps) |
devops config init wizard: it checks a typed URL and dials nothing |
commands/config.py:361, :377, :387, validate_service_url |
configured (wider: loopback without the flag) |
"Configured" is loopback, or private when ai.allow_private_network is set (configured_level). "The flag" is ai.allow_private_network.
Each caller in the table calls vet_addresses at its level and names its time-of-check gap in a docstring. DockerEngineService.resolve_host (docker/engine.py:374-381) already names its gap. The wizard catches a failed lookup (httpcore2.ConnectError) as it catches a refusal today.
3. Remove the last raw clients and the AI client pre-flight check. Part 1 (#2422) leaves these to this part, because #1110 changes ai/client/*.
| Caller | Today | After | Level |
|---|---|---|---|
AI client base URL, validate_base_url |
ai/client/network.py:604, validate_configured_service_url |
the pre-flight check goes; the factory client checks at the connect (ai/client/base.py:64-66); the scheme and host checks at ai/client/network.py:585-599 stay |
configured (same) |
| AI client with an injected transport | raw httpx2.Client(transport=...) at ai/client/base.py:77 and :102; the only caller that gives a transport is the review dry-run preview, with an in-memory httpx2.MockTransport (ai/review/runner.py:247-254) |
no raw client outside http/client.py |
no dial |
4. Add the checks. Add the two rg checks of #1381 as ast-grep rules in .ast-grep/rules/, with rule tests in .ast-grep/rule-tests/. The pre-commit ast-grep-scan hook (.pre-commit-config.yaml:78-80) then fails when a raw client or a pre-flight resolve path comes back.
5. Update the documents. Each one says that every HTTP client is checked at the connect, and it names the kept pre-flight callers:
README.md:18,:134;ARCHITECTURE.md:144,:195;SECURITY.md:18(item 2);docs/ROUTINE_TASKS.md:257;docs/KNOWN_ISSUES.md:13-15, which namesvalidate_service_url()andvalidate_configured_service_url();- the knowledge base page
src/devops_cli/ai/knowledge_base/devops_cli/libraries/httpx2.md:56("some older clients still buildhttpx2.Clientdirectly") and:90; - the comment at
config/constants.py:2671.
Corrections to the document list of #1381 on d739a47: AGENTS.md has no SSRF paragraph, and .devops/review.md has no SSRF text. The HALLUCINATION-INTERNAL-SERVICE-PRIVATE-NETWORK catalog entry is gone, because #1150 deleted the catalog. This part adds none of them back.
Already done, no change: Valkey GLIDE (#1113) calls vet_addresses at the private level (valkey/client.py:53). The PlaywrightBrowser stub (#887) is gone. Part 4 (#2431) changes the sandbox CIDR builders.
Reproduction Steps
- On
origin/main(d739a47), runrg -n -g '*.py' '_resolve_host_ips|_enforce_non_private_ssrf' src. - Run
rg -n -g '*.py' 'httpx2\.((Async)?Client|get|post|put|patch|delete|head|request|stream)\(' src. - In a test, install
resolver = scripted_resolver(monkeypatch, {"example.com": [[PUBLIC_ADDRESS]]})fromtests/web_fakes.py. - Construct
QdrantClient("http://example.com:6333", allow_private_network=False)(ai/rag/qdrant.py:177), and readresolver.lookups["example.com"].
Expected vs Actual Behavior
Expected: step 1 prints nothing. Step 2 lists only src/devops_cli/http/client.py. Each kept pre-flight caller resolves its host once, through vet_addresses, and its docstring names the gap between that lookup and the dial.
Actual: step 1 lists the two definitions and their five call sites in core/validation.py. Step 2 lists the raw clients that Parts 1 to 3, #1319 and this part move. In step 4, validate_configured_service_url resolves the name through _resolve_host_ips, outside vet_addresses.
Environment Diagnostics
- DevOps CLI Version: 0.8.3 (
origin/maind739a47) - Python Version: 3.14.10
- OS & Architecture: Linux x86_64
- Execution Environment: DevContainer
Logs, Traces, or Terminal Output
src/devops_cli/core/validation.py:378: resolved_ips = _resolve_host_ips(clean_nodot)
src/devops_cli/core/validation.py:411:def _resolve_host_ips(
src/devops_cli/core/validation.py:465: resolved = _resolve_host_ips(clean)
src/devops_cli/core/validation.py:550: resolved_ips = _resolve_host_ips(host)
src/devops_cli/core/validation.py:599:def _enforce_non_private_ssrf(
src/devops_cli/core/validation.py:625: resolved_ips = _resolve_host_ips(host, port=effective_port)
src/devops_cli/core/validation.py:691: _enforce_non_private_ssrf(clean_url, host, parsed.scheme, parsed.port, purpose)Acceptance criteria
These are the criteria of #1381 that apply to this part.
-
rg -n -g '*.py' '_resolve_host_ips|_enforce_non_private_ssrf' srcprints nothing. -
rg -n -g '*.py' 'httpx2\.((Async)?Client|get|post|put|patch|delete|head|request|stream)\(' srclists onlysrc/devops_cli/http/client.py. - Address pre-flight checks remain only at the callers in the table of section 2 and at the sandbox CIDR builders of Part 4. Each one calls
vet_addressesat its level and names its time-of-check gap in a docstring. - The two
rgchecks run as ast-grep rules with rule tests. A rule test fails on a rawhttpx2.Client(...)outsidehttp/client.pyand on a call to a deleted resolve path. -
test_each_caller_dials_at_its_levelintests/test_http_egress.pyhas a row for the AI client base URL, with and withoutai.allow_private_network. A test checks the level of each kept pre-flight caller with and without the flag. The wider row (the config wizard) has a case that fails on the code before the change. - No test patches
_resolve_host_ips:tests/test_validation.pyandtests/test_sandbox_lifecycle.py:537,:593count lookups withScriptedResolver. - Tests stay offline (
ScriptedResolverandConnectRecorderintests/web_fakes.py), and each call phase stays under 1 s. - The documents in section 5 say that every HTTP client is checked at the connect, and that is true when this part merges.
- The required CI checks pass.
Related
- Parent: fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381. This item is Part 5 of 5. fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381 closes when all five parts close.
- Blocked by: fix(ai): the ai service clients dial through the egress-checked factory, and their pre-flight address checks go #2422 (Part 1), fix(k8s): the grafana, prometheus, argo cd and loki clients dial through the egress-checked factory, and their pre-flight address checks go #2424 (Part 2), fix(security): the osv, internetdb, radar and cloudflare api clients dial through the egress-checked factory at the public level #2430 (Part 3), fix(sandbox): the metrics scrape loses its pre-flight address check, and the sandbox address-range builders resolve with vet_addresses #2431 (Part 4) and refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319 (the telemetry clients). Also blocked by fix(ai): replies carry their server as an httpx2 origin, so a password in an AI URL stays out of output, the spend ledger, metrics, spans and cache #1110: this part changes
ai/client/network.pyandai/client/base.py, and fix(ai): replies carry their server as an httpx2 origin, so a password in an AI URL stays out of output, the spend ledger, metrics, spans and cache #1110 changesai/client/*. - Level table and the list of kept pre-flight checks: fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898.
- refactor(security): the egress checks read legacy numeric hosts with getaddrinfo and AI_NUMERICHOST, and the hand-written ipv4 parser goes #2152 changes how
core/validation.pyreads numeric hosts. refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317 changes the Qdrant seam. The one that lands second rebases on the other. - refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 is not a duplicate. It later replaces the factory functions with one HTTP seam. This part finishes the move to the factory that exists now.
Pre-Submission Checklist
- I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
- I have checked existing issues and pull requests to ensure this is not a duplicate.
Source: #1381
Proposed design
Problem statement
The pre-flight DNS resolve paths in core/validation.py resolve a host name before the dial, and the dialler resolves it again. This double-resolution creates a DNS-rebinding window. This part deletes the two resolve paths and their callers, rewires the four kept pre-flight callers to vet_addresses, removes the last raw httpx2 clients, adds ast-grep rules to prevent regression, and updates the documents to state that every HTTP client is checked at the connect.
Acceptance criteria
Requirement: No pre-flight resolve paths
The codebase SHALL contain no definition or call of _resolve_host_ips or _enforce_non_private_ssrf.
Scenario: rg search for deleted functions
- WHEN A developer runs
rg -n -g '*.py' '_resolve_host_ips|_enforce_non_private_ssrf' src - THEN The command prints nothing.
Requirement: No raw httpx2 clients outside the factory
The codebase SHALL construct httpx2.Client or httpx2.AsyncClient only in src/devops_cli/http/client.py.
Scenario: rg search for raw client construction
- WHEN A developer runs
rg -n -g '*.py' 'httpx2\.((Async)?Client|get|post|put|patch|delete|head|request|stream)\(' src - THEN The command lists only
src/devops_cli/http/client.py.
Requirement: Kept pre-flight callers use vet_addresses
Each kept pre-flight caller SHALL call vet_addresses at its egress level and name its time-of-check gap in a docstring.
Scenario: Qdrant caller uses vet_addresses
- WHEN A test constructs
QdrantClientwith aScriptedResolverandallow_private_network=False - THEN The resolver records exactly one lookup of the host name, and the caller's docstring names the gap between the lookup and the dial.
Requirement: ast-grep rules prevent regression
The repository SHALL contain ast-grep rules that fail on a raw httpx2.Client outside http/client.py and on a call to a deleted resolve path.
Scenario: Rule test fails on raw client
- WHEN A rule test file contains
httpx2.Client(...)outsidehttp/client.py - THEN The ast-grep rule reports a match and the test fails.
Requirement: Test coverage for each caller level
test_each_caller_dials_at_its_level SHALL have a row for the AI client base URL with and without ai.allow_private_network, and a test SHALL check the level of each kept pre-flight caller.
Scenario: AI client base URL row with and without the flag
- WHEN A test runs
test_each_caller_dials_at_its_levelwithai.allow_private_networkset and unset - THEN Both rows pass, and the wider row for the config wizard has a case that fails on the code before the change.
Requirement: No test patches deleted functions
No test SHALL patch _resolve_host_ips or _enforce_non_private_ssrf.
Scenario: Tests use ScriptedResolver
- WHEN A test in
tests/test_validation.pyortests/test_sandbox_lifecycle.pycounts DNS lookups - THEN The test uses
ScriptedResolverfromtests/web_fakes.py, not a patch of a deleted function.
Requirement: Tests stay offline
All tests SHALL use ScriptedResolver and ConnectRecorder from tests/web_fakes.py, and each call phase SHALL stay under 1 second.
Scenario: Offline test with scripted resolver
- WHEN A test installs
scripted_resolverand runs a client call - THEN No real network connection is made, and the call phase completes in under 1 second.
Requirement: Documents state connect-time checking
The documents in section 5 SHALL state that every HTTP client is checked at the connect and name the kept pre-flight callers.
Scenario: README states connect-time checking
- WHEN A reader reads the egress section of
README.md - THEN The text states that every HTTP client is checked at the connect and names the kept pre-flight callers.
Requirement: CI checks pass
The required CI checks SHALL pass.
Scenario: CI runs on the pull request
- WHEN The pull request is opened into
main - THEN The
Static AnalysisandTests & Coveragechecks complete with a passing status.
Existing Tool Considered
The egress checking is covered by devops_cli.http.egress (vet_addresses, VettingBackend, AsyncVettingBackend), already built in Parts 1 to 4 of #1381. The static analysis is covered by ast-grep (open source, https://ast-grep.github.io), already in the project's pre-commit config at .pre-commit-config.yaml:78-80. This part does not build new egress code; it deletes the old pre-flight resolve paths and rewires callers to the existing vet_addresses.
Key questions
- What egress level does each kept pre-flight caller use?: Qdrant uses configured, k8s apply uses public, the docker engine uses public or private with the flag, and the config wizard uses configured (wider: loopback without the flag). (best practice) [sources: src/devops_cli/ai/rag/qdrant.py:215, src/devops_cli/commands/k8s/cluster_context.py:197, src/devops_cli/docker/engine.py:368, src/devops_cli/commands/config.py:361]
- Chosen: Use the level from the fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 level table. The body records this decision in its table, and fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 defines the levels for each caller.
- Rejected: Use a single level for all callers. The callers dial different kinds of addresses. A single level would be too wide or too narrow for some of them.
- How to eliminate the raw
httpx2.Client(transport=...)atai/client/base.py:77and:102while keeping the review dry-run preview working?: Add atransportparameter tonew_http_clientandnew_async_http_clientinhttp/client.pyfor test and preview injection. The factory remains the only place that constructshttpx2.Client. The review dry-run preview atai/review/runner.py:247-254passes itshttpx2.MockTransportthrough the factory. (best practice) [sources: src/devops_cli/http/client.py, src/devops_cli/ai/review/runner.py:247-254]- Chosen: Add a transport override parameter to the factory. The factory stays the only constructor of
httpx2.Client. The preview injects itsMockTransportthrough the factory. This meets the acceptance criterion. - Rejected: Keep the raw client for the MockTransport case. Violates the acceptance criterion that no raw client exists outside
http/client.py. - Rejected: Restructure the preview to not need a raw client. The preview needs an in-memory transport. It cannot use the factory's real transport, which dials a real address.
- Chosen: Add a transport override parameter to the factory. The factory stays the only constructor of
- Where do the ast-grep rules and their tests go?: Rules go in
.ast-grep/rules/and rule tests go in.ast-grep/rule-tests/. The pre-commit hook at.pre-commit-config.yaml:78-80runsast-grep-scan. [sources: .pre-commit-config.yaml:78-80] - Which documents need updating to state that every HTTP client is checked at the connect?:
README.md:18and:134,ARCHITECTURE.md:144and:195,SECURITY.md:18,docs/ROUTINE_TASKS.md:257,docs/KNOWN_ISSUES.md:13-15,src/devops_cli/ai/knowledge_base/devops_cli/libraries/httpx2.md:56and:90, and the comment atconfig/constants.py:2671. [sources: README.md:18, ARCHITECTURE.md:144, SECURITY.md:18, docs/KNOWN_ISSUES.md:13-15, src/devops_cli/ai/knowledge_base/devops_cli/libraries/httpx2.md:56] - What is the config wizard's egress level, and why is it wider than the other configured callers?: The wizard uses configured (wider: loopback without the flag). It checks a typed URL and dials nothing, so the wider level catches a loopback URL early without requiring
ai.allow_private_network. (best practice) [sources: src/devops_cli/commands/config.py:361]- Chosen: configured (wider: loopback without the flag). The wizard dials nothing. It only validates a typed URL. The wider level catches a loopback URL early without requiring the flag.
- Rejected: public. The wizard is a configured-service check, not a public check. Using public would refuse loopback URLs that the wizard should accept.
- Does a scheme and syntax check without a DNS lookup stay in
core/validation.py?: Yes. A scheme and syntax check without a lookup can stay where a command needs an early error. Only the DNS resolve paths go. (best practice) [sources: src/devops_cli/core/validation.py]- Chosen: Keep the scheme and syntax check. A command needs an early error for a bad scheme or syntax. The check does not resolve a host name, so it has no TOCTOU gap.
- Rejected: Delete the scheme and syntax check. The check is not a DNS resolve path, but deleting it would remove an early error that a command needs.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 28, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
The change closes a TOCTOU gap by removing double-resolution and ensuring every client is checked at connect time.It is the final part of an approved security split and closes a known double-resolution gap, but no active exploit is reported.It removes a DNS-rebinding window and guarantees every egress path is checked at the dial, which protects all users of the CLI.It deletes two functions and their callers, rewires four caller sites, removes two raw clients, adds two ast-grep rules, and updates docs.Both work on the HTTP client and egress-check architecture, but #1314 consolidates the client factories while this candidate deletes the pre-flight DNS resolve paths and redirects the remaining callers to vet_addresses.fix(ai): the AI service clients dial through the egress-checked facto…
docs(security): name the config init wizard as the exception to the l…
fix(k8s): the grafana, prometheus, argo cd and loki clients dial thro…
fix(sandbox): the metrics scrape and the whitelist NetworkPolicy reso…
fix(security): the osv, internetdb, radar and cloudflare api clients …
refactor(telemetry): OTLP export goes through one exporter seam, and …
devops-cli-service commentedon Oct 29, 2026
Status set to Ready at 38a0a44 (see proposed design in issue body).
chore(main): release 0.26.1 (#2848)