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 — fix(opencode): check permission for bare redirects with no parsed command by DSHCorrectover · Pull Request #53597 · anomalyco/opencode

Conversation

@DSHCorrectover

@DSHCorrectover DSHCorrectover commented Oct 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #49948

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A bare redirect like > file or >> file is valid POSIX — it truncates or creates the target file — but the tree-sitter shell scanner parses it into zero command nodes. The shell tool built its permission patterns only from parsed commands, so a zero-command statement produced no patterns and the permission check was skipped entirely. The statement then ran unchecked even with an explicit deny:

permission:
  bash:
    "*": "deny"

The issue predates the current scanner, but this still reproduces on dev: both > victim.txt and >> victim.txt parse to 0 command nodes, so nothing is asserted before they execute.

The fix: while scanning, also look at redirected_statement nodes. A redirected statement with no command body (the bare-redirect case) is added as a permission pattern using its raw text, so it flows through the same evaluation as any other statement — denied by an explicit deny, allowed by an explicit allow, or shown as a prompt otherwise. Redirects that do have a command (e.g. echo hi > out.txt) keep their existing pattern and are unaffected.

Scope note

The issue also points to a second fail-open in packages/core/src/permission.ts: an empty resource list falls through to allow. That file belongs to the separate legacy permission system, and changing its default could affect behavior well beyond this path, so I did not touch it here. With this change the shell path no longer reaches that state for bare redirects because a pattern is always produced.

How did you verify your code works?

Added three regression tests in packages/opencode/test/tool/shell.test.ts:

  • > victim.txt is denied under a wildcard deny rule and the file is not truncated.
  • >> victim.txt produces one bash permission prompt whose pattern is the raw statement.
  • echo hi > out.txt keeps its single existing pattern (no extra bare-redirect pattern, no duplicate prompt).

Results on a clean tree:

  • bun test test/tool/shell.test.ts — 26 pass / 0 fail
  • bun test test/permission/next.test.ts test/permission-task.test.ts — 100 pass / 0 fail
  • tsgo --noEmit — passes
  • oxlint on the two changed files — 0 errors (12 pre-existing warnings)

Screenshots / recordings

N/A — no UI change.

Checklist

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@DSHCorrectover
fix(opencode): check permission for bare redirects with no parsed com…
e6d8399
…mand
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Oct 6, 2026
@DSHCorrectover
DSHCorrectover force-pushed the fix/bare-redirect-permission branch from c13030b to e6d8399 Compare October 6, 2026 20:15
@DSHCorrectover DSHCorrectover closed this Oct 6, 2026
@DSHCorrectover DSHCorrectover reopened this Oct 6, 2026
@DSHCorrectover DSHCorrectover closed this Oct 6, 2026
@DSHCorrectover DSHCorrectover reopened this Oct 6, 2026
@DSHCorrectover

DSHCorrectover commented Oct 6, 2026

Copy link
Copy Markdown
Author

Note for maintainers: the check-duplicates job on this PR failed with a transient GitHub GraphQL infrastructure error inside script/duplicate-pr.ts ("Something went wrong while executing your query"), not because a duplicate was found. It can't be re-triggered from a fork (workflow only runs on opened); a maintainer re-run should resolve it. Happy to help if anything is needed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DSHCorrectover
DSHCorrectover force-pushed the fix/bare-redirect-permission branch from 178c3cd to e6d8399 Compare October 6, 2026 20:18
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thdxr thdxr closed this Oct 10, 2026
@opencodejr opencodejr Bot mentioned this pull request Oct 28, 2026
shell: bare redirect bypasses the permission check (scanner returns no commands) #49948
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

shell: bare redirect bypasses the permission check (scanner returns no commands)

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@DSHCorrectover @thdxr
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.