Skip to content

fix(security): purge the search index when quarantine arrives via config - #1062

Merged
Dumbris merged 2 commits into
mainfrom
fix/1061-quarantine-index-purge
Aug 26, 2026
Merged

Dumbris merged 2 commits into
mainfrom
fix/1061-quarantine-index-purge

Conversation

@Dumbris

@Dumbris Dumbris commented Aug 26, 2026

Copy link
Copy Markdown
Member

Fixes #1061.

What was wrong

Quarantining a server by editing the config file left every one of its tools in the Bleve index. retrieve_tools then returned their names, full descriptions and a call_with variant as ordinary callable results. The call itself was still refused, so this is a disclosure bug rather than an execution one — but disclosure of untrusted tool descriptions is exactly what quarantine exists to prevent, since that is where a Tool Poisoning Attack payload lives.

The description-bearing branch of the search path has no query-time quarantine filter. Absence from the index is the control, and the code says so (internal/server/mcp.go):

Quarantined tools are deliberately absent from the search index: their untrusted descriptions/schemas are withheld so a Tool Poisoning Attack payload is never exposed to the agent. The loop above therefore can never surface them…

The same block already anticipates index lag — but only as "the brief window after a runtime quarantine toggle when a tool may still linger in the index". On the config path that window never closed.

Root cause

The purge was bolted onto the API handler rather than onto the state transition.

  • Runtime.QuarantineServer called indexManager.DeleteServerTools + reindexAffectedProfiles under an explicit // Security: comment.
  • LoadConfiguredServers — the disk-reload path — detected the same transition (it is part of the hasChanged test and is logged as quarantined_changed: true) and acted only on oauthChanged.
  • The orphan sweep did not cover it either: it removes servers no longer in config, not servers still configured but newly quarantined.

So every writer other than the one API handler inherited the hole — an operator edit, and the config-load admission gate re-holding an unreviewed server.

Fix

Extract purgeQuarantinedServerFromIndex and call it from both paths, keyed on the false → true transition.

  • Purging whenever the flag is true would re-delete on every unrelated reload.
  • Purging on true → false would blank the catalog until the next discovery pass.
  • The API path does not purge twice: it writes storage before reloading, so the reload sees no transition.

Tests

Three, asserting the property — "a quarantined server has no tools in the index" — against both writers rather than the implementation of either, so a future third path cannot quietly reintroduce the hole:

Test Before After
TestQuarantineViaConfigReload_PurgesToolsFromIndex ❌ fails (2 tools left indexed) ✅
TestQuarantineViaAPI_StillPurgesToolsFromIndex ✅ ✅
TestUnquarantineViaConfigReload_LeavesIndexAlone ✅ ✅

go test ./internal/runtime -race green (152s). golangci-lint run --config .github/.golangci.yml ./internal/runtime/... → 0 issues.

Live verification

Isolated core, scratch --config and --data-dir, real @modelcontextprotocol/server-memory upstream:

Step Before this PR After
indexed, /index/search?q=knowledge+graph 5 hits 5 hits
write "quarantined": true into the config file 5 hits 0 hits
retrieve_tools for a matching query all 9 tools, full descriptions, call_with nothing
purge log line absent emitted once

Not in scope

Fixes #1061.

Quarantining a server by editing the config file left every one of its tools in
the Bleve index. retrieve_tools then returned their names, full descriptions and
a call_with variant as ordinary callable results, until something else happened
to reindex. The call was still refused, so this is disclosure rather than
execution - but disclosure of untrusted tool descriptions is precisely what
quarantine exists to prevent, since that is where a Tool Poisoning Attack
payload lives.

The description-bearing branch of the search path has no query-time quarantine
filter; absence from the index IS the control, and the code says so
(internal/server/mcp.go: "Quarantined tools are deliberately absent from the
search index ... The loop above therefore can never surface them"). The same
block already anticipates index lag, but only as "the brief window after a
runtime quarantine toggle". On the config path that window never closed.

Root cause: the purge was bolted onto the API handler rather than onto the state
transition. Runtime.QuarantineServer called indexManager.DeleteServerTools under
an explicit Security comment; LoadConfiguredServers detected the very same
transition - it is in the hasChanged test and logged as quarantined_changed:true
- and acted only on oauthChanged. The orphan sweep did not cover it either: it
removes servers no longer in config, not servers still configured but newly
quarantined.

Fix: extract purgeQuarantinedServerFromIndex and call it from both paths, keyed
on the false -> true transition. Doing it whenever the flag is true would
re-delete on every unrelated reload; doing it on true -> false would blank the
catalog until the next discovery pass. The API path is unaffected in practice
because it writes storage before reloading, so the reload sees no transition and
does not purge twice.

Tests assert the property against both writers rather than the implementation of
either, so a future third path cannot quietly reintroduce the hole, plus the
un-quarantine direction which must NOT purge.

Verified live on an isolated core: with a connected memory server indexed (5 hits
for "knowledge graph"), writing "quarantined": true into the config file drops
the index to 0, logs the purge once, and retrieve_tools surfaces nothing - where
before it returned all nine tools with their descriptions.

Disabling via the config file was already correct (a disabled server drops out of
the active set the orphan sweep uses) and is unchanged.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: b901c89
Status: ✅  Deploy successful!
Preview URL: https://f6383c1d.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-1061-quarantine-index-pu.mcpproxy-docs.pages.dev

View logs

…storage

Widens the #1061 purge condition from "false -> true transition" to "quarantined
AND (not in the stored view OR previously not quarantined)".

The added arm is not redundant. LoadConfiguredServers flattens a FAILED storage
read into an empty stored view — it only keeps the distinction for the admission
gate — so on a read failure every configured server looks first-seen while the
index still holds the previous run's tools. Keyed solely on the transition, a
quarantined server would keep its descriptions searchable for exactly as long as
storage stayed unreadable.

Cost on the ordinary path is a no-op: a genuinely first-seen server has nothing
indexed, and reindexAffectedProfiles early-returns when no profile exists and
otherwise rebuilds only profiles that actually contain the server.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 56.25000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/runtime/lifecycle.go 56.25% 5 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/1061-quarantine-index-purge

Available Artifacts

  • archive-darwin-amd64 (29 MB)
  • archive-darwin-arm64 (26 MB)
  • archive-linux-amd64 (17 MB)
  • archive-linux-arm64 (15 MB)
  • archive-windows-amd64 (29 MB)
  • archive-windows-arm64 (25 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (23 MB)
  • installer-dmg-darwin-arm64 (21 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 32979870668 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit d5b28dd into main Aug 26, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: quarantining a server via the config file leaves its tools in the search index, so retrieve_tools still discloses their descriptions

2 participants