Files
ECC/scripts/hooks
Nguyen Thanh Dat f48abf7f22 fix(gateguard): read env's option cluster and the split string's own quoting
Two follow-ups on the previous commit, both reported and both reproduced.

CodeRabbit: `env -vS "rm -rf /"` still bypassed. `envSplitString` only matched a
token starting with `-S`, but getopt gives the first argument-taking option in a
cluster the rest of the token — so `-S` is reachable through `-v`/`-i`, attached
or separate. Walk the cluster instead of anchoring at position 1.

That walk has to stop at `-u`/`-C`, which claim the cluster themselves. Without
that stop, `env -uSHELL rm -rf /important/data` reads `HELL` as the split string,
`HELL` is the command word, and the deletion is allowed. Mutation-testing the
first draft is what surfaced this: removing the stop passed all 200 tests, so
the case is now pinned.

Greptile: the split string carries its own quoting, and expanding it with a
whitespace-only split left `env -S '"rm" -rf /'` with a command word of `"rm"`,
which matches nothing. Expand with the file's quote-aware tokenizer, falling
back to the plain split if it cannot parse.

    deny    env -vS"rm -rf /important/data"
    deny    env -iS "rm -rf /important/data"
    deny    env -S '"rm" -rf /important/data'
    deny    env -S 'env -S "rm" -rf /important/data'
    deny    env -uSHELL rm -rf /important/data
    (none)  env -uS FOO
    (none)  env -vS "npm test"
    (none)  env -C /tmp npm run build

202 passed, 0 failed. Mutation-tested: anchoring `-S` at position 1 fails 3,
dropping quote awareness fails 2, dropping the `-u`/`-C` stop fails 1.
2026-08-25 19:15:02 +07:00
..