GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): make the portable bash scanner sound against real shells by kitlangton · Pull Request #53277 · anomalyco/opencode

Conversation

@kitlangton

@kitlangton kitlangton commented Oct 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Why

The portable shell scanner (experimental.portable_shell_scanner) is meant to replace the tree-sitter analyzer that decides which commands the shell tool asks permission for. Its Bash scanner had three separate lexers that each decided where $(…), {…}, [[…]] and heredocs end. When they disagreed, the rest of the command was silently treated as a comment or literal text. Inputs like these ran a hidden command in real shells while the scanner reported no commands at all, so no permission was requested:

[[ a]]# ]] && <cmd>
{ export X={}# ; <cmd>; }
export X="$(case esac in (esac) <cmd>;; esac)"
cat <<'}'; {
:
}
<cmd>; cat <<'}'; }
}

Several of these, such as for i in 1; { <cmd>; } and escaped quotes inside double-quoted backticks, are also missed by the tree-sitter analyzer that is the default today.

What Changes

The Bash/POSIX scanner is now a single recursive-descent parser that fails closed. Every command a real shell would execute is reported, or the whole command is opaque.

Input Before After
[[ a]]# ]] && probe no commands probe
{ export X={}# ; probe; } no commands probe
export X="`… \"'\" ; probe; …`" no commands probe
case $r in a) ls | head;; esac opaque (tool call fails) ls, head
{ find . -exec echo {} \; ; } opaque find
unset 'a[$(probe)]', ${x@P}, zsh ${(e)x}, *(e:'probe':) missed opaque
(( probe )) with sh/dash (two nested subshells there) missed probe

On 41,499 real agent shell commands replayed locally (not committed), only 4 outputs differ from v2, all improvements, and the opaque count stays at 6.

Recursive Parsing

Nested constructs no longer get a separate pre-scan to find where they end. $(…), backticks, <(…), ${ …; }, subshells, brace groups, case, loops, and [[ ]] recurse into the same command-list parser, and the construct ends wherever that parse ends, the same way bash parses $(…). Reserved words count only in reserved-word position. Pending heredocs are shared across nesting levels, so a body is read after the next newline wherever it occurs. A single quoting/expansion primitive replaces about 13 hand-copied variants.

