Files
ECC/scripts/hooks
Nguyen Thanh Dat 89c1bf4fff fix(gateguard): run env's split string through classification, not past it
Review feedback on #2832 — CodeRabbit and Greptile independently flagged the
same bypass, and it reproduces.

`env` declares `-S` / `--split-string` as value-consuming, so
`stripCommandWrappers` skipped the option AND its value. But that value is the
command: `env -S "rm -rf /important/data"` runs the deletion, and the hook saw
no `rm` token at all. Measured against the built hook, all three spellings were
allowed while the bare `rm -rf` was denied:

    deny    rm -rf /important/data
    (none)  env -S "rm -rf /important/data"
    (none)  env --split-string="rm -rf /important/data"
    (none)  env -S"rm -rf /important/data"

Expand the split string into tokens and keep walking, so a wrapper nested inside
it (`env -S "sudo rm -rf /"`) is stripped too. Bounded by
MAX_WRAPPER_EXPANSIONS so a self-referential string cannot spin.

The second half is the mirror image — a false positive.
`command -v git reset --hard` only reports where `git` resolves; nothing runs.
The wrapper walk dropped `-v` and classified the operand, so a lookup was
denied. `-v`, `-V`, and combined forms like `-pv` now yield no executable
tokens, while `-p` alone still does, because it executes.

`env -S "npm run build"` stays allowed and `command -p rm -rf /` still denies.

192 passed, 0 failed. Mutation-tested: dropping the expansion fails 5, dropping
the lookup guard fails 3.
2026-08-25 18:45:10 +07:00
..