mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 00:21:14 +01:00
Destructive-command check blocks four more ways past its disk-wipe and force-push checks (GST-3207) (#4534)
The destructive-command check now blocks `wipefs -a` on every target, disk redirects written with quotes or through a link to `/dev`, and `git push -fn --no-dry-run`. It only gets stricter: replaying 3,471 recorded agent commands against the previous check moves 0 decisions toward allow. Nothing to do: the check runs in every session already. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/outside-voice#1 reader=outside-voice Review-Finding: p1/adversarial-native#1 reader=adversarial-native Review-Finding: p1/red-team#2 reader=red-team
This commit is contained in:
1 parent
a0534ce6db
commit
ab6a38b767
3 files changed
+127
-80
No files matched your search
@@ -211,7 +211,7 @@ const PARSER_CASES: Array<[string, string, Decision, Tree]> = [
|
||||
['dry run in another statement', 'aws s3 rm s3://example-invalid/demo --recursive --dryrun; terraform destroy', 'ask', 'clean'],
|
||||
['dry run in another statement', 'terraform destroy -var name=plan', 'ask', 'clean'],
|
||||
['push dry run in a flag group', 'git push -nf origin main', 'allow', 'clean'],
|
||||
['wipefs on a file', 'wipefs -a demo.img', 'allow', 'clean'],
|
||||
['wipefs on a file (GST-3207: no image exemption)', 'wipefs -a demo.img', 'deny', 'clean'],
|
||||
['wipefs on a file (control)', 'wipefs -a /dev/sdb', 'deny', 'clean'],
|
||||
['SQL shape in a search or text', "grep 'truncate demo;' fixtures.sql", 'allow', 'clean'],
|
||||
['SQL shape in a search or text', "echo 'truncate demo;'", 'allow', 'clean'],
|
||||
@@ -235,7 +235,7 @@ const PARSER_CASES: Array<[string, string, Decision, Tree]> = [
|
||||
['round 2: cd after time', 'time cd B && git reset --hard', 'ask', 'clean'],
|
||||
['round 2: cd then a discard (control)', 'cd B && git clean -fdx', 'ask', 'clean'],
|
||||
['round 2: an image suffix under /dev', 'wipefs -a /dev/sdb.img', 'deny', 'clean'],
|
||||
['round 2: wipefs option values', 'wipefs -t ext4 -a demo.img', 'allow', 'clean'],
|
||||
['round 2: wipefs option values (GST-3207: no image exemption)', 'wipefs -t ext4 -a demo.img', 'deny', 'clean'],
|
||||
['wipefs in the regex again: targets from xargs', 'ls /dev/sd* | xargs wipefs -a', 'deny', 'clean'],
|
||||
['wipefs in the regex again: targets from stdin', 'echo /dev/sdb | xargs wipefs --all', 'deny', 'clean'],
|
||||
['wipefs in the regex again: --a', 'wipefs --a /dev/sdb', 'deny', 'clean'],
|
||||
@@ -244,13 +244,39 @@ const PARSER_CASES: Array<[string, string, Decision, Tree]> = [
|
||||
['wipefs in the regex again: attached value in a group', 'wipefs -aftvfat /dev/sdb', 'deny', 'clean'],
|
||||
['wipefs in the regex again: image suffix under /dev', 'wipefs --al /dev/sdb.img', 'deny', 'clean'],
|
||||
['wipefs in the regex again: image names from xargs', 'ls *.img | xargs wipefs -a', 'deny', 'clean'],
|
||||
['wipefs in the regex again: attached value on an image (control)', 'wipefs -a -tvfat demo.img', 'allow', 'clean'],
|
||||
['wipefs in the regex again: several images (control)', 'wipefs --all disk.qcow2 build/b.iso', 'allow', 'clean'],
|
||||
['wipefs in the regex again: attached value on an image (GST-3207: no image exemption)', 'wipefs -a -tvfat demo.img', 'deny', 'clean'],
|
||||
['wipefs in the regex again: several images (GST-3207: no image exemption)', 'wipefs --all disk.qcow2 build/b.iso', 'deny', 'clean'],
|
||||
['wipefs round 2: an image name that is a symlink', 'wipefs -a alias.img', 'deny', 'clean'],
|
||||
['wipefs round 2: a symlink made in the same command', 'ln -sf /dev/sdb d.img; wipefs -a d.img', 'deny', 'clean'],
|
||||
['wipefs round 2: output redirected into a disk', 'wipefs -a demo.img > /dev/mmcblk0', 'deny', 'clean'],
|
||||
['wipefs round 2: a quoted spelling beside a proven wipe', "wipefs -a demo.img; wi''pefs -a /dev/sdb", 'deny', 'clean'],
|
||||
['wipefs round 2: errors sent to /dev/null (control)', 'wipefs -a demo.img 2>/dev/null', 'allow', 'clean'],
|
||||
['wipefs round 2: errors sent to /dev/null (GST-3207: no image exemption)', 'wipefs -a demo.img 2>/dev/null', 'deny', 'clean'],
|
||||
];
|
||||
|
||||
// GST-3207: checks that only get stricter than 17303862: wipefs -a on every target, disk redirects with quotes or
|
||||
// through a link to /dev, and --no-dry-run. Every row but the controls was allowed or asked at 17303862;
|
||||
// [item, command, expected, tree].
|
||||
const STRICT_CASES: Array<[string, string, Decision, Tree]> = [
|
||||
['wipefs: no image exemption', "wipefs -a demo.img >'/dev'/sdb", 'deny', 'clean'],
|
||||
['wipefs: no image exemption', 'wipefs -a demo.img" #" /dev/sda', 'deny', 'clean'],
|
||||
['wipefs: no image exemption', 'wipefs -a demo.img > devlink/sdb', 'deny', 'clean'],
|
||||
['wipefs: no image exemption (control: without -a it only lists)', 'wipefs demo.img', 'allow', 'clean'],
|
||||
['wipefs: a longer word is not wipefs (control)', 'echo wipefs-archive && wipefs -a /dev/sdb', 'deny', 'clean'],
|
||||
['wipefs: a backslash before the name', '\\wipefs -a /dev/sdb', 'deny', 'clean'],
|
||||
['quoted /dev redirect', "echo hi >'/dev'/sdb", 'deny', 'clean'],
|
||||
['quoted /dev redirect', 'echo hi > "/dev/mmcblk0"', 'deny', 'clean'],
|
||||
['redirect through a folder that links to /dev', 'echo hi > devlink/sdb', 'deny', 'clean'],
|
||||
['redirect through a folder that links to /dev (control: not a disk name)', 'echo hi > devlink/null', 'allow', 'clean'],
|
||||
['redirect through a folder that links to /dev (control: a real folder)', 'echo hi > build/sdb', 'allow', 'clean'],
|
||||
['push dry run undone later', 'git push -fn --no-dry-run origin main', 'deny', 'clean'],
|
||||
['push dry run undone later', 'git push --force -n --no-dry-run origin main', 'deny', 'clean'],
|
||||
['push dry run undone later (control: the last flag wins)', 'git push --no-dry-run -fn origin main', 'allow', 'clean'],
|
||||
['wipefs: a redirect is not an option end', 'wipefs > -- -$\'a\' /dev/sdb', 'deny', 'clean'],
|
||||
['wipefs: a backslashed name with a getopt spelling', '\\wipefs -$\'a\' /dev/sdb', 'deny', 'clean'],
|
||||
['wipefs: a longer word still denies, as at 17303862', 'echo wipefs-archive', 'deny', 'clean'],
|
||||
['unchanged from 17303862 (control: words after a quoted # stay unread)', 'echo \'git push -f origin main # --dry-run\'', 'deny', 'clean'],
|
||||
['unchanged from 17303862 (control: words after a quoted # stay unread)', 'echo \'git restore # --staged\'', 'ask', 'dirty'],
|
||||
['unchanged from 17303862 (control: a backslashed cd stays unread)', '\\cd /srv/demo && git push -f', 'ask', 'clean'],
|
||||
];
|
||||
|
||||
let base = '';
|
||||
@@ -273,6 +299,7 @@ function makeTree(kind: Tree): string {
|
||||
fs.writeFileSync(path.join(dir, image), '');
|
||||
}
|
||||
fs.symlinkSync('/dev/null', path.join(dir, 'alias.img'));
|
||||
fs.symlinkSync('/dev', path.join(dir, 'devlink'));
|
||||
git(['add', '.']);
|
||||
git(['commit', '-q', '-m', 'init']);
|
||||
git(['update-ref', 'refs/remotes/origin/main', 'HEAD']);
|
||||
@@ -342,6 +369,25 @@ describe('each new rule, with negative controls', () => {
|
||||
expect(decide(command, tree).decision).toBe(expected);
|
||||
});
|
||||
|
||||
test.each(STRICT_CASES)('%s: %s -> %s (%s tree)', (_item, command, expected, tree) => {
|
||||
expect(decide(command, tree).decision).toBe(expected);
|
||||
});
|
||||
|
||||
test('a long command full of redirect-like words is still checked well inside the guard hook\'s 8 s timeout', () => {
|
||||
const body = Array.from({ length: 12000 }, (_, i) => `a > d${i}/sdb`).join(' ');
|
||||
const started = Date.now();
|
||||
expect(decide(`echo "${body}"; rm -rf src`, 'clean').decision).toBe('ask');
|
||||
expect(Date.now() - started).toBeLessThan(6000);
|
||||
});
|
||||
|
||||
test('a redirect into a disk is still found behind many other redirects', () => {
|
||||
const decoys = (n: number, dir: (i: number) => string) => Array.from({ length: n }, (_, i) => `echo > ${dir(i)}/sdb${i};`).join(' ');
|
||||
expect(decide(`${decoys(70, () => 'x')} echo hi >'/dev'/sdb`, 'clean').decision).toBe('deny');
|
||||
expect(decide(Array.from({ length: 20000 }, (_, i) => `>'/dev'/sd${i}`).join(' '), 'clean').decision).toBe('deny');
|
||||
expect(decide(`${decoys(70, (i) => `d${i}`)} echo hi > devlink/sdb`, 'clean').decision).toBe('ask');
|
||||
expect(decide(`${decoys(60, (i) => `d${i}`)} echo hi > build/sdb`, 'clean').decision).toBe('allow');
|
||||
});
|
||||
|
||||
test('a 200 KB command is still checked well inside the guard hook\'s 8 s timeout', () => {
|
||||
const body = Array.from({ length: 4000 }, (_, i) => `const x${i} = f(a, b) && (c || d); // ${i}`).join('\n');
|
||||
const started = Date.now();
|
||||
|
||||
Reference in new issue
Block a user