fix(permission): make * not match / in wildcard patterns, add ** globstar support#28689
Open
lexlian wants to merge 2 commits into
Open
fix(permission): make * not match / in wildcard patterns, add ** globstar support#28689lexlian wants to merge 2 commits into
lexlian wants to merge 2 commits into
Conversation
…star support Wildcard * now matches any characters except /, aligning with standard glob semantics (gitignore, bash glob). Use ** to match across directory separators. - packages/core/src/util/wildcard.ts: * -> [^/]*, ** -> .*, ? -> [^/] - packages/opencode/src/util/wildcard.ts: same changes - packages/opencode/src/agent/agent.ts: update defaults to use ** for patterns that need cross-directory matching (read, external_directory) - packages/opencode/src/permission/index.ts: add array/type validation in fromConfig() - tests: update existing tests for new wildcard behavior, add new tests for path-aware matching and ** globstar Fixes anomalyco#28150
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Closes #28150
Type of change
What does this PR do?
Issue: Granular read permission deny rules don't block file access. When a user configures
{ read: { "*.env": "deny", "*": "allow" } }, the deny rule is bypassed for paths likesrc/.env.Root cause: Wildcard
*was converted to regex.*, which matches any character including/. This meant*.envmatchedsrc/.env,a/b/.env, making it as broad as*. With "last matching rule wins" semantics, a later wildcard*rule always overrode specific deny rules for any path containing/.Fix: Made
*match any characters except/, added**globstar support for cross-directory matching. This aligns with standard glob semantics (gitignore, bash glob).Files changed:
1.
packages/core/src/util/wildcard.ts— core wildcard matchingChanged the regex generation:
*→[^/]*(matches any chars except/)**→.*(matches any chars including/)?→[^/](single char except/)Uses placeholder tokens to avoid
**being partially consumed by the*replacement and?corrupting the(?:...)?optional group in**/.2.
packages/opencode/src/util/wildcard.ts— same changes for the opencode copy3.
packages/opencode/src/agent/agent.ts— updated default permission rulesPatterns that need to match across directories now use
**:read:"*"→"**"(catch-all),"*.env"→"**/*.env"(deny at any depth)external_directory:"*"→"**"(catch-all)"*"suffix →"**"suffix4.
packages/opencode/src/permission/index.ts— defensive validationAdded type check in
fromConfig()to skip array/null values with a warning.Examples:
*.env.env,src/.env,a/b/.env.envonly**/*.env*.env(no**support).env,src/.env,a/b/.envsrc/*.envsrc/.env,src/a/.envsrc/.envonlysrc/**/*.envsrc/.env,src/a/.env****Config migration for users:
If your config uses
*to match files at any depth, change to**:How did you verify your code works?
Checklist