Row 18 of the review (with @teknium1's analysis): the floors restored the
raw command only when DownloadThenRunMatcher recognized a run of the file
a `cat` heredoc wrote. What can execute that file has no end (`mv` then
run, a variable, find -exec, xargs, make, npm scripts, crontab, git hooks,
a bin dir, rc files), so each unrecognized run dropped the body from the
floors and `approvals.mode: off` approved it.
The hardline and deny floors now always scan the raw command alongside
the body-dropped copies, as main does, so they are never looser than main.
The dropped copies still expose a command after the terminator that a
body quote hid (#140704), so those rows stay stricter than main. Only the
dangerous-prompt layer drops a `cat` body as data (a miss there costs a
prompt, not a block), and it keeps the run tracking so a written script
that the same string runs still prompts.
Trade-off, as on main: a data-only heredoc that names a hardline or denied
command hits the floor again. Tests that pinned "quiet on the deny list"
now pin "the doc adds no prompt", and a new test pins the floors for
unrecognized runs.
Co-authored-by: Bear Huddleston <196404565+BearHuddleston@users.noreply.github.com>
Rows 16 and 17 of the review: two spelling families that run the file a
heredoc just wrote never reached the run or read-run passes, so main's
hardline and deny floors were lost on them.
- A command string handed to a shell, pwsh/powershell, cmd or su
(`bash -c 'bash job.sh'`, `sudo sh -c "sh job.sh"`, `su -c '…' root`,
`cmd /c "call j.bat"`) is a command line of its own. Both run regexes
now accept that carrier prefix, and `call` counts as a run keyword.
- PowerShell runs a file's content through Invoke-Expression or a script
block (`iex (gc j.ps1 -Raw)`, `Get-Content j.ps1 | iex`,
`[scriptblock]::Create((gc j.ps1 -Raw))`), or dot-sources/calls it in a
-Command string. A new _PS_READ_RUN_RE pass catches these when FILE was
written earlier in the same string.
Patch from the review applied unchanged.
Co-authored-by: Bear Huddleston <196404565+BearHuddleston@users.noreply.github.com>
#155452 moved _PIPE_PATH_PREFIX_RE and _PIPE_WRAPPERS_RE into
tools/approval_pipe_launchers.py. This branch had defined the same two
names, with identical values, in approval_fetch_exec.py, so after the
rebase approval_detection.py imported them twice (F811). Import them from
approval_pipe_launchers in both modules and drop the duplicate
definitions. No behaviour change: the compiled patterns are the same
objects.
A `cat > f <<'EOF'` body dropped from the floors' scan copies when the same
command ran the file's content (`eval "$(cat f)"`, `cat f | bash`,
`bash <(cat f)`, `sh -c "$(< f)"`), passed runner option values before the
script (`bash -euo pipefail f`, `bash -o pipefail f`, `python3 -W ignore f`),
or ran it through pwsh/powershell/cmd. main scans those bodies; the
download-then-run matcher now recognises the content-run forms and parses
each runner's option values, keeping syntax checks and piped programs with
their own script operand quiet.
Refs #108235
Co-authored-by: Bear Huddleston <196404565+BearHuddleston@users.noreply.github.com>
After a same-string heredoc write, `"/bin/bash" job.sh`, `sudo 'bash'
job.sh` and `C:\Git\bin\bash.exe job.sh` did not count as running the
file, so its body left the hardline floor (main floors all three). Accept
the pipe sink's token shape (optional quotes, `.exe`) around the runner.
A path-qualified program word that is itself the download counts as a
run too, which restores `./node --check app.js` / `./python3 s.py` after
downloading node/python3 and keeps `./node.exe --version` flagged; bare
names resolve through PATH and stay quiet.
Refs #108235
Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
A written cat script run through a path-qualified shell, a launcher with
valued options (sudo -u root, timeout 60), a VAR= prefix, a compound
keyword, ( / { / | starts or `shell < FILE` lost main's hardline and deny
floors. The run matcher now reuses the pipe sink's launcher grammar
with whitespace kept on one line, and `command -v` becomes a post-filter
on the matched span. The launcher table stays in approval_pipe_launchers;
_pipe_launcher_re gains a `ws` parameter defaulting to `\s`, so the pipe
sink's pattern is unchanged. _PIPE_PATH_PREFIX_RE and _PIPE_WRAPPERS_RE
move here from approval_detection.
Refs #140704
Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
Review follow-up to NousResearch/hermes-agent#155467 (c2h5oh).
A /bin/bash invocation executes the just-written script, so scan its
heredoc body through the existing hardline and deny gates.
(cherry picked from commit afa410228d4475ffcf0db671301e4f24abca5c33)
The flag group in the write-then-run matcher allowed \s, so `bash -n` at the
end of a line took the next line's `./i.sh` as its operand; the run was then
skipped as a syntax check and a heredoc body it wrote fell off the floors.
Flag whitespace now stays on one line. Also pin that every flag must be the
tool's check flag (bash -n -e, node --inspect, php -f stay flagged).
Refs #108235
Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
`curl -o f URL && command -v f` and `... && bash -n f` / `node --check f` /
`ruby -c f` / `php -l f` name the downloaded file without executing it.
The skip applies only when every flag is the check flag; `perl -c` stays
flagged because it runs BEGIN/use blocks.
Refs #108235
Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
curl -O/--remote-name saves under the URL basename; written files may be quoted (> 'j'), appended (>>), run behind sudo/env/nohup/exec with VAR= words, quoted, after a cd (basename on both sides, over-matching on purpose), or by a script interpreter. Timing bound raised to the 2 s tests/AGENTS.md floor with curl -O stress inputs; every new repeat is possessive.
Refs #108235
cat <<'EOF' > job.sh ... bash job.sh lost its body from the hardline, dangerous and deny scans. Scan the raw command too whenever a dropped body's file is executed later in the string, in both _command_detection_variants and the deny projections.
Refs #108235
Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
The #140708 masking blanked every heredoc body whatever its consumer, and to end-of-string on a
`<<` that is not a heredoc, so `cat <<EOF | sh`, `sh -s`/`bash`/`ssh host <<EOF` bodies and
`echo $((1<<2))\n<cmd>` fell off the hardline floor. Masking now reuses the
strip_inert_heredoc_bodies rule (quoted delimiter, exact terminator, allowlisted consumer, no
pipe/list after the heredoc, nothing unknown or unterminated anywhere): `cat` bodies are dropped
outright; python/osascript bodies are code, so their dropped copy is scanned in addition to the raw
one. Bodies are removed rather than blanked, since long whitespace runs made the `\s*`
command-position prefixes backtrack (300-line `cat <<'EOF'`: 108 s -> 0.16 s).
The download-then-run regex retried a lazy `[^\n]*?(?P=dl)` from every fetch (64 KB of
`curl -o f`: 12.8 s for the rule). It is now a two-step matcher in tools/approval_fetch_exec.py:
collect each fetch segment's -o/-O/--output/> targets, then check later command starts against
them (rule alone < 0.05 s).
Fixes#140704
Refs #108235#140708