Skip to content

Redirect-only bash statements bypass all permission rules ("> out.txt" runs under "bash": {"*": "deny"}) #52180

Closed as not planned

Description

@mogochucho

Description

{ "permission": { "bash": { "*": "deny", "echo hacheck *": "allow", "*>*": "deny" } } }
Command Expected Actual
id denied denied
echo hacheck a > out.txt denied denied
> out.txt denied executed
>> out.txt denied executed
&> out.txt denied executed
2> out.txt denied executed
echo hacheck a; > out.txt denied executed

No prompt is shown either — the call never reaches the permission layer.

> out.txt creates or truncates the file, >> appends.

"*>*": "deny" is what makes row 2 safe, and it is the only thing that does. It
provably cannot help the rest: the redirect-only statements are never matched
against any pattern, so there is nothing for a pattern to catch. Neither can
">*" or any other pattern — the value being matched does not exist.

Without a redirect deny, row 2 also executes; that was #5330, fixed by #6737.
The statements above are the residual case that fix does not cover.

Root cause

// packages/opencode/src/tool/bash.ts
for (const node of tree.rootNode.descendantsOfType("command")) {
  // ...
  if (command.length && command[0] !== "cd") {
    patterns.add(commandText)
  }
}

A bare redirection parses as a redirected_statement containing only a
file_redirect — there is no command node. The loop body never runs, patterns
stays empty, and no permission check is issued. The command.length guard causes
the same skip for any command node that yields no tokens.

This is the residual case of #5330: the fix in #6737 (commit e7ff7143) attaches
the redirect text via node.parent.text, but only for statements that already
contain a command node. The same commit also introduced the env-prefix bypass in
#16075, so the string handling around here looks worth revisiting.

Likely part of the class covered by #31485.

Version: 1.18.31

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. github-actions commented on Sep 29, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    • #49948: Bare redirects are parsed as zero commands and bypass shell permission checks.
    • #52083: Redirections are dropped from permission resources in compound shell commands.

    If possible, please also add the OpenCode version and OS/shell used to help confirm whether this varies by environment.

  2. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions