Skip to content

fix(security): the pre-flight resolve paths go, the kept pre-flight checks call vet_addresses, and the docs say every http client is checked at the connect #2437

Description

@dan-petty

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) under validate_url_egress (:560), and validate_url (:644, :691). The resolve_dns parameters 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 in http/validation.py and http/__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 names validate_service_url() and validate_configured_service_url();
  • the knowledge base page src/devops_cli/ai/knowledge_base/devops_cli/libraries/httpx2.md:56 ("some older clients still build httpx2.Client directly") 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

  1. On origin/main (d739a47), run rg -n -g '*.py' '_resolve_host_ips|_enforce_non_private_ssrf' src.
  2. Run rg -n -g '*.py' 'httpx2\.((Async)?Client|get|post|put|patch|delete|head|request|stream)\(' src.
  3. In a test, install resolver = scripted_resolver(monkeypatch, {"example.com": [[PUBLIC_ADDRESS]]}) from tests/web_fakes.py.
  4. Construct QdrantClient("http://example.com:6333", allow_private_network=False) (ai/rag/qdrant.py:177), and read resolver.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/main d739a47)
  • 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' src prints nothing.
  • rg -n -g '*.py' 'httpx2\.((Async)?Client|get|post|put|patch|delete|head|request|stream)\(' src lists only src/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_addresses at its level and names its time-of-check gap in a docstring.
  • The two rg checks run as ast-grep rules with rule tests. A rule test fails on a raw httpx2.Client(...) outside http/client.py and on a call to a deleted resolve path.
  • test_each_caller_dials_at_its_level in tests/test_http_egress.py has a row for the AI client base URL, with and without ai.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.py and tests/test_sandbox_lifecycle.py:537, :593 count lookups with ScriptedResolver.
  • Tests stay offline (ScriptedResolver and ConnectRecorder in tests/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

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 QdrantClient with a ScriptedResolver and allow_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(...) outside http/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_level with ai.allow_private_network set 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.py or tests/test_sandbox_lifecycle.py counts DNS lookups
  • THEN The test uses ScriptedResolver from tests/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_resolver and 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 Analysis and Tests & Coverage checks 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]
  • How to eliminate the raw httpx2.Client(transport=...) at ai/client/base.py:77 and :102 while keeping the review dry-run preview working?: Add a transport parameter to new_http_client and new_async_http_client in http/client.py for test and preview injection. The factory remains the only place that constructs httpx2.Client. The review dry-run preview at ai/review/runner.py:247-254 passes its httpx2.MockTransport through 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 its MockTransport through 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.
  • 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-80 runs ast-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:18 and :134, ARCHITECTURE.md:144 and :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:56 and :90, and the comment at config/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

#2422, #2424, #2430, #2431, #1319, #1110

Activity

  1. added
    source/agent
    type/security
    on Oct 28, 2026
  2. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/security. The change closes a TOCTOU gap by removing double-resolution and ensuring every client is checked at connect time.
    • Priority: P2-Medium. It is the final part of an approved security split and closes a known double-resolution gap, but no active exploit is reported.
    • Value: High. It removes a DNS-rebinding window and guarantees every egress path is checked at the dial, which protects all users of the CLI.
    • Effort: Medium. It deletes two functions and their callers, rewires four caller sites, removes two raw clients, adds two ast-grep rules, and updates docs.
    • Related: refactor(cli): Unify HTTP and DNS seams with shared fakes #1314, which asks for a different change. 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.
  3. added
    priority/p2-medium
    status/new
    effort/medium
    value/high
    on Oct 28, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 29, 2026
  5. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 38a0a44 (see proposed design in issue body).

  6. added
    type/bug
    scope/security
    status/in-progress
    status/in-review
    and removed
    type/security
    status/ready
    status/in-progress
    on Oct 30, 2026
  7. removed
    status/in-review
    on Oct 31, 2026
  8. added a commit that references this issue on Oct 31, 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

    effort/mediumpriority/p2-mediumscope/securitysource/agenttype/bugvalue/high

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions