fix(mcp): security hardening#54
Merged
Merged
Conversation
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.
Summary
Re-aligns Corex MCP with the upstream Tidewave security model (
tidewavev0.5.6) and fixes Corex-specific regressions. Corex MCP stays read-only (component discovery only); no Tidewave eval/SQL/log tools are added.X-Frame-Optionsrewriting on non-MCP routes (Corex has no embedded browser client, unlike Tidewave)source_pathviaCorex.MCP.root/0instead of absolute filesystem paths/corex/configJSON to reduce fingerprintingplug Corex.MCPraises in:produnlessforce: trueMotivation
Corex MCP is forked from Dashbit's Tidewave MCP transport. A security review found several divergences from upstream and unnecessary behavior inherited without Tidewave's embedded client use case. This PR brings Corex in line with Tidewave where appropriate and hardens areas specific to Corex (path disclosure, tool validation, prod mounting).
Changes
Plug (
lib/mcp/plug.ex)register_before_sendCSP rewrite andX-Frame-Optionsdeletion on all non-/corexresponsesCorex.MCP.root/0for project-root resolution (config :corex, mcp_root: ...)Server.init_tools/0once ininit/1validate!/1on every request (Tidewave parity):produnlessforce: trueis passedServer (
lib/mcp/server.ex)init_tools/0fromhandle_http_message/1:publicfrom the ETS table (matches upstream)tidewavev0.5.6Component docs (
lib/mcp/component_docs.ex)source_pathis now relative toCorex.MCP.root/0Router (
lib/mcp/router.ex)/corex/configno longer exposesallow_remote_accessTools
list_components: rejects non-empty argument mapsget_component: requires exactlyid(string, max 64 bytes); unknown keys rejectedinstallation_guide: invalid or unknownscenario/ extra keys return{:error, :invalid_arguments}Docs (
guides/MCP.md)mcp_root/forceoptionsIntentionally unchanged (Tidewave parity)
allow_remote_access: falsedefault/corex/mcpand/corex/configproject_eval, SQL, logs, etc.)Test plan
mix test test/corex/mcp(53 tests)mix lintmix test e2e/test/e2e_web/corex_mcp_test.exshttp://localhost:4000/corex/mcp;list_componentsandget_componentworkX-Frame-Optionswhenplug Corex.MCPis mounted