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
+40
View File
@@ -282,3 +282,43 @@ fn a_command_line_given_to_a_shell_or_eval_is_read() {
assert_eq!(bash(p.path(), command), json!({}), "{command}");
}
}
/// The same behind a wrapper or an assignment, and a shell, a wrapper or a verb given by
/// its path: what counts is the word the prefix walk stops at, by its file name.
#[test]
fn a_shell_behind_a_wrapper_and_a_verb_given_by_path_are_read() {
let p = project(&[(".botignore", ".env\n"), (".env", ENV), ("id_rsa", PEM)]);
for command in [
"sudo bash -c 'cat .env'",
"env bash -c 'cat .env'",
"/usr/bin/env bash -c 'cat .env'",
"/bin/bash -c 'cat .env'",
"timeout 5 bash -c 'cat .env'",
"nohup sh -c 'cat .env'",
"exec sh -c 'cat .env'",
"xargs sh -c 'cat .env'",
"busybox sh -c 'cat .env'",
"X=1 bash -c 'cat .env'",
"env X=1 bash -c 'cat .env'",
"command eval 'cat .env'",
// The read gate, with no rule on the name.
"sudo bash -c 'cat id_rsa'",
"/bin/bash -c 'cat id_rsa'",
"X=1 bash -c 'cat id_rsa'",
"/bin/cat id_rsa",
"/usr/bin/env cat id_rsa",
"/usr/bin/sudo cat id_rsa",
"/usr/bin/timeout 5 cat id_rsa",
] {
assert_eq!(verdict(&bash(p.path(), command)), "deny", "{command}");
}
for command in [
"sudo bash -c 'ls .env'",
"/bin/bash -c 'echo .env'",
"X=1 bash -c 'echo hello'",
"/usr/bin/env ls id_rsa",
"/usr/bin/timeout 5 ls id_rsa",
] {
assert_eq!(bash(p.path(), command), json!({}), "{command}");
}
}
+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