fix(fermata): a shell behind a wrapper and a verb given by path are read; the forms that stay text are named

The bash/sh/zsh/eval unwrap reads the word after the prefix walk, so sudo, env,
timeout, nohup, exec, xargs, busybox and X=1 in front of a shell no longer hide
its command line. A prefix counts by its file name, as a verb already did, so
/bin/bash -c, /usr/bin/env cat and /usr/bin/timeout 5 cat are read.

Named as limits, each with a test in known_limits.rs: dash -c, ksh -c,
bash -c -- x, eval past its first argument, sudo -u root bash -c, and on the read
gate eval cat id_rsa and cat <&3 id_rsa. (re-check I-3, I-4 leftover, I-5's stale line)
This commit is contained in:
2026-11-07 02:11:10 +01:00
parent bfe83165a7
commit 34298c5f9a
6 changed files with 97 additions and 23 deletions
+32 -4
View File
@@ -403,16 +403,44 @@ fn a_command_that_names_the_file_in_a_form_the_check_does_not_read_passes() {
}
}
/// A wrapper's flag whose value is a word makes that word the verb, and a glob over
/// directories is no file: the read gate sees neither. A rule still reads what names it.
/// A shell's command line is read for `bash`, `sh` and `zsh` with the word right after
/// their `-c`, and for `eval`'s first argument. These stay text.
#[test]
fn a_command_line_the_check_does_not_read_as_one_passes() {
for rule in RULES {
let p = ruled(rule);
assert!(denied(&p.bash("sudo bash -c 'cat .env'")), "control");
for command in [
"dash -c 'cat .env'",
"ksh -c 'cat .env'",
"bash -c -- 'cat .env'",
"eval 'true' 'cat .env'",
"sudo -u root bash -c 'cat .env'",
] {
let out = p.bash(command);
assert!(passes(&out), "{rule:?}: {command}: {out}");
}
}
}
/// A wrapper's flag whose value is a word makes that word the verb, `eval` past its first
/// argument is text, `<&` ends the segment and a glob over directories is no file: the
/// read gate sees none of them. A rule on the file's name still reads each.
#[test]
fn a_flag_value_as_verb_and_a_glob_over_directories_pass_the_read_gate() {
let p = project(&[("id_rsa", b"fake key text\n"), ("sub/id_rsa", b"fake key text\n"), ("sub/a.key", b"fake key text\n")]);
let files: [(&str, &[u8]); 3] = [("id_rsa", b"fake key text\n"), ("sub/id_rsa", b"fake key text\n"), ("sub/a.key", b"fake key text\n")];
let p = project(&files);
assert!(denied(&p.bash("sudo cat id_rsa")), "control");
assert!(denied(&p.bash("cat sub/id_rsa")), "control");
for command in ["sudo -u root cat id_rsa", "cat */id_rsa", "cat ./s*/a.key"] {
let commands = ["sudo -u root cat id_rsa", "eval cat id_rsa", "cat <&3 id_rsa", "cat */id_rsa", "cat ./s*/a.key"];
for command in commands {
assert!(passes(&p.bash(command)), "{command}");
}
let p = project(&files);
fs::write(p.dir().join(".botignore"), "id_rsa\na.key\n").unwrap();
for command in commands {
assert!(denied(&p.bash(command)), "{command}");
}
}
/// A file a command is about to make is not there to check, so a rule on its directory