GeezerVison is showing github.com — shell: bare "--" in a pwsh command skips the permission check · Issue #54393 · anomalyco/opencode
shell: bare "--" in a pwsh command skips the permission check #54393DescriptionSummary
On Windows with pwsh, a bare -- token in a shell command skips the shell permission check entirely: an agent whose rules are shell * deny plus a few git … * allows can run any command by appending --.
Environment
- opencode version: 2.0.25
- OS: Windows 11 (10.0.26200), x64
- Terminal: OpenChamber (desktop)
- Shell:
"shell": "C:/Program Files/PowerShell/7/pwsh.exe" in opencode.jsonc (pwsh 7)
- Install/channel: latest
- Active plugins: @openchamber/opencode-claude, openchamber-agent-tool, opencode.browser
Reproduction
- Subagent file with:
permissions:
- { action: shell, resource: "*", effect: deny }
- { action: shell, resource: "git status *", effect: allow }
- Ask it to run the commands below, one shell call each.
| command |
result |
git grep -n "x" README.md |
Permission denied: shell |
git grep -n "x" -- README.md |
runs |
git rev-parse HEAD -- |
runs |
node -e "console.log(1)" -- |
runs |
Get-Content README.md -TotalCount 1 -- |
runs |
Expected Behavior
Every command is matched against the rules; an unparseable command is denied (or asked), not executed.
Actual Behavior
Commands containing a bare -- run without any permission check.
Additional Context
packages/core/src/tool/plugin/shell.ts (v2.0.25) only asserts when the scanner found command nodes:
if (parsed.commands.length > 0)
yield* permission.assert({ action: name, resources: parsed.commands.map((command) => command.resource), … })
With pwsh the tree-sitter-powershell parse of a command containing -- yields no command node, so parsed.commands is empty and the call is skipped. Reproducible every time. Not tested with bash or with experimental.portable_shell_scanner. Activityopencode-agent commented on Oct 10, 2026 Thanks for the detailed report. I reproduced this on 2.0.25, and it still happens on the latest dev (7b3d4ce).
There's no Windows in our sandbox, so I used a stand-in executable named pwsh. OpenCode chooses the PowerShell parser from that name, so the real tree-sitter-powershell scan runs. I set the shell to it, with rules shell * deny plus git status * allow:
echo PLAIN-RAN was denied with Permission denied: shell.
echo BYPASS-RAN -- ran with no permission check.
I also called the scanner directly. With a PowerShell shell, git grep -n "x" -- README.md, git rev-parse HEAD --, node -e "console.log(1)" -- and Get-Content README.md -TotalCount 1 -- all give zero commands, so the check in packages/core/src/tool/plugin/shell.ts is skipped, as you described. The portable scanner finds a command in each case, and so does the tree-sitter scanner when the shell is bash.
A possible workaround I haven't tried end to end: set "experimental": { "portable_shell_scanner": true } in your config.
The recording and script below reproduce it. Related:
recording.mp4

Reproduction script (drive.ts)
// Repro for anomalyco/opencode#54393: with a PowerShell shell, a bare `--` makes the
// tree-sitter-powershell scan return zero commands, so the shell permission check is skipped.
//
// Setup: on Linux, a stand-in `pwsh` executable (OpenCode only looks at the name "pwsh"
// to choose the PowerShell parser) that runs the -Command text with bash:
// mkdir -p /tmp/opencode/fakepwsh && cat > /tmp/opencode/fakepwsh/pwsh <<'EOF'
// #!/bin/bash
// for last; do :; done
// exec /bin/bash -c "$last"
// EOF
// chmod +x /tmp/opencode/fakepwsh/pwsh
//
// `experimental.portable_shell_scanner: false` pins the tree-sitter scanner that release
// builds use by default (source/dev-channel runs default to the portable scanner).
import { Effect } from "effect"
import { Llm, OpenCodeDriver } from "opencode-drive"
const shell = (id: string, command: string) => [
Llm.toolCall({ index: 0, id, name: "shell", input: { command } }),
Llm.finish("tool-calls"),
]
export default OpenCodeDriver.use(
{
...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
tui: { recording: true },
project: { git: true, files: { "README.md": "hello x\n" } },
config: {
shell: "/tmp/opencode/fakepwsh/pwsh",
experimental: { portable_shell_scanner: false },
permissions: [
{ action: "shell", resource: "*", effect: "deny" },
{ action: "shell", resource: "git status *", effect: "allow" },
],
},
},
({ ui, llm }) =>
Effect.gen(function* () {
yield* ui.submit("run the two commands")
// 1) without `--`: must be denied
yield* llm.send(...shell("call_plain", "echo PLAIN-RAN"))
// 2) same kind of command with a trailing bare `--`: should also be denied
yield* llm.send(...shell("call_dash", "echo BYPASS-RAN --"))
yield* llm.send(Llm.text("done"))
yield* ui.waitFor("done")
yield* Effect.sleep("1 second")
yield* ui.screenshot("result")
}),
)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
added a commit that references this issue on Oct 11, 2026This issue will close once commit ca16c0c is merged into the 'dev' branch.ca16c0c cc-bb-aa commented on Oct 11, 2026 A bare token short circuiting the permission check means the parser treats -- as end of options and then matches nothing, which is an allow-by-parser-gap bug. The fix is to classify the command before option parsing, or to fail closed when the parsed result is empty but the raw string is not. A fuzz pass over shell metacharacters would likely find siblings of this one. MateoEstradaOSU commented on Oct 16, 2026 I can reproduce this on current dev: the legacy tree-sitter-powershell parse of git rev-parse HEAD -- yields no command nodes, so parsed.commands is empty and the permission.assert at packages/core/src/tool/plugin/shell.ts:137 is skipped entirely.
Working on a fail-closed fix in shell.ts: when the scanner finds no command or directory nodes in a non-empty command, assert the raw command text instead of skipping the check. PR incoming. android6 commented on Oct 17, 2026 Two more pwsh inputs from the same family — the legacy tree-sitter-powershell scan returns a command list that does not match what pwsh will run. Found on 2.0.27 (Windows, pwsh 7) with an agent whose rules are shell: "*": deny plus git log * / git diff * / … allows and a trailing git * --output* deny. Parser output below is from web-tree-sitter + tree-sitter-powershell 0.25.10 using the same walk as scanLegacy (all command nodes, resource = node text):
|
tree.rootNode.descendantsOfType("command").reduce( |
|
(result, node) => { |
|
if (!node) return result |
|
const command = parts(node) |
|
const tokens = command.map((part) => part.text) |
|
if (tokens.length === 0) return result |
|
const name = powershell ? tokens[0].toLowerCase() : tokens[0] |
|
if (CWD.has(name)) { |
|
result.directories.push(...directoryArgs(command, powershell, cwd, shell)) |
|
return result |
|
} |
|
result.commands.push({ |
|
resource: (node.parent?.type === "redirected_statement" ? node.parent.text : node.text).trim(), |
|
save: `${prefix(tokens).join(" ")} *`, |
|
}) |
1. A here-string piped into a command scans to zero commands, so the check is skipped. Same root cause as the bare -- here (the if (parsed.commands.length > 0) guard), but reached by ordinary agent code: a subagent ran a probe script this way and it executed although bun run is not allowed.
@'
console.log(1)
'@ | bun run - → commands: []
2. --option=value breaks the parse (ERROR node): the command is truncated at =, and what follows either becomes a separate "command" or disappears.
git log --format=fuller 02abf50..HEAD → ["git log --format", "02abf50..HEAD"] denied: the range is checked as a command
git log --format=fuller -n 1 → ["git log --format"] allowed
git log --pretty=x --output=out.txt → ["git log --pretty"] allowed: `git * --output*` deny never sees --output
git log --pretty=x -n 1; Remove-Item f → ["git log --pretty", "Remove-Item f"] later statements are still seen
git log --format="fuller" HEAD~1 → ["git log --format"] (quoting the value does not help the scan, it just avoids the stray "command")
So the same bug gives a false denial in one direction (a commit or range after --format= is treated as a command name and rejected by an allowlist — agents hit this with plain git log --format=fuller <range>) and a silent pass in the other (any argument after the first = is invisible to deny rules, so --output=<file> writes a file under an agent that denies it).
A fail-closed rule for an empty scan would cover case 1 but not case 2: there the scan is non-empty, it is just wrong. Treating a tree with ERROR nodes the same way as an empty scan (fall back to checking the raw command, or ask/deny) would cover both. The guard:
|
if (parsed.commands.length > 0) |
|
yield* permission.assert({ |
|
action: name, |
|
resources: parsed.commands.map((command) => command.resource), |
|
save: parsed.commands.map((command) => command.save), |
|
sessionID: context.sessionID, |
|
agent: context.agent, |
|
source, |
|
}) |
LMR-eitea commented on Oct 27, 2026 in general the shell permissions are completely busted. If you allow anything with a wildcard, all bets are off…
edit: ok maybe I'm overstating the issue here, but certainly wildcards are to be used sparingly still nikitakot commented on Oct 29, 2026
9. I can reproduce this on current dev: the legacy tree-sitter-powershell parse of git rev-parse HEAD -- yields no command nodes, so parsed.commands is empty and the permission.assert at packages/core/src/tool/plugin/shell.ts:137 is skipped entirely.
Working on a fail-closed fix in shell.ts: when the scanner finds no command or directory nodes in a non-empty command, assert the raw command text instead of skipping the check. PR incoming.
I was reporting the same thing in v1 with a PR fix.
#39931
#39938
Can confirm it still reproes.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|