Repository navigation
Conversation
…ratch cleanup The destructive-command gate had drifted in both directions: it missed several operations that really do destroy, and it fired on prose and on throwaway directories. Coverage gaps closed: - `dd` could never fire on a real invocation. `/\bdd\s+if=\b/` needs a word character after `=`, but every real use continues with a path, so `dd if=/dev/zero of=/dev/sda` did NOT match while the inert `dd if=x` did. `of=` — the operand that actually writes — was never matched at all. `dd` now has a command-position rule covering both operands. - `rm -r` without `-f` was waved through: the rule required BOTH flags, so a recursive delete of a source tree passed unchallenged. - `find -delete` had no rule; only `-exec <destroyer>` was covered. - `shred`, a standalone `unlink`, and the coreutils `truncate` had no rule. `unlink` was recognised only inside `find -exec`. Precision fixes: - `truncate` was matched as a bare word, so every mention of it was destructive: the Jinja/Django filter of the same name, a branch name, a file name, a line of prose in a commit body. SQL truncation always names a table, so the pair is now required; the coreutils binary is caught in command position instead. - Delete targets that resolve to scratch space, build caches, virtualenvs or test artefacts no longer raise the gate. Bare `/tmp` is deliberately excluded, so `rm -rf /tmp/junk` is still challenged. Supporting changes: - `stripQuotedStrings` can now stash quoted literals in a slot table instead of blanking them. A quoted argument still tokenizes as one opaque token, so `git commit -m '(rm -rf x)'` stays inert, but the literal is recoverable — without it `rm -rf "$SCRATCH/build"` cannot be judged at all. Both quote styles are matched in one left-to-right alternation rather than two sequential passes, which is how the shell reads mixed quoting. - `NAME=value` assignments in the same command line are resolved before a target is judged, since scripts define the scratch root in the very command that deletes from it. `$(mktemp -d)` is treated as disposable. A target still carrying an unresolved `$VAR`, a bare root, or any operand that is not clearly derived keeps the gate loud. - `isDestructiveQuoteAware` now receives the same context and the new rules. Without this the disposable-target decision made in the main pass was silently reversed by the later one, and `sh -c` could have bypassed the additions. The GHSA-4v57-ph3x-gf55 regression tests still pass. Measured against 20,737 distinct Bash commands from 14 days of real agent traffic: denials fall from 273 to 138 (-49%) with zero commands newly challenged. Every one of the 41 distinct paths that stopped raising the gate is a scratchpad, mktemp directory, .venv, test-results, .playwright-mcp or gitignored plan directory. 19 tests added; suite goes 144 -> 163, all passing.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Separate from this PR's diff, the same measurement turned up something structural that I think is worth a maintainer's opinion before anyone writes code for it. Filing it here rather than as a patch, because the fix is an architecture choice, not a detector tweak. The retry key is set by the denial itselfIn all three gates, if (!isChecked(key)) {
if (!markChecked(key)) return allowWithStateWarning();
return denyResult(...); // key already recorded above
}
return rawInput; // second attempt: allowedSo the second attempt always succeeds, whether or not a single fact was presented. A Two consequences, both measured over 14 days of one operator's real traffic (2,605 denials, 120 sessions):
The first-touch gates have the same shape with a per-path key, so the cost is per file rather than per command: 2,454 of the 2,605 denials (94.6%) came from those two gates, and none of them blocked anything a second unchanged attempt did not immediately perform. A possible directionThe signal for "did it investigate" is not text — it is an action, and actions are observable at That is a bigger change than this PR, and it interacts with |
|
This PR is stale due to inactivity. |
The destructive-command gate had drifted in both directions: it missed
several operations that really do destroy, and it fired on prose and on
throwaway directories.
Coverage gaps closed:
ddcould never fire on a real invocation./\bdd\s+if=\b/needs aword character after
=, but every real use continues with a path, sodd if=/dev/zero of=/dev/sdadid NOT match while the inertdd if=xdid.
of=— the operand that actually writes — was never matched atall.
ddnow has a command-position rule covering both operands.rm -rwithout-fwas waved through: the rule required BOTH flags,so a recursive delete of a source tree passed unchallenged.
find -deletehad no rule; only-exec <destroyer>was covered.shred, a standaloneunlink, and the coreutilstruncatehad norule.
unlinkwas recognised only insidefind -exec.Precision fixes:
truncatewas matched as a bare word, so every mention of it wasdestructive: the Jinja/Django filter of the same name, a branch name,
a file name, a line of prose in a commit body. SQL truncation always
names a table, so the pair is now required; the coreutils binary is
caught in command position instead.
virtualenvs or test artefacts no longer raise the gate. Bare
/tmpisdeliberately excluded, so
rm -rf /tmp/junkis still challenged.Supporting changes:
stripQuotedStringscan now stash quoted literals in a slot tableinstead of blanking them. A quoted argument still tokenizes as one
opaque token, so
git commit -m '(rm -rf x)'stays inert, but theliteral is recoverable — without it
rm -rf "$SCRATCH/build"cannotbe judged at all. Both quote styles are matched in one left-to-right
alternation rather than two sequential passes, which is how the shell
reads mixed quoting.
NAME=valueassignments in the same command line are resolved beforea target is judged, since scripts define the scratch root in the very
command that deletes from it.
$(mktemp -d)is treated as disposable.A target still carrying an unresolved
$VAR, a bare root, or anyoperand that is not clearly derived keeps the gate loud.
isDestructiveQuoteAwarenow receives the same context and the newrules. Without this the disposable-target decision made in the main
pass was silently reversed by the later one, and
sh -ccould havebypassed the additions. The GHSA-4v57-ph3x-gf55 regression tests still
pass.
Measured against 20,737 distinct Bash commands from 14 days of real
agent traffic: denials fall from 273 to 138 (-49%) with zero commands
newly challenged. Every one of the 41 distinct paths that stopped
raising the gate is a scratchpad, mktemp directory, .venv,
test-results, .playwright-mcp or gitignored plan directory.
19 tests added; suite goes 144 -> 163, all passing.