Repository navigation
Destructive-command check stops asking about harmless /tmp work and written deploy hooks (GST-3207) - #4531
Closed
garrytan wants to merge 5 commits into
Closed
Destructive-command check stops asking about harmless /tmp work and written deploy hooks (GST-3207)#4531garrytan wants to merge 5 commits into
garrytan wants to merge 5 commits into
Conversation
…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>
|
Merging to
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 |
…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>
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The destructive-command check no longer asks about relative deletes in
/tmpwork folders after a secondcd, a subshell or a loop, or about deploy hooks a command only writes to a file.It blocks
wipefs -aon 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:
cdfrom/tmpscratch 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).;inside a subshell,$( ), backticks or afor/while/until/if/select/{ }body starts from the state the group was entered with, while nocd,pushdorpopdran inside it (cd /tmp/w && (make; rm -rf out)).forloop variable over plain literal words is a scratch target inside its owndo ... donebody:/tmpwords anywhere, relative words after acdinto 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,evaland the like, a glob,~,..or a path after the variable keeps the ask.cd "$W"readsWwhenW=...is the command's first statement and no single quote or backslash follows it, soW=/tmp/w && cd "$W" && rm -rf outis scratch. A relativecdwithCDPATHset or named is never scratch.rm -rf "/tmp/scratch demo") is one word when its closing quote ends a word;rm "a b"c -r ~/xis read word by word as before. The root deny still reads each piece.cat > F <<'EOF'ortee 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 runsF(as a command, through a quoted path, or afterbash,sh,source,.,exec,evalorxargs,sh < Fincluded), pipes anything into a shell, pipes the heredoc on, or, for a file underhooks/, runsgit push.TRUNCATEtext printed byechono 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/nullis text. A copy to another descriptor (>&3,1>&2) still asks.Gaps closed:
wipefs -ais denied on every target. The image-file exemption is gone: GEVA-560's 254,322 commands hold nowipefs -aat 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.>'/dev'/sdb,> "/dev/mmcblk0") and through a folder whose real path is/dev(> d/sdbwithd -> /dev);mmcblkandrdiskjoin the redirect names.#inside quotes is no longer read as a comment, sorm -rf "a #" ~is denied.git push -fn --no-dry-runis a real force-push (the last flag wins).\wipefs,wipefs''and doubled quotes are caught;echo wipefs-archiveis not (the deny needswipefsas a word of its own).| sh), goes through$( ), backticks,<( )or>( ), or comes fromgit grep -O/--open-files-in-pager. Statements are cut where bash cuts them, outside quotes.Kept on purpose:
printf x >> f && git reset --hardon 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 dirwas already allowed at 1730386; a row pins it.Tests and measurements
test/careful-replay.test.tsgains 95FOLLOWUP_CASESrows, aREVIEW_CASEStable from the review rounds, and a symlink test with a real/tmpfolder; 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
<<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 agit reset --hardthere is allowed here but asked on main. The fix is to cut each line at its first unquoted#before looking for<<.cdstill asks, as on main,cd $VAR && git reset -q --hardincluded: a profile function or alias between the two can move the folder, and the hook can't see the profile.cd $VARandrm -rf "$VAR"withVARfrom the environment still ask: trusting the hook's environment for the Bash tool's shell is a design call.cdinside a group followed by;((cd sub; rm -rf out)) still asks, even when both folders are scratch.;for deletes and git (rm -rf "x;" ~asks rather than denies), andecho cd /tmpstill counts as acd, as on main.wipefs --no-actstill denies (theainact).delete_outsideasks were not changed: none could be proven harmless from the files this PR could read./tmpfolder that is itself a symlink still counts as scratch, as on main:cd /tmp/L && cd p && rm -rf sremoves the same path main already allows ascd /tmp/L && rm -rf p/s.wi''pefs -aandw"ipe"fs -a(quotes inside the word) are allowed here and on main.make,find -exec) is not detected; only shells,source,exec,eval,xargs, a pipe into a shell and running the file by name are.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