Skip to content

M64 (TASK-121-FREE): Hardened --live MCP Sandboxing & .verity/mcp-lock.json Supply-Chain Pinning

1. Purpose & Architectural Decisions

  • Problem (P1.3): Probing arbitrary untrusted stdio MCP servers (--live / --live-probe / --detect-bait-and-switch) exposes the host to shell injection, env-var secret exfiltration, runaway subprocesses, and silent upstream schema mutations.
  • Transport Hardening: StdioDiscoveryTransport gains a pre-spawn shell denylist (sh, bash, zsh, cmd.exe, powershell, -c, eval) that fails closed unless --allow-untrusted-exec is passed, a stripped env allowlist, an isolated tempfile.TemporaryDirectory() for TMPDIR/HOME (so children cannot read $HOME secrets), a 1 MiB line cap, a 10s timeout, start_new_session=True, and guaranteed os.killpg process-group teardown in finally:.
  • OS Sandbox Enforcement: optional sandbox-exec (macOS) / bwrap (Linux) wrappers; --require-os-sandbox fails closed when the sandbox binary is unavailable.
  • Deterministic Supply-Chain Pinning: verity lock [--verify-only] writes .verity/mcp-lock.json pinning command_spec_sha256, declared_package_version, server_info, and per-tool description_sha256, input_schema_sha256, tool_sha256.
  • Diff Semantics: config declared_package_version + command_spec_sha256 changed → mcp-version-upgrade (info/low); command_spec_sha256 unchanged while tool_sha256 changed → mcp-schema-drift (critical/high, exit 1).
  • Free/Open-Core Boundary: pure Open-Core hardening; zero Pro dependencies.

2. Target Files

File Change
src/verity/discovery/transports/stdio.py Shell denylist + --allow-untrusted-exec gate, env allowlist, isolated TMPDIR/HOME, 1 MiB line cap, 10s timeout, start_new_session=True, os.killpg teardown, OS sandbox wrapping
src/verity/ucp/lockfile.py New .verity/mcp-lock.json model, canonical hash helpers, and mcp-version-upgrade / mcp-schema-drift classification
src/verity/discovery/auditor.py Surface lock verification findings through the auditor path
src/verity/cli.py Add verity lock / verity lock --verify-only, --allow-untrusted-exec, --require-os-sandbox
tests/unit/test_stdio_sandbox_and_mcp_lock.py Unit tests for sandbox isolation, sandbox-required fail-closed, and lock diff classification

3. ATDD Traceability Matrix

AC ID Acceptance Criterion Paired Benign / Negative Control Verification Tier Test Target
AC-64.1 StdioDiscoveryTransport blocks shell wrappers (sh, bash, -c, eval) by default unless --allow-untrusted-exec is passed, strips parent secret env vars, isolates TMPDIR/HOME, enforces the 1 MiB line cap, and tears down process groups via os.killpg. Benign control: allowlisted stdio server (python -m ...) runs cleanly; --allow-untrusted-exec unblocks the shell form. unit tests/unit/test_stdio_sandbox_and_mcp_lock.py::test_stdio_transport_blocks_shell_wrappers_and_isolates_env
AC-64.2 OS sandbox wrapper (sandbox-exec / bwrap) wraps the command when enabled; --require-os-sandbox fails closed if the sandbox binary is unavailable. Benign control: sandbox-disabled path spawns the bare command; unavailable binary + --require-os-sandbox returns a hard failure. unit tests/unit/test_stdio_sandbox_and_mcp_lock.py::test_stdio_transport_os_sandbox_requirement_fails_closed
AC-64.3 verity lock writes .verity/mcp-lock.json with canonical hashes; verity lock --verify-only classifies version + command_spec_sha256 change as mcp-version-upgrade (info/low) and unchanged command_spec_sha256 + changed tool_sha256 as mcp-schema-drift (critical/high, exit 1). Paired control: byte-identical lock file yields zero findings and exit 0. unit tests/unit/test_stdio_sandbox_and_mcp_lock.py::test_mcp_lock_verify_classifies_upgrade_and_schema_drift
AC-64.4 Ruff linter and full unit test suite pass cleanly. Clean workspace yields zero lint errors. ruff uv run ruff check src tests && uv run pytest tests/

4. Verification Commands

uv run pytest tests/unit/test_stdio_sandbox_and_mcp_lock.py
uv run pytest tests/
uv run ruff check src tests

5. Execution Checklist

  • [ ] AC-64.1 implemented (shell denylist, env allowlist, TMPDIR/HOME isolation, 1 MiB cap, os.killpg teardown)
  • [ ] AC-64.2 implemented (sandbox-exec/bwrap wrapping + --require-os-sandbox fail-closed)
  • [ ] AC-64.3 implemented (.verity/mcp-lock.json + mcp-version-upgrade / mcp-schema-drift classification)
  • [ ] AC-64.4 verified green (ruff + full pytest)
  • [ ] Board #5 item PVTI_lAHOD-xmQM4Br351zhOMD30 synced & status updated