Where shells read the same text differently, the scanner fails closed. Examples: <<$"…" delimiters, $[…], line continuations that split operators, single quotes inside double-quoted ${…}, and quoted or escaped $( / ` / ${ in an arithmetic context or a value bound to a variable. ShellScan.scan takes a dialect (bash, zsh, or posix) from the shell's basename. posix, which is also the default, covers both bash-like and dash readings.

Values that reach arithmetic or eval only at runtime, from the environment, function arguments, or another program's output, remain out of reach for static analysis. This is documented in the code; tree-sitter has the same limit.

Scope

This changes only the Bash/POSIX path of the portable scanner. Tree-sitter stays the default; the scanner remains opt-in through experimental.portable_shell_scanner. The PowerShell scanner is unchanged and needs the same treatment in a follow-up. An opaque result still fails the tool call; asking permission for the raw command instead would be a separate change (see #49954). Making the portable scanner the default is a separate decision.

Verification

cd packages/core
bun run test test/shell-scan test/shell-parse-parity.test.ts test/tool-shell.test.ts
SHELL_ORACLE_STRICT=1 bun run test test/shell-scan/oracle.test.ts
bun typecheck
cd ../.. && bun run check
  • Test suites: 3,160 pass, 0 fail.

  • Real-shell oracle tests: the new oracle.test.ts runs each fixture in every available shell (bash 3.2, bash 5.3, zsh, dash) with a harmless scan_probe on PATH. It asserts that every probe the shell executed is reported, or that the result is opaque. With SHELL_ORACLE_STRICT=1 on a machine that has all four shells, it also asserts that every fixture still executes somewhere; this run used strict mode. CI covers whichever shells the runner has. These tests are skipped on Windows.

  • Repo check: bun run check passes, 36/36 tasks.

  • Fuzzing (local): a random nested-program generator, run against all four shells, found 3 bypasses in 600 programs on the old scanner and 0 in 7,500 programs on this branch, across several seeds.

  • Benchmark (local):

    Tree-sitter path This scanner
    Size shipped ~2.6 MB of WASM grammars and runtime 39 KB
    CPU per command 88 µs 44 µs

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
kitlangton added 30 commits October 4, 2026 21:04
@kitlangton
test(core): add real-shell soundness oracle for bash scanner
f6d9a84
@kitlangton
fix(core): unify bash command scanner with recursive-descent parsing
6d9efaf
Replace bashDelimited and bashExpansion with recursive-descent parsing in
scanBash so nested subshells, command substitutions, process substitutions,
brace groups, and nofork substitutions use the same tokenizer and command
parser rather than a separate delimiter pre-scan.

Update redirect.test.ts for 'pwd && cd >out /outside', where a real shell
executes cd /outside after the redirect while legacy tree-sitter drops the
trailing directory operand.
@kitlangton
fix(core): tighten case and for header validation and expand oracle
0abbbe0
@kitlangton
test(core): skip real-shell oracle on Windows and format scanner
f3bcd53
@kitlangton
test(core): add failing real-shell fixtures for scanner soundness gaps
d0e57b4
@kitlangton
refactor(core): remove dead bash scanner state and guards
0974946
@kitlangton
refactor(core): track bash list state in one place
9926646
@kitlangton
fix(core): scan bash quoting and expansions with one primitive
b9c934a
@kitlangton
fix(core): end case pattern words at bracket metacharacters
32f62ed
@kitlangton
fix(core): match bash operators and assignment subscripts structurally
7fc28a7
@kitlangton
fix(core): fail closed on words after a bash ampersand redirect
1764fad
@kitlangton
fix(core): bound bash heredoc continuation scanning
46d263f
@kitlangton
refactor(core): split bash and powershell directory word resolution
6dd193c
@kitlangton
fix(core): fail closed on bash subscript and parameter evaluation
f375126
@kitlangton
fix(core): fail closed on zsh glob qualifier positions
2cc542c
@kitlangton
fix(core): scan posix for loops without an in list
bd7ab85
@kitlangton
fix(core): fail closed on bash reserved words after redirects
527cfd6
@kitlangton
refactor(core): read bash function heads and continuations declaratively
2470f60
@kitlangton
fix(core): mark every bash expansion in decoded subscript text
1cdc33d
@kitlangton
test(core): generate nested real-shell oracle fixtures from one list
66329a0
@kitlangton
refactor(core): skip the bash unit scanner for ordinary characters
81926b2
@kitlangton
docs(core): note the runtime limit of bash subscript checks
8a6f4a1
@kitlangton
fix(core): limit bash subscript evaluation checks to shell sinks
e7ae5a7
@kitlangton
test(core): add failing fixtures for reviewer-confirmed scanner misses
3993dce
@kitlangton
fix(core): share pending bash heredocs across nested scans
454d474
@kitlangton
fix(core): scan dash double parentheses under a posix dialect
89b4f2c
@kitlangton
fix(core): fail closed on bash arithmetic that rereads as a subshell
005e195
@kitlangton
fix(core): reject quote-hidden parameter ends in bash arithmetic quotes
5bcebfa
@kitlangton
fix(core): check bash arithmetic contexts and bound values for litera…
fa69d1d
…l expansions
@kitlangton
fix(core): fail closed on zsh flag groups and glob modifiers
d768766
kitlangton added 2 commits October 4, 2026 21:04
@kitlangton
fix(core): fail closed on zsh array adjacency and dash script aliases
e8cbdb8
@kitlangton
test(core): drop empty known-gap scaffolding
f8dd0ae
@github-actions github-actions Bot added the contributor label Oct 5, 2026
kitlangton added 6 commits October 4, 2026 21:16
@kitlangton
test(core): verify oracle fixture execution only in strict mode
a61ed90
@kitlangton
fix(core): close remaining shell scanner soundness gaps and false opa…
a6320df
…city
@kitlangton
fix(core): harden shell scanner parameter, subscript, ansi-quote, and…
f664209
… zsh builtin checks
@kitlangton
fix(core): harden shell scanner subscripts, escape decoders, and cont…
a197414
…inuations
@kitlangton
fix(core): close shell scanner subscript, conditional, and quote desyncs
d5debc3
@kitlangton
fix(core): tighten ansi-quote and double-quoted parameter desync checks
1b113c9
@kitlangton
kitlangton merged commit 2590927 into v2 Oct 5, 2026
18 of 21 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@kitlangton
kitlangton deleted the shell-scan-parser branch October 5, 2026 16:05
This was referenced Oct 5, 2026
fix(core): make the portable PowerShell scanner sound against real pwsh #53404
Merged
feat(core): enable portable shell scanner on local and dev channels #53479
Merged
@opencode-agent opencode-agent Bot mentioned this pull request Oct 13, 2026
shell/webfetch policy resources match raw strings — argv tokenization and URL host normalization needed (evasion classes un-enumerable) #55232
Open
@neriousy neriousy mentioned this pull request Oct 21, 2026
core: shell permission scanning on runtimes without tree-sitter WASM (workerd) #42184
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@kitlangton
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.