Problem
block-dangerous-git.sh blocked a PowerShell command that invokes no git command at all.
Reproduction
A PowerShell script measuring directory sizes was blocked with:
BLOCKED: this PowerShell 'git' command cannot be parsed with confidence — blocked (fail-closed).
Trigger: a construct the guard cannot faithfully tokenize (backtick, '--%', subexpression, or {}/() grouping).
The command's only relationship to git was the literal string '.git' appearing inside an array membership test used to classify directory names:
Get-ChildItem -LiteralPath $p -Recurse -Force -Directory |
Where-Object { $_.Name -in @('node_modules','obj','bin','.git') } |
ForEach-Object { ... }
No git executable is invoked anywhere in it.
Analysis
Two independent failures compose here:
- Detection: the guard appears to match the substring
git against the command text rather than detecting git in command position. .git — a string that appears in most filesystem tooling on a developer machine — is enough to engage it.
- Tokenization: having engaged, it then finds
{} grouping it cannot parse and fails closed. But ForEach-Object { } and Where-Object { } are the ordinary way to write PowerShell; treating scriptblock braces as suspicious makes idiomatic PowerShell unrunnable.
The practical effect is that while the guard is active, most non-trivial PowerShell touching the filesystem is blocked, whether or not it has anything to do with git.
Proposed change
Detect an actual git invocation — command position, not substring — before engaging the tokenizer at all, so a command that never calls git is deferred instantly and never reaches the fail-closed path.
Acceptance criteria
- A PowerShell script containing the string
.git but invoking no git command is not blocked.
- A genuine
git reset --hard / git clean -fd / git checkout -- in any spelling the guard handles today is still blocked.
- The fail-closed behavior is retained for commands that do invoke git and cannot be tokenized.
Problem
block-dangerous-git.shblocked a PowerShell command that invokes no git command at all.Reproduction
A PowerShell script measuring directory sizes was blocked with:
The command's only relationship to git was the literal string
'.git'appearing inside an array membership test used to classify directory names:No
gitexecutable is invoked anywhere in it.Analysis
Two independent failures compose here:
gitagainst the command text rather than detectinggitin command position..git— a string that appears in most filesystem tooling on a developer machine — is enough to engage it.{}grouping it cannot parse and fails closed. ButForEach-Object { }andWhere-Object { }are the ordinary way to write PowerShell; treating scriptblock braces as suspicious makes idiomatic PowerShell unrunnable.The practical effect is that while the guard is active, most non-trivial PowerShell touching the filesystem is blocked, whether or not it has anything to do with git.
Proposed change
Detect an actual
gitinvocation — command position, not substring — before engaging the tokenizer at all, so a command that never calls git is deferred instantly and never reaches the fail-closed path.Acceptance criteria
.gitbut invoking no git command is not blocked.git reset --hard/git clean -fd/git checkout --in any spelling the guard handles today is still blocked.