fix(approval): catch perl/ruby -i as a separate flag token

The salvaged pattern matched -i only inside the first flag token, so
`perl -p -i -e '...' config.yaml` (the -i split out after -p) slipped
through. Widen to match a -...i flag token anywhere in the args; still
no false positive on `perl -e` code eval or config reads. Adds tests
for the separate-token, backup-suffix, and read-safe forms.
This commit is contained in:
Teknium
2026-06-04 05:36:30 -07:00
parent a6a4e6f9d7
commit b04c6e95f6
2 changed files with 30 additions and 1 deletions
+6 -1
View File
@@ -446,7 +446,12 @@ DANGEROUS_PATTERNS = [
# perl -i and ruby -i perform the same in-place mutation as sed -i but are
# not caught by the -e/-c script-execution pattern above (which targets code
# evaluation, not file mutation). Pairs the sed -i coverage from #14639.
(rf'\b(?:perl|ruby)\s+-[^\s]*i.*(?:{_HERMES_CONFIG_PATH}|{_HERMES_ENV_PATH})', "in-place edit of Hermes config/env (perl/ruby)"),
# The -i flag can appear as its own token after other flags
# (`perl -p -i -e ... config.yaml`), combined (`perl -pi -e`), or with a
# backup suffix (`perl -i.bak`). Match any flag token containing `i`
# anywhere in the args, not just the first token — `perl -e '...'` (code
# eval, no -i) does not trip because it has no `-...i` flag token.
(rf'\b(?:perl|ruby)\b.*(?:^|\s)-[^\s]*i\b.*(?:{_HERMES_CONFIG_PATH}|{_HERMES_ENV_PATH})', "in-place edit of Hermes config/env (perl/ruby)"),
# Script execution via heredoc — bypasses the -e/-c flag patterns above.
# `python3 << 'EOF'` feeds arbitrary code via stdin without -c/-e flags.
(r'\b(python[23]?|perl|ruby|node)\s+<<', "script execution via heredoc"),