Repository navigation
Description
Problem Description
Part 1 of #1381. The owner approved the split of #1381 into five parts on 2026-10-28.
The AI service clients below build a raw httpx2.Client or call httpx2.get. Most of them check the host name before the dial with a pre-flight check (validate_url_egress, validate_service_url, validate_configured_service_url or validate_url). Some check nothing. httpx2 then resolves the name again at the socket. A rebinding DNS server can give a different address the second time. #898 closed this window for the callers that it moved to the egress-checked factory (devops_cli.http.client). This part moves the AI service callers.
Scope, with lines on origin/main 86d5bce and the level from the #898 level table:
| Caller | Raw client | Pre-flight check that goes | Level |
|---|---|---|---|
| Gateway model info | ai/gateway.py:289 |
ai/gateway.py:286 |
configured |
| Gateway health probe | ai/gateway.py:482 |
ai/gateway.py:473 |
configured (wider: loopback without the flag; metadata refused with it) |
| Backend probe | ai/gateway.py:668 |
ai/gateway.py:607 |
configured (wider, as above) |
devops ai gateway connect probe |
commands/ai_gateway.py:167 |
commands/ai_gateway.py:220 |
private (same as today: the address is a node address from the Kubernetes API, and the command sets ai.allow_private_network itself) |
devops ai gateway load Prometheus query |
ai/pool_load.py:47 |
ai/pool_load.py:43, commands/ai_gateway.py:610 |
configured (see the note below) |
| Embeddings | ai/rag/embeddings.py:439, :681, :775, :916 |
ai/rag/embeddings.py:678, :760, :902, :1138 |
configured |
devops ai cost --source URL |
ai/spend/pricing.py:672 |
none today | configured (narrower: a private source needs the flag) |
| Default pricing registry | ai/spend/pricing.py:684 |
none today | public (narrower) |
| Documentation crawler | ai/library/docs_ingester.py:257 |
ai/library/docs_ingester.py:242, :266 |
public; the flag does not widen it (narrower) |
| pydantic-ai Ollama model | no client: create_ollama_model (called from ai/pydantic_ai_bridge.py:128) gives the provider no http_client, so pydantic-ai builds its own |
ai/models/ollama.py:34 (resolve_dns=True), :73 |
configured (narrower: a private Ollama needs the flag on this path too) |
| Benchmark endpoints | the AI client and the embeddings engine | commands/benchmark.py:75, ai/benchmark/runner.py:225, ai/benchmark/embedding_runner.py:303 |
configured, through the AI client (wider: loopback without the flag) |
| pydantic-ai provider base URL | none: ai/providers/__init__.py:117-118 already uses the factory at configured |
ai/providers/__init__.py:93 |
configured (same) |
"Configured" is loopback, or private when ai.allow_private_network is set (configured_level).
Note on the pool-load query: the #898 table gives the pool-load query the private level and the Prometheus commands, commands/ai_gateway.py among them, the configured level. devops ai gateway load is now the only caller of prometheus_query. Thus the query dials at the level that its caller gives, and the command gives configured.
Out of scope:
ai/client/*, which 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 changes. Part 5 removes the pre-flight atai/client/network.py:584and the two clients around an injected transport atai/client/base.py:77and:102.ai/providers/__init__.py:93if test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331 deletes that module first.
Reproduction Steps
- On
origin/main(86d5bce), runrg -n -g '*.py' 'httpx2\.((Async)?Client|get|post)\(' src/devops_cli/ai/gateway.py src/devops_cli/commands/ai_gateway.py src/devops_cli/ai/pool_load.py src/devops_cli/ai/rag/embeddings.py src/devops_cli/ai/spend/pricing.py src/devops_cli/ai/library/docs_ingester.py. - In a test, install
scripted_resolver(monkeypatch, {"example.com": rebinding(1, "10.0.0.1")})andrecord_connectsfromtests/web_fakes.py. - Without
ai.allow_private_network, probe the gateway athttps://example.com/v1withGatewayRouter.probe_gateway. - Read
recorder.dialled.
Expected vs Actual Behavior
Expected: each caller resolves its host once, at the connect. It dials only the addresses that its level admits. The factory checks each redirect hop the same way.
Actual: step 1 lists the raw clients in the table. In step 4, the pre-flight check passes on the first (public) answer, and httpx2 resolves the name again and dials 10.0.0.1.
Environment Diagnostics
- DevOps CLI Version: 0.8.2 (
origin/main86d5bce) - Python Version: 3.14.10
- OS & Architecture: Linux x86_64
- Execution Environment: DevContainer
Logs, Traces, or Terminal Output
src/devops_cli/ai/gateway.py:289: with httpx2.Client(timeout=2.0) as ephemeral_client:
src/devops_cli/ai/gateway.py:482: with httpx2.Client(timeout=timeout) as client:
src/devops_cli/ai/gateway.py:668: with httpx2.Client(timeout=timeout) as client:
src/devops_cli/ai/library/docs_ingester.py:257: with httpx2.Client(timeout=30.0) as client:
src/devops_cli/ai/pool_load.py:47: with httpx2.Client(timeout=timeout) as client:
src/devops_cli/ai/rag/embeddings.py:439: self._http_client = httpx2.Client(timeout=client_timeout)
src/devops_cli/ai/rag/embeddings.py:681: with httpx2.Client(timeout=timeout) as client:
src/devops_cli/ai/rag/embeddings.py:775: with httpx2.Client(timeout=client_timeout) as client:
src/devops_cli/ai/rag/embeddings.py:916: with httpx2.Client(timeout=client_timeout) as client:
src/devops_cli/ai/spend/pricing.py:672: r = httpx2.get(source_url, timeout=timeout)
src/devops_cli/ai/spend/pricing.py:684: r = httpx2.get(url, timeout=timeout)
src/devops_cli/commands/ai_gateway.py:167: with httpx2.Client(timeout=timeout) as client:Acceptance criteria
These are the criteria of #1381 that apply to this part.
-
rg -n -g '*.py' 'httpx2\.((Async)?Client|get|post|put|patch|delete|head|request|stream)\(' src/devops_cli/ai/gateway.py src/devops_cli/commands/ai_gateway.py src/devops_cli/ai/pool_load.py src/devops_cli/ai/rag/embeddings.py src/devops_cli/ai/spend/pricing.py src/devops_cli/ai/library/docs_ingester.pyprints nothing. - The pydantic-ai Ollama model gets an
http_clientfromnew_async_http_clientat the configured level. - No pre-flight address check remains in the files of the table:
rg -n 'validate_url_egress|validate_service_url|validate_configured_service_url|validate_url\(|resolve_dns=True' <those files>prints nothing. A scheme and syntax check without a lookup can stay where a command needs an early error. -
test_each_caller_dials_at_its_levelintests/test_http_egress.pyhas a row for each caller in the table, with and withoutai.allow_private_network. Each narrower or wider row has a case that fails on the code before the move. - Tests stay offline (
ScriptedResolverandConnectRecorderintests/web_fakes.py), and each call phase stays under 1 s. - If the move makes a document wrong, the same pull request fixes it. The general statement that every HTTP client is checked at the connect waits for Part 5.
- 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 1 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.
- Level table: fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898.
- refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317 and test(ai): Wire rag once in ai/rag, test with edge fakes #1329 change the embedding clients. Whichever lands second builds on the other.
- 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 is closed, so this part moves the documentation crawler, as fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381 says.
- 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 changes
ai/client/*, which this part leaves alone. - 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 moves callers 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 AI service clients in six files build a raw httpx2.Client or call httpx2.get, then check the host name before the dial. A rebinding DNS server can give a different address on the second resolution at the socket. This part moves those callers to the egress-checked factory so the address is vetted at the connect, and removes the now-redundant pre-flight checks.
Acceptance criteria
- Criterion 1: No raw httpx2 client or request call remains in the six in-scope files.
Verification: Runrg -n -g '*.py' 'httpx2\.((Async)?Client|get|post|put|patch|delete|head|request|stream)\(' src/devops_cli/ai/gateway.py src/devops_cli/commands/ai_gateway.py src/devops_cli/ai/pool_load.py src/devops_cli/ai/rag/embeddings.py src/devops_cli/ai/spend/pricing.py src/devops_cli/ai/library/docs_ingester.pyand confirm it prints nothing. - Criterion 2: The pydantic-ai Ollama model receives an http_client from new_async_http_client at the configured level.
Verification: Inspectai/models/ollama.pyandai/pydantic_ai_bridge.py:128to confirmcreate_ollama_modelpasses anhttp_clientbuilt bynew_async_http_client(level=configured_level(...)). - Criterion 3: No pre-flight address check remains in the in-scope files.
Verification: Runrg -n 'validate_url_egress|validate_service_url|validate_configured_service_url|validate_url\(|resolve_dns=True' src/devops_cli/ai/gateway.py src/devops_cli/commands/ai_gateway.py src/devops_cli/ai/pool_load.py src/devops_cli/ai/rag/embeddings.py src/devops_cli/ai/spend/pricing.py src/devops_cli/ai/library/docs_ingester.pyand confirm it prints nothing. A scheme and syntax check without a DNS lookup may remain where a command needs an early error. - Criterion 4: test_each_caller_dials_at_its_level has a row for each caller in the table, with and without ai.allow_private_network.
Verification: Runpytest tests/test_http_egress.py::test_each_caller_dials_at_its_level -vand confirm a row exists for each of the twelve callers, each tested with the flag set and unset. Each narrower or wider row has a case that fails on the code before the move. - Criterion 5: Tests stay offline and each call phase stays under 1 s.
Verification: Runpytest tests/test_http_egress.py -v --timeout=5and confirm all tests pass using ScriptedResolver and ConnectRecorder from tests/web_fakes.py, with no network access and no test exceeding 1 s. - Criterion 6: If the move makes a document wrong, the same pull request fixes it.
Verification: Search the repository for statements that claim every HTTP client is checked at the connect. Confirm the general statement waits for Part 5 and is not added here. Fix any document that is now inaccurate. - Criterion 7: The required CI checks pass.
Verification: Confirm Static Analysis, Tests & Coverage, and Semantic PR title checks all report a passing status on the pull request.
Key questions
- What egress level does each caller in the table use?: Gateway model info, gateway health probe, backend probe, embeddings, devops ai cost --source URL, and benchmark endpoints use configured. The devops ai gateway connect probe uses private. The default pricing registry uses public. The documentation crawler uses public (the flag does not widen it). The pool-load query uses configured. The Ollama model uses configured. [sources: src/devops_cli/ai/gateway.py:286, src/devops_cli/ai/gateway.py:473, src/devops_cli/ai/gateway.py:607, src/devops_cli/commands/ai_gateway.py:220, src/devops_cli/ai/pool_load.py:43, src/devops_cli/ai/rag/embeddings.py:678, src/devops_cli/ai/spend/pricing.py:672, src/devops_cli/ai/spend/pricing.py:684, src/devops_cli/ai/library/docs_ingester.py:242, src/devops_cli/ai/models/ollama.py:34, src/devops_cli/commands/benchmark.py:75]
- What level does the pool-load query dial at, given that the fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 table gives it the private level but devops ai gateway load is its only caller?: The query dials at the level its caller gives. devops ai gateway load gives configured. Thus the pool-load query dials at configured, not private. (proposed) [sources: src/devops_cli/ai/pool_load.py:47, src/devops_cli/commands/ai_gateway.py:610]
- Are the ai/client/ files in scope for this part?*: No. 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 changes ai/client/. Part 5 of fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381 removes the pre-flight at ai/client/network.py:584 and the two clients at ai/client/base.py:77 and :102. This part leaves ai/client/ alone. (proposed) [sources: src/devops_cli/ai/client/network.py:584, src/devops_cli/ai/client/base.py:77]
- Is ai/providers/init.py:93 in scope?: No, if test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331 deletes that module first. If test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331 has not landed, the line already uses the factory at configured level, so no change is needed here. (proposed) [sources: src/devops_cli/ai/providers/init.py:117]
- How does the Ollama model get its http_client?: create_ollama_model is called from ai/pydantic_ai_bridge.py:128 and gives the provider no http_client, so pydantic-ai builds its own. The fix passes an http_client from new_async_http_client at the configured level. A private Ollama needs ai.allow_private_network set on this path. [sources: src/devops_cli/ai/pydantic_ai_bridge.py:128, src/devops_cli/ai/models/ollama.py:34, src/devops_cli/ai/models/ollama.py:73]
- What factory functions does this part use?: new_http_client and new_async_http_client from devops_cli.http.client, which fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 established. The factory swaps httpx2's pool for a vetting httpcore2 pool that resolves the host once at the connect and checks each address against the level. [sources: src/devops_cli/http/client.py, tests/test_http_egress.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
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 candidate closes a TOCTOU DNS rebinding vulnerability in AI service callers by routing them through the egress-checked factory.A security vulnerability with a concrete reproduction path affects multiple AI service callers.It removes a DNS rebinding attack window for gateway probes, embeddings, pricing, and other AI service calls.The pattern is set by #898, but the candidate lists over ten call sites across six files to migrate.Both items work on the HTTP client layer, but #1314 unifies the three client factories into one seam while the candidate moves specific AI callers to the existing egress-checked factory.dan-petty commentedon Oct 28, 2026
Status set to Ready at 73d1807 (see proposed design in issue body).
fix(k8s): the grafana, prometheus, argo cd and loki clients dial thro…