Uh oh!
There was an error while loading. Please reload this page.
fix(permission): make * not match / in wildcard patterns, add ** globstar support - #28689
fix(permission): make * not match / in wildcard patterns, add ** globstar support#28689lexlian 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 Fixesanomalyco#28150
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
martin-braun
commented
Aug 13, 2026
Current implementation https://github.com/anomalyco/opencode/blob/dev/packages/core/src/util/wildcard.ts and documentation is using globstars implying A bummer this got auto closed, but how would you even not make this a breaking change at this point? -.- |
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