Commit 206113d
fix(mcp): harden the untrusted env copy; make the collision test actually collide
Second round of PR #29 review (Copilot). Both were real.
1. normalizeServer copied a repo-authored env with Object.assign, which hands an
own "__proto__" key (JSON.parse creates one) to the prototype SETTER instead of
copying it. Measured before changing anything: this is NOT currently
exploitable — the object-valued payload is rejected by the existing
"env must be an object of strings" check, and a string-valued __proto__ is
ignored by the setter. But that makes the safety INCIDENTAL: it holds only as
long as nobody relaxes the value check. Now structural — safeEnvCopy skips
__proto__/constructor/prototype and copies into a fresh object. (Kept a normal
object rather than Object.create(null): later code may reasonably call
hasOwnProperty on it.) It also stops an env var named __proto__ from silently
vanishing into the setter.
2. The "servers that sanitize alike" test paired 'my-server' with 'my/server',
but '-' is already legal so they never collided — the test passed without ever
entering the dedupe path, i.e. it proved nothing. Now pairs 'my/server' with
'my:server' (both sanitize to 'my_server'), asserts the collision as an explicit
PRECONDITION so it cannot rot back, and asserts the dedupe reported it.
Added a prototype-pollution regression test alongside.
Verified: 24 tests pass; both fixes mutation-checked — restoring Object.assign
fails the suite (exit 1, caught via the `constructor` key), and restoring the
non-colliding inputs also fails (exit 1, caught by the new precondition). Full CI
gate: 18 suites, 0 failures.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 3c0412e commit 206113d
2 files changed
Lines changed: 51 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
58 | 80 | | |
59 | 81 | | |
60 | 82 | | |
| |||
71 | 93 | | |
72 | 94 | | |
73 | 95 | | |
74 | | - | |
| 96 | + | |
75 | 97 | | |
76 | 98 | | |
77 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
94 | 101 | | |
95 | 102 | | |
96 | | - | |
| 103 | + | |
| 104 | + | |
97 | 105 | | |
98 | 106 | | |
99 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
100 | 123 | | |
101 | 124 | | |
102 | 125 | | |
| |||
0 commit comments