Skip to content

MCP server: cap client strings in the info log and give clients unguessable task ids #1722

Backlog

Description

@smart-ssh-planner

Goal

MCP clients cannot fill the app log with arbitrarily long strings, and one MCP client cannot read or cancel a task that the app created for another client just by declaring the same client name.

Context

Log

  • crates/mcp-server/src/tool_server.rs:303-309 (run_confirmable_response): logs client = ?client_name at info. This is the raw clientInfo.name from client_name() (:254-258), before normalize_client_name (which trims and cuts to 64 characters, crates/app-logic/src/mcp_sessions.rs:71-78) runs in call_context (:250). A client can send a name of any length and it is logged in full on every call.
  • tool_server.rs:572-575 (get_server_notes): logs server_id = %server_id at info before parse_server_id (:577), so any client string is logged unbounded. In run_confirmable_response the id is parsed first (:300), so only valid UUIDs reach the log there.
  • The file logger writes JSON (crates/app-logic/src/logging.rs:300-304), so control characters are escaped; the problem is size, not forged lines. Spec 0094 (no content in default logs) applies.

Tasks

  • ExtensionSet::answer_as_task (crates/mcp-server/src/extension.rs:563-601) stores the task under the id chosen by the extension (answer.task.task_id) and returns that id to the client unchanged.
  • task_owner (extension.rs:604-624) lets tasks/get and tasks/cancel (tool_server.rs:693-717) reach a task when the caller's normalised client name equals the creator's (:619). The client name is self-declared (clientInfo.name); ADR 0109 Decision 2 states it separates workspaces and is not an authorisation. All clients share one token.
  • So any client that knows or guesses a task id and declares the same name (or no name) can read or cancel that task. The core does not require task ids to be unguessable.
  • THREAT-MODEL.md:380-384 says tasks/get and tasks/cancel "only reach tasks created for the same client", without saying that the client identity is self-declared.

Requirements

  • Every info/warn/error log field in crates/mcp-server/src/tool_server.rs that carries a client-supplied string logs at most a bounded prefix: the client name is logged in its normalised form (≤ 64 characters), and get_server_notes logs the server id only after parse_server_id succeeded (an invalid id is logged as invalid, without its text).
  • The core gives MCP clients its own task id instead of the extension's: a random id with at least 122 bits of entropy (UUID v4), generated by the core when it registers the task. tasks/get and tasks/cancel look up the task by this id and call the extension hooks with the extension's own id, so the extension API (McpExtension) does not change. Every task object the client receives (the answer to the tool call and the result of tasks/get) carries the core's id.
  • The client-name check in task_owner stays as an additional check.
  • Existing duplicate-id handling, TTL expiry and session-close cleanup keep working with the new mapping.
  • THREAT-MODEL.md (MCP tasks paragraph) states that the client name is self-declared and that a task is reachable only with its unguessable id; Spec 0028 describes the core-issued task id.

Acceptance Criteria

  • A tool call with a clientInfo.name of 1 MiB produces log lines whose client field is at most 64 characters (test with a captured tracing subscriber)
  • get_server_notes with a 1 MiB server_id returns the invalid-id error and the log line does not contain the id text
  • The task id returned to the client differs from the id the extension returned and is a UUID v4; two tasks get different ids
  • tasks/get and tasks/cancel with the returned id reach the extension hook with the extension's own id (test in crates/mcp-server/tests/tasks.rs)
  • tasks/get / tasks/cancel with the extension's own id, or with a returned id from a client with another name, give not-found
  • TTL expiry and session close remove the mapping (existing tests adapted, still green)
  • Without extensions nothing changes
  • Relevant automated tests pass

Technical Notes

  • Security-critical module (crates/mcp-server/). No change to the filter engine, the confirmation flow or the token check; MCP origin still forces confirmation.
  • Spec 0094 A1.6 (tool name only, never arguments) stays as is.
  • User-visible as a security change: add a changelog fragment.

Files: crates/mcp-server/src/tool_server.rs, crates/mcp-server/src/extension.rs, crates/mcp-server/src/tool_server/tests.rs, crates/mcp-server/tests/tasks.rs, docs/specs/0028-mcp-server-integration.md, THREAT-MODEL.md, changelog.d/

Spec impact: update 0028

Open questions

  • Where to keep the id mapping: (a) replace the map key in ExtensionSet::tasks by the core id and store the extension's id in TaskOwner, (b) a second map. Recommendation: (a), one map, one lookup.

Related Work

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmcpsecurity

    Type

    Fields

    Priority

    P2 - Normal

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions