Repository navigation
Studio: two ways past the stdio MCP UI-session gate - #8551
Conversation
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Follow-up to #8550, which put local (stdio) MCP commands behind a UI session on every route that defines one. Two paths still let an sk-unsloth API key around it. GET /api/mcp/servers/ returns stored rows verbatim. For a stdio row both fields are secrets: url is the argv, which carries credentials often enough that stdio_log_id exists so it is never logged raw, and headers is the subprocess env. A key that may not define a command could still read back one the owner had defined, tokens included. Listing now drops stdio rows for API-key callers. Dropping the row rather than blanking its fields also keeps a redacted url from round-tripping into update as a bogus command. http(s) rows are untouched, headers included, and a UI session still sees everything. mcp_server.py calls the validate route function directly, so the ViaApiKey dependency never runs and its `= False` default reads as a UI session. The /mcp surface is a remote static bearer, so it could validate a recipe carrying a stdio provider, which discovers that provider's tools and starts the command. It now passes via_api_key = True explicitly. Tests: the listing hides the stdio row from a key with the argv and env secrets asserted absent from the serialized response, shows both to a session, keeps http headers visible to a key, and pins the call site that has to hand in the flag.
c415fda to
6172680
Compare
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
A stdio MCP server is a local command. The MCP client parses the stored address into argv and hands it to FastMCP's
StdioTransport, which starts the process as the backend user, outside the tool sandbox. That is the intended feature for someone sitting at their own machine, and this PR keeps it that way: a loopback bind still defaults it on, so the MCP Servers dialog works with no env var, exactly as before.What was not intended is the credential that could reach it.
The problem
Every route in
routes/mcp_servers.pydepends only onget_current_subject, which accepts ansk-unslothAPI key as readily as the UI's session JWT. That key is the remote, long-lived, exportable one. We hand it out for programmatic access and for Cloudflare remote access, and the README says so plainly:So a leaked inference key could
POST /api/mcp/servers/testwith a command in theurlfield and have it spawned on the spot, with no storage round trip:Sandboxed tool execution and arbitrary local process execution are different grants, and only the first one was ever offered.
POST /api/data-recipe/mcp/toolswas the same hole in a cleaner form:command,argsandenvcome straight from the request body and are spawned immediately.The fix
Gate the command paths on an interactive UI session, reusing
require_ui_sessionfromroutes/provider_credentials.pyrather than inventing a mechanism.create,update,import,testandrefreshnow takeauthenticated_via_api_keyand run a new_guard_stdio. The guard fires only when the address is a stdio command. Anhttp(s)MCP server is data rather than code, so managing one stays open to API keys.updatekeys off the resulting address or the stored row, not just the payload. Editing a stdio row is privileged even when no url is sent, since it can re-enable the row or rewrite the env the subprocess is handed.importapplies the guard per entry, inside the existing per-entry error handling, so an API key's http entries still import instead of the whole batch failing._validate_url, so a host with stdio disabled keeps answering 400 rather than 403. The response does not reveal whether the gate is open./api/data-recipe/mcp/toolsgets the same rule, reported per provider so http providers in the same request still list.deleteandlistare deliberately left open. One de-privileges, the other is read-only, and gating delete would strand rows for API-only clients.Each registration or probe now writes one audit line carrying
stdio_log_id(executable basename plus a short digest), never the raw address, the argv or the headers. Argv routinely carries credentials, and for a stdio rowheaders_jsonis the subprocess environment._stdio_log_idloses its underscore so the routes can share that redaction.What deliberately did not change
The loopback auto-default stays. Removing it would have meant every local Studio and Desktop user had to set an environment variable and restart before adding an MCP server, which fixes the hole by breaking the feature.
No frontend change. The MCP Servers dialog and the desktop app both authenticate with a session JWT, so a local user adding
npx -y @modelcontextprotocol/server-filesystem /tmpsees no difference: same field, same Test connection button, no env var, no new prompt.No other caller is affected. The CLI, the Tauri Rust side and the Colab notebook never call these routes, and the internal keys minted by Deep Research and data recipe jobs only ever reach
/v1.The chat path is untouched. An API key can still invoke stdio MCP tools that a UI session already registered, which is the documented "Studio as an API server with my tools" flow.
--disable-toolsandenabled_toolsremain the lever there.Nothing here is stateful: no new setting, no schema change, no migration, so re-running is a no-op.
Tests
291 pass across the MCP, tool policy and provider suites. New coverage:
test_http_management_still_open_to_api_keys: create, update, test and refresh onhttps://x/mcpall still succeed with an API keyRoute handlers are called directly in tests, so an omitted
via_api_keyreceives theDependssentinel, which is truthy and fails closed. Existing stdio call sites now passvia_api_key = False.