Skip to content

fix(permissions): preserve strict all-tools rules under last-match evaluation - #3866

Merged
dyoshikawa merged 2 commits into
dyoshikawa:mainfrom
jdotc1:fix/opencode-all-tools-last-match-20261117
Nov 18, 2026
Merged

dyoshikawa merged 2 commits into
dyoshikawa:mainfrom
jdotc1:fix/opencode-all-tools-last-match-20261117

Conversation

@jdotc1

@jdotc1 jdotc1 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Addresses the *-key ordering case in #3822 item 6 (first bullet). Other issues under #3822 remain open.

Security fix

OpenCode/Kilo treat permission patterns as last-match-wins. A * category such as { ".env": "deny", "*": "allow" } previously emitted the later catch-all allow unchanged, so the explicit restriction could be overridden. Emit all-tools allows first, asks next, and denies last, consistently with Rulesync's stricter-action precedence. Also handle the catch-all deny case when there are no pattern-specific restrictions.

This is a narrow, fail-closed reordering: it does not grant any new permission, alter rules for tools without last-match semantics, or address the remaining integer-like-key ordering and category-restatement gaps.

Verification

  • pnpm exec vp test run src/features/permissions --silent=true — 2,869 passed across 59 files.
  • pnpm run typecheck — passed.
  • pnpm exec vp fmt --check ... and pnpm exec vp lint ... --max-warnings 0 — passed.
  • Added three focused ordering regressions; no new dependencies.

Copilot AI lite review requested due to automatic review settings November 17, 2026 13:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical authorization bug remains because a global all-tools deny can be overridden by a later category-specific allow when no pattern-specific restrictions exist.

1 open issue
What changed in this PR

This PR hardens OpenCode/Kilo permission generation under last-match-wins evaluation by ordering all-tools rules from least to most restrictive and preserving catch-all deny handling.

Changes:

  • Reorders * category rules as allow → ask → deny.
  • Processes all-tools rules even when only a catch-all deny is present.
  • Adds focused regression tests for ordering and catch-all deny scenarios.
File Description
src/​features/​permissions/​last-match-restate.ts Reorders OpenCode/Kilo all-tools permission rules by strictness and handles catch-all configurations.
src/​features/​permissions/​last-match-restate.test.ts Adds regression coverage for allow, ask, deny, and catch-all rule ordering.

Review effort: Lite

action !== "allow" && pattern !== CATCH_ALL_PATTERN && !isPrototypePollutionKey(pattern),
);
if (restrictions.length === 0) {
if (restrictions.length === 0 && !allToolsRules) {
@dyoshikawa
dyoshikawa merged commit 3f3befd into dyoshikawa:main Nov 18, 2026
7 checks passed
@dyoshikawa

Copy link
Copy Markdown
Owner

@jdotc1 Thank you!

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.

3 participants