Skip to content

Destructive-command check stops asking about harmless /tmp work and written deploy hooks (GST-3207) - #4531

Closed
garrytan wants to merge 5 commits into
mainfrom
careful-tmp-asks-and-quote-gaps
Closed

garrytan wants to merge 5 commits into
mainfrom
careful-tmp-asks-and-quote-gaps

Conversation

@garrytan

@garrytan garrytan commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

The destructive-command check no longer asks about relative deletes in /tmp work folders after a second cd, a subshell or a loop, or about deploy hooks a command only writes to a file.
It blocks wipefs -a on every target and catches disk redirects written with quotes or through a link to /dev, so nothing a user runs gets less protection.
Nothing to do: the check runs in every session already.

What changed, by shape

Over-asks removed, each as a proven exemption on top of the existing ask:

  • A relative cd from /tmp scratch keeps scratch when the command makes no links (ln) and no part of the path below scratch is a symlink on disk (cd /tmp/w && cd sub && rm -rf out).
  • A statement after ; inside a subshell, $( ), backticks or a for/while/until/if/select/{ } body starts from the state the group was entered with, while no cd, pushd or popd ran inside it (cd /tmp/w && (make; rm -rf out)).
  • A for loop variable over plain literal words is a scratch target inside its own do ... done body: /tmp words anywhere, relative words after a cd into scratch. A use before or after the loop, a nested loop, a single quote, backslash or backtick in the body, any other assignment, read, local, eval and the like, a glob, ~, .. or a path after the variable keeps the ask.
  • cd "$W" reads W when W=... is the command's first statement and no single quote or backslash follows it, so W=/tmp/w && cd "$W" && rm -rf out is scratch. A relative cd with CDPATH set or named is never scratch.
  • A quoted target with a space (rm -rf "/tmp/scratch demo") is one word when its closing quote ends a word; rm "a b"c -r ~/x is read word by word as before. The root deny still reads each piece.
  • A heredoc written with cat > F <<'EOF' or tee F <<'EOF' is data: discards inside it don't ask. An unquoted end word counts only when the body has no $ or backtick, since bash runs those while writing. Deletes and force-pushes inside it still count, and the whole body is read as commands again when the command runs F (as a command, through a quoted path, or after bash, sh, source, ., exec, eval or xargs, sh < F included), pipes anything into a shell, pipes the heredoc on, or, for a file under hooks/, runs git push.
  • SQL TRUNCATE text printed by echo no longer asks because a later, separate statement has a pipe, a quoted ; inside a grep pattern no longer splits it, and text sent to /dev/null is text. A copy to another descriptor (>&3, 1>&2) still asks.

Gaps closed:

  • wipefs -a is denied on every target. The image-file exemption is gone: GEVA-560's 254,322 commands hold no wipefs -a at all (its 13 denies are force-pushes and deletes), so it never fired and every fact it had to prove was a way past the deny.
  • A redirect into a disk is denied with its quotes removed (>'/dev'/sdb, > "/dev/mmcblk0") and through a folder whose real path is /dev (> d/sdb with d -> /dev); mmcblk and rdisk join the redirect names.
  • A # inside quotes is no longer read as a comment, so rm -rf "a #" ~ is denied.
  • git push -fn --no-dry-run is a real force-push (the last flag wins).
  • \wipefs, wipefs'' and doubled quotes are caught; echo wipefs-archive is not (the deny needs wipefs as a word of its own).
  • SQL text asks again when a grep's output is piped to anything but a viewer (| sh), goes through $( ), backticks, <( ) or >( ), or comes from git grep -O / --open-files-in-pager. Statements are cut where bash cuts them, outside quotes.

Kept on purpose:

  • printf x >> f && git reset --hard on a clean tree stays allowed (G7). The hook runs before the command, so the only work that can be lost is what the same command writes; asking on every compound command that ends in a discard would bring back the false asks the clean-tree probe removed.
  • LC_ALL=C cd /tmp && rm -rf dir was already allowed at 1730386; a row pins it.
Tests and measurements

test/careful-replay.test.ts gains 95 FOLLOWUP_CASES rows, a REVIEW_CASES table from the review rounds, and a symlink test with a real /tmp folder; five wipefs rows move from allow to deny. Run against 1730386's check, 39 of the first 67 new or changed rows fail and the rest are controls; 19 of the 23 rows added after a second-model read of the first commit ask or deny where that commit allowed, and 4 of the 5 added after a second read of the fix ask where the fix allowed. Replay plus hook tests: 390 pass, 0 fail on bash 5.2.21 and on bash 3.2.57. Adjacent checks (hook scripts, setup hook syntax, state-root ratchet, Codex hooks, module size, spawnSync tripwire, bun entry isolation): 349 pass. Typecheck and the test typecheck ratchet are clean. 1,600 random command mixes at the first commit and 1,600 at the final one: no crash or fallback ask on either bash.

Corpus replays (feeding commands to the hook, nothing run): GEVA-560's 2,831 commands that main flagged and 55aaa6c allowed give the same decision at this head except 5 harmless deploy-hook heredocs that now allow, on both bashes. Of GEVA-560's 538 changed rows (cut text), 25 harmless discard rows (9 commands) now allow and all 16 destructive rows that 1730386 asks about still ask. GEVA-560's 102 incident rows keep every expected decision.

