Skip to content

guardrails: block-dangerous-git.sh blocks PowerShell commands that invoke no git command #2592

Description

@kyle-sexton

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:

  1. 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.
  2. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions