Skip to content

fix(cli): the MCP guard refuses a field it cannot read instead of reading it as absent (TASK-069) - #1915

Merged
lilyshen0722 merged 3 commits into
mainfrom
kai/069-mcp-entry-audit
Sep 26, 2026
Merged

lilyshen0722 merged 3 commits into
mainfrom
kai/069-mcp-entry-audit

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What

cli/src/lib/declared-mcp-guard.js — a declared MCP entry whose env, headers or args cannot be read is now refused, instead of being read as absent.

The row's two named shapes are already refused on main — measured

shape (TASK-069 as written) guard on main today
{transport:'http', command:[…]}, no url REFUSE — http entry carries a command
{transport:'sse', command:[…]} REFUSE
{transport:'HTTP' | 'https' | 'websocket', command:[…]} REFUSE — unknown transport (fail-closed; the guard compares the string exactly)
shipped command + env.NODE_OPTIONS REFUSE — carries env/args/cwd beyond the shipped server's own (NODE_OPTIONS)
shipped command + env.npm_config_registry REFUSE
shipped command + env.PATH REFUSE
controls: canonical shipped entry, same-origin http entry ACCEPT

Probe: auditDeclaredMcp called directly on each shape. #1744 (merged 2026-09-19T15:09) is the PR this row already links, and its merged guard refuses both — #1764 (12:54) added the adapter half (an entry declaring a non-stdio transport is skipped even when it carries a command, Vera 69774, plus the pi rule that an unknown transport is never normalised into an admitted one). So the row text describes the defect those two fixed.

What is left of the class, and what this changes

The entry was admitted on the strength of the fields that read as expected, while a field the guard cannot read was read as absent:

shape on main before after
env: 'NODE_OPTIONS=--import=data:text/javascript,1' ACCEPT (as "the shipped entry") REFUSE — env is a string, not an object
headers: 'X-Token: ${COMMONLY_AGENT_TOKEN}' ACCEPT REFUSE — headers is a string, not an object
args: '--import=data:text/javascript,1' ACCEPT REFUSE — args is a string, not an array
env: { NODE_OPTIONS: undefined } ACCEPT (undefined === undefined in CANONICAL_STDIO_ENV[key] === value) REFUSE — env.NODE_OPTIONS is not a string
installed match, cwd: 1 / ['/tmp/evil'] / {…} / true ACCEPT (executionShape reads cwd as typeof === 'string' ? … : null, so it normalised to the installed entry's absent cwd) REFUSE — cwd is of type number, not a string
canonical shipped entry; env: null; args: [] ACCEPT ACCEPT (controls)

Severity, stated honestly: no live execution was found. Every reader spreads these fields — deliverSeatCredential does { ...server.env }, which turns a string into single-character keys, and claude/codex emit that object verbatim — so the shapes above are mangled rather than honoured by the adapters I read. The defect is that the predicate is unsound: it admits an entry whose meaning it did not establish, and the consumer that parses the string instead of spreading it is the one that would honour it. That is the same reading as the row's title, one field type further out.

Witness (mutation ledger)

Each branch removed in turn, whole file run, one run per arm:

arm red
the whole unreadableField call removed 5 — env-as-string, headers-as-string, args-as-string, non-string env value, non-string cwd
only the non-object branch disabled 2 — env-as-string, headers-as-string
only the env-value branch disabled 1 — non-string env value
only the args branch disabled 1 — args-as-string
only the cwd branch disabled 1 — non-string cwd (the string-cwd control stays green)
cwd banned outright rather than type-checked 1 — the string-cwd control

The controls stay green in arms 1–5, which is what makes the reds attributable; arm 6 reds a control on purpose, because that is the arm that would turn this into a ban on cwd rather than a rule about values it cannot read.

The cwd field (Vera's hold, measured on the previous head)

executionShape normalised an unreadable cwd to null, which equals the installed entry's absent cwd, so the entry was admitted as one the operator already installed. Against an installed allow-list: cwd: '/tmp/evil' refused (by value), and 1 / ['/tmp/evil'] / { dir: … } / true accepted. Now all four are refused with the shape message. A string cwd is judged by value, not banned: the same string on both sides is the installed entry and is admitted, a different string is refused by the whole-entry match. No adapter forwards a declared cwd (buildMcpConfig emits type/url/command/args/env/headers), so this was unsound-and-unreachable where the env cases were unsound-and-mangled — held anyway because the guard is the layer that has to hold when the layer above changes. Restored: 20/20 in the file, 49 suites / 876 passed / 10 skipped / 0 failed across the CLI suite, eslint clean.

Not done

  • No server-side mirror in backend/utils/environmentSpecValidation.ts. The daemon's layer is the one that holds when the server is wrong (the guard's own header says so), so the shape rule belongs here first; say the word if you want the writer gated too.
  • The row's prUrl still points at #1744; this is the residual of that row rather than a new one.

Gate

@vera — security-adjacent CLI guard, so you by default. Her hold landed on e7e26c37; the cwd fix is 61743d0b and the version bump db37a1b6 (cli 0.1.74 → 0.1.75, connector-ops 74373: the guard's src moved, so the published version has to move with it).

…ding it as absent (TASK-069)

The row asks `auditDeclaredMcp` to judge the whole ENTRY rather than selected
fields. The two shapes it names are already refused on main: #1744 refuses an
http/sse entry that carries a command and refuses a shipped command carrying
NODE_OPTIONS / npm_config_registry / PATH, and #1764 makes the adapters classify
by the declared transport. What is left of the class is the TYPE of a field: the
entry is admitted on the strength of the fields that read as expected, and a
field the guard cannot read is silently read as absent instead of refused.

Measured on main, accepted before this commit:
  env as a string ('NODE_OPTIONS=--import=data:...')  -> accepted as "the shipped entry"
  args as a string                                     -> accepted
  headers as a string (with ${COMMONLY_AGENT_TOKEN})    -> accepted
  env value undefined (CANONICAL_STDIO_ENV[k] === v)    -> accepted, undefined === undefined

Every reader spreads those fields, so the adapters I read mangle the value rather
than honour it: deliverSeatCredential does { ...server.env }, which turns a string
into single-character keys, and claude/codex emit that object verbatim. So no live
execution was found through the shapes above - the defect is that the predicate is
unsound, which is what a future consumer (or a runtime this CLI does not ship)
would need to be to turn it back into one. Fail closed instead.
…ch drops

Vera's hold on #1915. `executionShape` reads cwd as
`typeof server.cwd === 'string' ? server.cwd : null`, so an unreadable cwd
normalised to the installed entry's absent cwd, the two shapes compared equal, and
the entry was admitted as one the operator already installed. Measured on the
previous head against an installed allow-list: cwd 1, ['/tmp/evil'], { dir: … } and
true were all ACCEPTED; a string cwd was refused only because it differed from the
installed one.

Now refused with the same shape message as env/headers/args. A string cwd is still
judged by value, not banned: the same string on both sides is the installed entry
and is admitted, a different string is refused by the whole-entry match — the
control that keeps this a shape rule rather than a ban on the field.

No adapter forwards a declared cwd (buildMcpConfig emits type/url/command/args/env/
headers), so this is unsound-and-unreachable, as the env cases were
unsound-and-mangled: the guard is the layer that has to hold when the layer above
changes.
…must move with it

connector-ops (74373): main and npm latest are both 0.1.74, so the shape rule
would have reached the repo and zero seats. Folded into the push that carries
Vera's cwd fix, so the head is green in one round.
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 26, 2026
Merged via the queue into main with commit aba4f3d Sep 26, 2026
19 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant