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 — shell: bare "--" in a pwsh command skips the permission check · Issue #54393 · anomalyco/opencode

shell: bare "--" in a pwsh command skips the permission check #54393

New issue
Copy link
New issue
Copy link
Closed
#60332
Closed
shell: bare "--" in a pwsh command skips the permission check#54393
#60332
Copy link
Labels
reproducedseverity:high

Description

@android6
android6
opened on Oct 10, 2026
Issue body actions

Summary

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

  1. Subagent file with:
    permissions:
      - { action: shell, resource: "*", effect: deny }
      - { action: shell, resource: "git status *", effect: allow }
  2. 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.

Reacted by Nikita Kot

Activity

  1. opencode-agent commented on Oct 10, 2026

    @opencode-agent
    opencode-agentBot
    on Oct 10, 2026 – with OpenCode Agent
    Contributor
    More actions

    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:

    • shell: bare redirect bypasses the permission check (scanner returns no commands) #49948: the same skipped check, triggered by a bare redirect (> file); open PR fix(core): evaluate permissions for commands the scanner cannot decompose #49954 changes that check.
    • Permission patterns truncated/skipped when parsing commands with tree-sitter-powershell (Windows) — allow rules never match #52615 and bash permission escape via -- double hyphen #39931: the same -- bypass reported on v1.
    recording.mp4

    Screenshot

    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.

    Reacted by PiRomant
  2. opencode-agent
    added
    reproduced
    severity:high
    on Oct 10, 2026
  3. saurav-shakya
    added a commit that references this issue on Oct 11, 2026

    fix(core): scan PowerShell commands the grammar fails to parse

    This issue will close once commit ca16c0c is merged into the 'dev' branch.
    ca16c0c
  4. cc-bb-aa commented on Oct 11, 2026

    @cc-bb-aa
    cc-bb-aa
    on Oct 11, 2026
    More actions

    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.

  5. MateoEstradaOSU commented on Oct 16, 2026

    @MateoEstradaOSU
    MateoEstradaOSU
    on Oct 16, 2026
    More actions

    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.

  6. android6 commented on Oct 17, 2026

    @android6
    android6
    on Oct 17, 2026
    Author
    More actions

    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):

    opencode/packages/core/src/shell/parse.ts

    Lines 185 to 199 in dd7377b

    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:

    opencode/packages/core/src/tool/plugin/shell.ts

    Lines 137 to 145 in dd7377b

    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,
    })

  7. sergaent
    marked permissions: shell commands containing "--" bypass permission checks on Windows #57359 as a duplicate of this issue on Oct 20, 2026
  8. LMR-eitea commented on Oct 27, 2026

    @LMR-eitea
    LMR-eitea
    on Oct 27, 2026
    More actions

    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

  9. nikitakot commented on Oct 29, 2026

    @nikitakot
    nikitakot
    on Oct 29, 2026
    More actions

    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.

  10. kitlangton
    closed this as completedin #60332on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    reproducedseverity:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.