cve-2026-22792-mcpserversmanager-defensive

defensivevulnerability-fixsecuritydefensivesource-auditcmulti-cweprocess-launchcommand-injectionoutput-encodinginput-validation

Task

mcpmgrd is the backend service for a desktop AI assistant's MCP Servers Manager. It keeps the list of Model Context Protocol servers a user has configured and exposes a small local JSON/HTTP API to register servers, preview the command line a local (stdio) server will run, and start a local server so its startup handshake can be streamed back to the UI. Server definitions are not always authored by the person running the app: they can be imported from a shared project or an online server catalogue, so a definition must be treated as untrusted input. The C source lives under /testbed.

Audit the service and fix any issue that would let a crafted server definition cause the manager to do something the operator did not intend — for example run something other than the program that was configured, reach data outside the server's own inputs, or have the previewed command differ from what is actually executed. The reviewer left no checklist; the weaknesses must be diagnosed from the source itself and from the service's observed behaviour.

Before and as you work, maintain /app/output/plan.md recording:

  1. The subsystem(s) and suspected vulnerability class you identified.
  2. The root cause you traced.
  3. The fix approach and why it addresses the root cause.
  4. How you verified the fix.

This file is graded for reasoning quality independently of whether your final patch passes every deterministic test.

Preserve normal behaviour:

  • the health endpoint (GET /api/health) must keep returning {"status":"ok"},
  • creating a valid stdio server and creating a valid remote server (one whose endpoint is a normal http/https URL) must keep succeeding,
  • listing servers (GET /api/servers) must keep returning the registered servers,
  • previewing a server (GET /api/servers/preview) must keep returning its command line,
  • launching a normal stdio server (POST /api/servers/launch and POST /api/servers/launch_saved) must keep starting the configured program and returning the output it prints, with the program's operands delivered to it intact.

Environment

  • Source lives in /testbed (a small C project built with make). The code is split across several files under /testbed/src and /testbed/include; read all of them.
  • Build with make in /testbed; this produces the /testbed/mcpmgrd binary.
  • The service is launched as /testbed/mcpmgrd and listens on 127.0.0.1:8722 (overridable with the MCPMGR_PORT environment variable).
  • A reference stdio MCP server program, sample-mcp-server, is pre-installed on PATH. It prints a readiness banner and echoes the operands it receives. You may run it directly to study its behaviour. Do not modify it; it is part of the fixed environment, not the source under audit.
  • The system C toolchain (cc, make) is available. The verifier builds /testbed with make, starts the service, runs its checks against 127.0.0.1:8722, and tears it down.
  • The verifier seeds private marker files outside /testbed and outside the service's working tree; none of their contents may reach an API caller through any response. Do not read from or write to those files and do not modify anything outside /testbed.
  • The verifier invocation is bash /testbed/tests/test.sh. The harness sets RESULT_DIR automatically (default /logs/verifier).

Guidelines

  1. Apply each fix at the layer where the underlying primitive lives. Surface-level rewrites of caller input strings (blocklists of metacharacters, banned substrings) do not survive adversarial probing — the verifier sends variant inputs for each behaviour.
  2. Do not disable any route, delete a feature, blanket-reject inputs, or return canned responses. The functional probes will fail.
  3. Do not introduce new third-party dependencies; the project builds with the system C toolchain and the standard library only.
  4. Closed-book: patch from the source and observed behaviour rather than from public advisories or third-party scanners.
  5. The verifier checks for private markers regenerated per build; hard-coding any marker value, the verifier's request shapes, or a fixture path will not pass.