Skip to content

Allow wildcard patterns in the trust file - #3077

Closed
ktherage wants to merge 1 commit into
phpactor:masterfrom
ktherage:trust-glob-patterns
Closed

ktherage wants to merge 1 commit into
phpactor:masterfrom
ktherage:trust-glob-patterns

Conversation

@ktherage

@ktherage ktherage commented Oct 20, 2026 •

Copy link
Copy Markdown

Motivation

Trust is stored as a map of exact project directories, so trusting a whole workspace means adding one entry per project:

{
    "/home/me/projects/one": true,
    "/home/me/projects/two": true
}

This adds wildcard support, so a workspace can be trusted with a single entry:

{
    "~/projects/*": true
}

Behaviour

  • * matches any sequence of characters, including /, so nested project directories are covered too.
  • A leading ~ (or ~/, ~\) is expanded to the home directory ($HOME, falling back to %USERPROFILE%).
  • Exact path entries take precedence over patterns; otherwise the longest matching pattern wins, so a more specific pattern can exclude a directory from a broader one.
  • * is the only wildcard: ? and [] are matched literally, with or without a * in the same pattern.
  • A matching entry with a false value still counts as a decision: {"*": false} stops the language server from asking about every project, and an exact true entry (e.g. from phpactor config:trust) overrides it.
  • Patterns are matched against the project root as Phpactor resolves it, so they must be absolute or start with ~.

Security

Trusting a directory allows Phpactor to load a configuration file that can execute arbitrary code. The trust documentation now repeats this and recommends keeping patterns narrow (/home/me/projects/*, not /home/me/*).

Tests

  • TrustTest: exact match, wildcard match (including nested directories), negative patterns, exact vs. pattern precedence, most specific pattern, literal ? with and without *, ~ expansion for both patterns and exact entries, matching untrusted pattern as a decision, unconditional trust.
  • New system test: a trust.json containing a wildcard makes config:dump report core.trusted: true and load the project's .phpactor.json.
  • phpstan and php-cs-fixer are clean on the changed files.

Entries can contain a `*` wildcard and start with `~` (home directory),
so a whole workspace can be trusted with a single entry. Exact paths take
precedence, otherwise the longest matching pattern wins.
@ktherage

ktherage commented Oct 20, 2026 •

Copy link
Copy Markdown
Author

Closing this in favour of #3078.

On reflection this is a much broader topic than a simple regex: trust is deliberately per-path and non-recursive (#2923, #2924), and a wildcard changes what a decision means for directories that do not exist yet. I would rather agree on the shape (subtree grant vs. wildcard vs. generating exact entries from tooling) before proposing code.

@ktherage ktherage closed this Oct 20, 2026
@ktherage
ktherage deleted the trust-glob-patterns branch October 20, 2026 09:29
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.

1 participant