Skip to content

guardrails: an apostrophe inside a double-quoted string deletes the command from every PowerShell sink-trigger scan (fail-open on all three blocking hooks) #2965

Closed

Description

@kyle-sexton

ps::blank_quoted_spans pairs quote characters with two independent sed passes that have no notion of which quote style opened first. An apostrophe inside a DOUBLE-quoted string is a literal character to PowerShell, but the single-quote pass treats it as a span delimiter — so two apostrophe-bearing double-quoted strings straddling a command delete that command outright from the text every sink-trigger scan measures.

The result is a general bypass of the fail-closed sink on all three blocking hooks. A destructive git command, or a computed writer call, placed between two such strings is not merely mis-measured — it is invisible.

Observed

rc from each hook's .sh, payloads built with jq as real PreToolUse envelopes with tool_name: "PowerShell" (no shell quoting touched the command string). Measured against origin/main = 6dc12e45ab92b5093ddd129d1fb8c1bd005a4be1, PRISTINE — no patch applied.

command block-dangerous-git block-no-verify block-hook-bypass
& ('g'+'it') push --force (control) 2 2 —
Write-Host "a'b"; & ('g'+'it') push --force; Write-Host "c'd" 0 0 —
Write-Host "Kyle's build"; & ($tool) push --force; Write-Host "that's all" 0 0 —
& ('set-'+'content') f.txt x (control) — — 2
Write-Host "a'b"; & ('set-'+'content') f.txt x; Write-Host "c'd" — — 0

The controls are the point: each command blocks correctly on its own. Adding two ordinary double-quoted strings that happen to contain apostrophes — "Kyle's build", "that's all" — is what makes it vanish.

Cause

ps::blank_quoted_spans (plugins/guardrails/lib/powershell/ps-command.sh, ~line 163):

text=$(printf '%s' "$text" | sed -e "s/'[^']*'//g" -e 's/"[^"]*"//g')

Two passes, each blind to the other. The single-quote pass runs first and matches from the apostrophe inside the first double-quoted string to the apostrophe inside the last, consuming everything between them.

Demonstrated by calling the library function directly on the pinned tree:

input:  Write-Host "a'b"; & ('g'+'it') push --force; Write-Host "c'd"
output: Write-Host

The entire command reduces to one token. ps::classify_git_command's sink-trigger scan then sees no special construct, no dynamic invocation, and no launcher, so the fail-closed sink is never entered — this is an entry-side failure, not a measuring-probe failure. Every downstream probe is irrelevant because none of them run.

Severity

Higher than the over-block in issue 2926, and higher than the residual in issue 2906. Both of those require the guard to reach a probe and mis-answer. This one removes the evidence before the guard decides whether to look at all, on all three blocking hooks, using only ordinary PowerShell string content.

Not a regression from any recent PR

The two-pass sed predates PR 2890, PR 2908, and PR 2925. This is long-standing shipped behavior, surfaced now rather than introduced now.

Fix direction (not prescriptive)

The safe direction for an ENTRY scan is to OVER-block, never to under-block, so the fix does not need a faithful PowerShell lexer:

  • Blank quoted spans in a single LEFT-TO-RIGHT pass in which whichever quote character opens first owns its span, so an apostrophe inside a double-quoted span is ordinary text. The file already carries ps::_skip_double_quote and ps::_skip_single_quote for exactly this kind of walk in the sink-blanking path; the same discipline applied here would resolve the pairing correctly without new machinery.
  • Where pairing remains ambiguous (an unterminated span, a smart quote, a backtick-escaped delimiter), resolve toward NOT deleting — leaving text in view can only cause an over-block, while deleting it causes the fail-open documented above.

Guard on any fix

The six issue-2848 acceptance cases must stay rc=0 on all three blocking hooks:

  • $py = "..."; if (-not (Test-Path $py)) { $py = (Get-Command python).Source }; & $py run.py --flag
  • & $py $script (Join-Path $dir "$id.jsonl")
  • & $py -m unittest discover
  • . $PROFILE
  • & $py script.py
  • foreach ($x in @('a')) { & $w f.txt }

and prose that merely mentions a write or a git command must stay inert, since ps::blank_quoted_spans is what makes it inert:

  • Write-Host 'example > out.txt'
  • git commit -m 'use -Value x'
  • echo 'run & $($w) f.txt x later'

Provenance

Surfaced by a fresh-context adversarial verifier probing merged content while a separate change to issue 2926 was being evaluated, then independently re-measured against pristine 6dc12e45a before filing.

Related

  • issue 2926 — the over-block whose evaluation surfaced this; that one is friction, this one is a bypass.
  • issue 2906 — a different pre-existing evasion rooted in the same function's deletion semantics.
  • issue 2848 — the over-block removal whose acceptance cases any fix here must preserve.

Activity

  1. added
    needs-triage
    on Aug 17, 2026
  2. added 2 commits that reference this issue on Aug 21, 2026
    e1bc5ee
    761967d
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

    needs-triage

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions