[PR #9257] fix: deny bash commands with arguments when command name matches rule #13039

Open
opened 2026-02-16 18:17:55 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9257

State: open
Merged: No


Summary

Fixes #7063 - Permission system allows explicitly denied bash commands to execute

Problem

Commands configured with 'deny' in opencode.json permissions were being executed anyway. Specifically, package managers (yarn, npm, pnpm, npx, pnpx) ran despite being explicitly denied.

Root Cause: When a user configures "yarn": "deny", this creates a rule with pattern "yarn". However, the bash tool sends patterns like "yarn test" or "yarn install", which don't match the exact pattern "yarn" via Wildcard.match().

Solution

Modified the evaluate() function in packages/opencode/src/permission/next.ts to add special handling for bash permissions:

  1. First checks if the full command pattern matches any rule (existing behavior)
  2. For bash permissions only: also extracts the command name (first word) and checks if it matches any rule

This ensures that when a user configures yarn: deny, commands like yarn test, yarn install, etc. are correctly denied.

Changes

  • packages/opencode/src/permission/next.ts: Added bash-specific command name matching in evaluate()
  • packages/opencode/test/permission/next.test.ts: Added 10 new tests for bash command name matching

Testing

All 92 permission tests pass, including 10 new tests specifically for this fix:

  • yarn test with yarn: deny → now correctly denies
  • npm install with npm: deny → now correctly denies
  • pnpm run build with pnpm: deny → now correctly denies
  • npx create-react-app with npx: deny → now correctly denies
  • Existing wildcard behavior preserved
  • Non-bash permissions unaffected

Example Configuration That Now Works

{
  "permissions": {
    "bash": {
      "yarn": "deny",
      "npm": "deny"
    }
  }
}

With this fix, yarn test, yarn install, npm run build, etc. will all be correctly denied.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9257 **State:** open **Merged:** No --- ## Summary Fixes #7063 - Permission system allows explicitly denied bash commands to execute ## Problem Commands configured with 'deny' in opencode.json permissions were being executed anyway. Specifically, package managers (yarn, npm, pnpm, npx, pnpx) ran despite being explicitly denied. **Root Cause**: When a user configures `"yarn": "deny"`, this creates a rule with pattern `"yarn"`. However, the bash tool sends patterns like `"yarn test"` or `"yarn install"`, which don't match the exact pattern `"yarn"` via `Wildcard.match()`. ## Solution Modified the `evaluate()` function in `packages/opencode/src/permission/next.ts` to add special handling for bash permissions: 1. First checks if the full command pattern matches any rule (existing behavior) 2. For bash permissions only: also extracts the command name (first word) and checks if it matches any rule This ensures that when a user configures `yarn: deny`, commands like `yarn test`, `yarn install`, etc. are correctly denied. ## Changes - `packages/opencode/src/permission/next.ts`: Added bash-specific command name matching in `evaluate()` - `packages/opencode/test/permission/next.test.ts`: Added 10 new tests for bash command name matching ## Testing All 92 permission tests pass, including 10 new tests specifically for this fix: - `yarn test` with `yarn: deny` → now correctly denies - `npm install` with `npm: deny` → now correctly denies - `pnpm run build` with `pnpm: deny` → now correctly denies - `npx create-react-app` with `npx: deny` → now correctly denies - Existing wildcard behavior preserved - Non-bash permissions unaffected ## Example Configuration That Now Works ```json { "permissions": { "bash": { "yarn": "deny", "npm": "deny" } } } ``` With this fix, `yarn test`, `yarn install`, `npm run build`, etc. will all be correctly denied.
yindo added the pull-request label 2026-02-16 18:17:55 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13039