Commit 47c2d62
committed
fix(mcp): tighten the allow-list name check; never copy a non-object policy
Follow-up review on #41, after merge. Three findings, all valid.
1. isNamespacedToolName was too permissive (and its doc overclaimed).
It asked "could this have come out of namespaceToolName?" but only checked the
alphabet and the length, so it accepted `abc`, `read_file`, and
`'x'.repeat(64)` — none of which namespacing can emit. Such a key would sit
inert in mcp.toolPolicy looking like it did something.
It now accepts exactly the two shapes namespaceToolName emits:
1. `server__tool` — whenever the joined name fits the cap
2. `<57 chars>_<6-char base36 hash>` — the truncated form, always exactly 64
Shape 2 is why "must contain __" is still wrong: when a server's name ALONE
reaches the cap, the cut lands inside that first segment and no separator
survives. That case must stay legal or "Always allow" silently does nothing for
that server — the bug the previous round fixed.
Because being too strict fails SILENTLY, the guard is now swept rather than
sampled: 560 (server, tool) length pairs across the truncation boundary must all
validate, and the test asserts it actually reached the truncated and
separator-less regions so it cannot go vacuous.
2. A non-object mcp.toolPolicy would be copied key-by-key.
userScopedSetting returns whatever is in settings.json, of whatever type. A
policy that is accidentally a STRING would have safeCopy faithfully copy its
character indices — {"0":"a","1":"l",…} — and write that back as the policy,
destroying it. A malformed value is now discarded, not migrated.
3. The blocking await on mcpAllowAlways was already fixed in f247f1a. Verified it
is correct; restored the security rationale that commit dropped (the button only
ever adds an `allow`, is offered only for non-destructive tools, and is re-checked
regardless) and recorded why it is deliberately not awaited.
49 mcpConfig cases; 23 suites, 0 failures.1 parent a1d9c6e commit 47c2d62
3 files changed
Lines changed: 81 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
778 | 783 | | |
779 | 784 | | |
780 | 785 | | |
| |||
789 | 794 | | |
790 | 795 | | |
791 | 796 | | |
792 | | - | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
793 | 804 | | |
794 | 805 | | |
795 | 806 | | |
| |||
1390 | 1401 | | |
1391 | 1402 | | |
1392 | 1403 | | |
1393 | | - | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
1394 | 1412 | | |
1395 | 1413 | | |
1396 | 1414 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
230 | | - | |
231 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
232 | 236 | | |
233 | 237 | | |
234 | 238 | | |
235 | | - | |
236 | | - | |
237 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
238 | 243 | | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
| 244 | + | |
| 245 | + | |
243 | 246 | | |
| 247 | + | |
| 248 | + | |
244 | 249 | | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
250 | 256 | | |
251 | 257 | | |
252 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
566 | 566 | | |
567 | 567 | | |
568 | 568 | | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
569 | 595 | | |
570 | 596 | | |
571 | 597 | | |
572 | 598 | | |
573 | 599 | | |
574 | | - | |
575 | 600 | | |
576 | 601 | | |
577 | 602 | | |
578 | 603 | | |
579 | 604 | | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
580 | 619 | | |
581 | 620 | | |
582 | 621 | | |
| |||
0 commit comments