Skip to content

fix(opencode): skip env-var prefixes in shell permission pattern matching#29680

Open
JunJieLiu51520 wants to merge 1 commit into
anomalyco:devfrom
JunJieLiu51520:fix/env-prefix-permission-matching
Open

fix(opencode): skip env-var prefixes in shell permission pattern matching#29680
JunJieLiu51520 wants to merge 1 commit into
anomalyco:devfrom
JunJieLiu51520:fix/env-prefix-permission-matching

Conversation

@JunJieLiu51520
Copy link
Copy Markdown

Issue for this PR

Closes #14110

Type of change

  • Bug fix

What does this PR do?

The source() function in shell.ts returned the full tree-sitter node text including variable_assignment children. This meant commands like GOFLAGS=-mod=vendor go test ./... produced the pattern "GOFLAGS=-mod=vendor go test ./..." instead of "go test ./...", so permission rules like "go *": "allow" never matched.

Now source() filters out variable_assignment child nodes before constructing the pattern text, so env-var prefixed commands correctly match their permission rules.

How did you verify your code works?

Given a bash AST for GOFLAGS=-mod=vendor go test ./..., tree-sitter parses it as a command node with children [variable_assignment("GOFLAGS=-mod=vendor"), word("go"), word("test"), word("./...")]. The fix skips the variable_assignment node and joins the rest → "go test ./...", which matches "go *".

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…hing

The source() function returned the full node text including variable_assignment
children (e.g. "GOFLAGS=-mod=vendor go test"). This caused permission rules
like "go *": "allow" to never match commands with env-var prefixes.

Now source() filters out variable_assignment children before constructing the
pattern text, so "GOFLAGS=-mod=vendor go test ./..." correctly matches "go *".

Closes anomalyco#14110
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found a potential duplicate:

PR #28475: fix: strip inline env var prefixes from bash permission patterns

This PR appears to be addressing the exact same issue - stripping environment variable prefixes from bash commands in permission pattern matching. Both PRs target the same problem where commands like GOFLAGS=-mod=vendor go test ./... should match permission rules like "go *" by filtering out the env-var prefix.

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.

Bash permission rules don't match commands with env variable prefixes

1 participant