Commit 42debd1
committed
fix(core): close AST substitution gaps and log AST parser failures (#4386 R4)
Round-4 critical findings from wenshao:
1. **AST substitution blind spots in non-`command` node types** —
`evaluateStatementReadOnly` (shellAstParser.ts) only checked
`containsCommandSubstitutionAST` inside the `command` node branch.
Substitution living in OTHER node types slipped through as
read-only, causing `resolveDefaultPermission` to return `'allow'`
and `coreToolScheduler` to auto-approve silently. Verified blind
spots (tests added):
- `variable_assignment` / `variable_assignments`:
`FOO=$(curl evil)` and `FOO=$(cat /etc/shadow) ls` were read-only
- Backtick form: `FOO=\`cat /etc/shadow\`` was read-only
The pre-PR #4386 regex check in `resolveDefaultPermission` was a
safety net masking these AST gaps; removing it without patching
the AST was a real security regression.
Fix: hoist the `containsCommandSubstitutionAST` guard to the top
of `evaluateStatementReadOnly` so every node type inherits the
check in one place. Net behavior: substitution anywhere in the
statement subtree marks the whole statement as non-read-only,
matching the contract the function's docstring (and the comment
in `resolveDefaultPermission`) already claimed.
Tests follow Step 7.1 RED → fix → GREEN ordering: confirmed each
of the 3 affected shapes was misclassified as read-only before
the AST hoist, and all 4 cases pass after.
2. **Silent catch in `resolveDefaultPermission`** — the `try/catch`
around `isShellCommandReadOnlyAST` swallowed parser exceptions
without logging. With the regex safety net gone, the AST check is
now the sole gatekeeper, so a parser regression would silently
route every command to 'ask' with no trace. Added the same
`debugLogger.warn` already used by the equivalent catches in
`shell.ts` (line 1394) and `monitor.ts` (line 192).
3. **Misleading comment** in `resolveDefaultPermission` already
asserted "the AST walker marks any node with a substitution
expansion as non-read-only" — true post-fix, but false pre-fix.
Updated to reference the load-bearing top-level guard in
`shellAstParser.ts` so the claim is verifiable from one place.
Closes wenshao R4 findings: AST blind spots (`permission-manager.ts:417`
+ `shellAstParser.ts:884`), silent catch (`permission-manager.ts:415`).1 parent baa1e9f commit 42debd1
3 files changed
Lines changed: 61 additions & 7 deletions
File tree
- packages/core/src
- permissions
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | | - | |
417 | | - | |
418 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
419 | 424 | | |
420 | 425 | | |
421 | 426 | | |
422 | 427 | | |
423 | 428 | | |
424 | | - | |
425 | | - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
426 | 436 | | |
427 | 437 | | |
428 | 438 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
46 | 82 | | |
47 | 83 | | |
48 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
831 | 831 | | |
832 | 832 | | |
833 | 833 | | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
834 | 842 | | |
835 | 843 | | |
| 844 | + | |
| 845 | + | |
836 | 846 | | |
837 | 847 | | |
838 | | - | |
839 | | - | |
840 | 848 | | |
841 | 849 | | |
842 | 850 | | |
| |||
0 commit comments