Skip to content

Conversation

@pschiel
Copy link
Contributor

@pschiel pschiel commented Jan 3, 2026

This patch fixes two issues in bash tool permission handling:

1. bash redirect statements are not handled (treesitter-bash usage)

Any commands parsed don't have redirects included (e.g. ls foo > bar results in ls foo) which prevents permission rules to match properly (e.g. "ls *>*": "deny" does not apply).

Cause: Redirect statements are parents of commands, thus not recognized in the loop over descendantsOfType("command")

$ echo "ls hello > /dev/null" | tree-sitter parse

(program [0, 0] - [1, 0]
  (redirected_statement [0, 0] - [0, 20]
    body: (command [0, 0] - [0, 8]
      name: (command_name [0, 0] - [0, 2]
        (word [0, 0] - [0, 2]))
      argument: (word [0, 3] - [0, 8]))
    redirect: (file_redirect [0, 9] - [0, 20]
      destination: (word [0, 11] - [0, 20]))))

Solution: use node.parent.text for the pattern matching, which includes the full command


2. bash always pattern lacks a space after the command

Approving ls adds ls* as an always pattern, which allows also other commands (e.g. lsof) which is not intended.

Solution: add a space so ls* becomes ls * in the pattern

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant