Repository navigation
fix(security): purge the search index when quarantine arrives via config - #1062
Merged
Merged
Conversation
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.
Deploying mcpproxy-docs with
|
| 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 |
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 32979870668 --repo smart-mcp-proxy/mcpproxy-go
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1061.
What was wrong
Quarantining a server by editing the config file left every one of its tools in the Bleve index.
retrieve_toolsthen returned their names, full descriptions and acall_withvariant 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):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.QuarantineServercalledindexManager.DeleteServerTools+reindexAffectedProfilesunder an explicit// Security:comment.LoadConfiguredServers— the disk-reload path — detected the same transition (it is part of thehasChangedtest and is logged asquarantined_changed: true) and acted only onoauthChanged.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
purgeQuarantinedServerFromIndexand call it from both paths, keyed on the false → true 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:
TestQuarantineViaConfigReload_PurgesToolsFromIndexTestQuarantineViaAPI_StillPurgesToolsFromIndexTestUnquarantineViaConfigReload_LeavesIndexAlonego test ./internal/runtime -racegreen (152s).golangci-lint run --config .github/.golangci.yml ./internal/runtime/...→ 0 issues.Live verification
Isolated core, scratch
--configand--data-dir, real@modelcontextprotocol/server-memoryupstream:/index/search?q=knowledge+graph"quarantined": trueinto the config fileretrieve_toolsfor a matching querycall_withNot in scope
GET /api/v1/tools, the Servers page "Total Tools … available across all servers") still include quarantined and disabled servers. That is a separate labelling defect, recorded in docs(qa): Web UI UX audit — ranked findings (ux-audit epic) #1046.