Latency, same machine, interleaved with 1730386 over the 102 incident rows (n=408 each), two passes: bash 5.2 p50 149.5 vs 151.2 ms and 133.9 vs 130.4 ms; bash 3.2 p50 195.6 vs 195.2 ms and 137.4 vs 132.6 ms. At the final head: bash 5.2 128.2 vs 124.8 ms, bash 3.2 130.6 vs 126.8 ms. Base p50 moved by up to 63 ms between passes, so the gaps are within run-to-run drift.

Open notes
  • Open blocker, so this PR is parked: a << after an unquoted # (cat > f # <<EOF, ls # ; cat > f <<EOF) is read as a heredoc. Bash treats it as a comment and runs the lines that follow, so a git reset --hard there is allowed here but asked on main. The fix is to cut each line at its first unquoted # before looking for <<.
  • Any discard after a cd still asks, as on main, cd $VAR && git reset -q --hard included: a profile function or alias between the two can move the folder, and the hook can't see the profile.
  • cd $VAR and rm -rf "$VAR" with VAR from the environment still ask: trusting the hook's environment for the Bash tool's shell is a design call.
  • A cd inside a group followed by ; ((cd sub; rm -rf out)) still asks, even when both folders are scratch.
  • Statements are still cut at a quoted ; for deletes and git (rm -rf "x;" ~ asks rather than denies), and echo cd /tmp still counts as a cd, as on main.
  • wipefs --no-act still denies (the a in act).
  • GEVA-2's 104 delete_outside asks were not changed: none could be proven harmless from the files this PR could read.
  • A /tmp folder that is itself a symlink still counts as scratch, as on main: cd /tmp/L && cd p && rm -rf s removes the same path main already allows as cd /tmp/L && rm -rf p/s.
  • wi''pefs -a and w"ipe"fs -a (quotes inside the word) are allowed here and on main.
  • A heredoc written to a file and then run by another program (make, find -exec) is not detected; only shells, source, exec, eval, xargs, a pipe into a shell and running the file by name are.
  • A loop operand given to another delete tool (for f in a b; do find $f -delete; done) allows exactly when its spelled-out form (find a -delete; find b -delete) allows on main.
Agent notes
{"head":"01870a0a5049dd0269a3d39e66208e80e5c2ffb9","run":"ship-4531-12ad94a","status":"started","review_loop":{"passes":2,"blocking_found":7,"deferred":0,"noted":4,"fixed":6,"scope":"frozen","rounds":2,"est_input_tokens":29618,"dispatches":{"specialist-batched":1,"red-team":2,"specialist":1}}}
{"head":"01870a0a5049dd0269a3d39e66208e80e5c2ffb9","run":"ship-4531-12ad94a","mark":"stop","tree":"a026ac3a9cd294d6f17d3eb8f2b4a8a2479fc458"}

…ritten deploy hooks, and closes the last quote tricks around disk wipes (GST-3207)

Drops the wipefs image-file exemption (0 uses in GEVA-560's corpus), reads disk redirects through quotes and /dev symlink folders, keeps quoted # out of comments, rebuilds the SQL-text exemption on a quote-aware cut, and keeps scratch through a second cd, groups, loop variables and set variables. Heredocs written to files no longer trigger discard asks until they are run.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 19, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

garrytan and others added 4 commits November 19, 2026 15:40
…new exemptions

Loop variables count only inside their own loop body, a cd into a
variable counts only when the command sets it first, CDPATH or .. make
a cd's folder unknown, a heredoc is data only when its end word is
quoted or its body has no $ or backtick, a written file run through a
quoted path, a shell reading it or a pipe into a shell is read as
commands, a quoted rm target is joined only when its quote closes the
word, and an echo copied to another descriptor is no longer plain text.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
A quoted ~ in a cd leaves its folder unknown, printf -v, source and . turn
off loop-variable tracking, a quoted target with a space no longer
compares to the working folder with _ in place of the space, and only
an exact /dev/null redirect counts as throwing text away.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… loop or rebound variable can move the folder

The review of this change found six commands the new exemptions allowed but
the old check asked about, each of which could delete files or discard
uncommitted work. The check now asks again when a shell function, source, .
or eval could change the folder; when a loop body cds after the delete; when
cd uses a variable the command sets again (read, printf -v, +=, for); when cd
is written as \cd, \pushd or with quotes; and when a file written from a
heredoc is followed by any command other than a short read-only list (make,
just or git commit run a written file without naming it).

Review-Finding: p1s/specialist-batched#1 reader=state-machines
Review-Finding: p1s/specialist-batched#2 reader=state-machines
Review-Finding: p1s/specialist-batched#3 reader=security
Review-Finding: p1s/red-team#1 reader=red-team
Review-Finding: p1s/red-team#2 reader=red-team
Review-Finding: p1s/red-team#3 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
A profile function or alias between a cd and git reset --hard can move
the folder, so after any cd the uncommitted-work check asks, as it did
before this change, instead of probing the folder the cd leads to.

Review-Finding: p2b/red-team#1
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai

capy-ai Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Closing this in favor of #4534, which landed on main as ab6a38b. It carries only the changes from this branch that make the check stricter. The exemptions here (scratch tracking, the deploy-hook heredoc allow, the SQL text exemption and the quoted /tmp path) come back later as one design pass, replayed on the full command corpus before review.

@capy-ai capy-ai Bot closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant