docs(fermata): the page lists what stays open after the fixes; the failure diagram leaves the public README

threat-landscape.svg showed specific failures and nothing else used it, so it is gone. The
false entry on runs outside a project now names all four markers, with a test.
This commit is contained in:
2026-11-07 09:48:21 +01:00
parent 67e41c58c3
commit b9e8e52731
5 changed files with 61 additions and 22 deletions
+47 -10
View File
@@ -396,6 +396,8 @@ fn a_command_that_names_the_file_in_a_form_the_check_does_not_read_passes() {
"git show HEAD:.env",
"git show :.env",
"cat .{env,x}",
"git commit -F.env",
"tool -f.env",
"echo \"$(cat .env)\"",
] {
let out = p.bash(command);
@@ -412,9 +414,10 @@ fn a_command_line_the_check_does_not_read_as_one_passes() {
let p = ruled(rule);
assert!(denied(&p.bash("sudo bash -c 'cat .env'")), "control");
for command in [
"bash -c -- 'cat .env'",
"eval 'true' 'cat .env'",
"sudo -u root bash -c 'cat .env'",
"rc -c 'cat .env'",
"pwsh -EncodedCommand Y2F0IC5lbnY=",
"python3 -c 'cat .env'",
] {
let out = p.bash(command);
assert!(passes(&out), "{rule:?}: {command}: {out}");
@@ -422,16 +425,17 @@ fn a_command_line_the_check_does_not_read_as_one_passes() {
}
}
/// 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.
/// A wrapper's flag whose value is a word makes that word the verb, `-o`'s value before a
/// shell's line is taken for its first word, `<&` ends the segment, a glob over directories
/// is no file, and a wrapper by a relative path is a script: 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 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");
let commands = ["sudo -u root cat id_rsa", "eval cat id_rsa", "cat <&3 id_rsa", "cat */id_rsa", "cat ./s*/a.key"];
let commands = ["sudo -u root cat id_rsa", "bash -c -o pipefail 'cat id_rsa'", "cat <&3 id_rsa", "cat */id_rsa", "cat ./s*/a.key", "./env cat id_rsa", "bin/sudo cat id_rsa", "./busybox cat id_rsa"];
for command in commands {
assert!(passes(&p.bash(command)), "{command}");
}
@@ -452,6 +456,35 @@ fn a_ruled_file_run_as_the_program_passes() {
}
}
/// A wrapper given by an absolute path may be a script, and it cannot be told from the real
/// one: its first word counts as a path, and if that is a metadata verb the file passes.
#[test]
fn a_script_given_by_an_absolute_path_passes_when_its_first_word_is_a_metadata_verb() {
let p = ruled(RULES[0]);
assert!(denied(&p.bash("/home/me/scripts/env .env")), "control");
assert!(passes(&p.bash("/home/me/scripts/env ls .env")));
}
/// `--exclude=`, `--exclude-dir=`, `--ignore=` and `--grep=` are taken at their word, for any
/// program: what a script does with such a flag's value is not read.
#[test]
fn a_flag_named_like_an_exclude_hides_its_value_for_any_program() {
let p = ruled(RULES[0]);
for command in ["tool --exclude=.env", "tool --ignore=.env", "python x.py --grep=.env"] {
assert!(passes(&p.bash(command)), "{command}");
}
}
/// With no `.git`, `.botsecrets`, `.botignore` or `fermata.toml` above the working directory
/// nothing is loaded, and the output passes.
#[test]
fn a_run_outside_any_project_is_not_masked() {
let p = project(&env_file(&format!("API_TOKEN={VALUE}\n")));
assert!(p.after_bash(VALUE).contains(MASK), "control: a .git alone makes a project");
fs::remove_dir_all(p.dir().join(".git")).unwrap();
assert!(p.after_bash(VALUE).contains(VALUE));
}
/// The over-denials that stay. Each errs towards stopping a command.
#[test]
fn a_harmless_command_a_rule_still_stops() {
@@ -474,19 +507,23 @@ fn a_harmless_command_a_rule_still_stops() {
#[test]
fn a_new_file_named_to_a_verb_off_the_writing_list_is_not_checked() {
let p = project(&[(".botignore", b"vendor/\n"), ("vendor/a", b"x"), ("a.txt", b"x")]);
for command in ["git clone https://example.invalid/x vendor/new", "unzip a.zip -d vendor/new", "python make.py vendor/new", "cp --target-directory=vendor/new a.txt"] {
for command in ["git clone https://example.invalid/x vendor/new", "unzip a.zip -d vendor/new", "python make.py vendor/new", "tar cf vendor/new a.txt", "touch vend*/new", "perl -pi -e 1 vendor/new"] {
assert!(passes(&p.bash(command)), "{command}");
}
assert!(denied(&p.bash("cp a.txt vendor/new")), "control");
assert!(denied(&p.bash("tool > vendor/new")), "control");
let p = project(&[(".botsecrets", b"[policy.write]\npatterns = [\"a.txt\"]\n"), ("a.txt", b"x")]);
for command in ["perl -pi -e 1 a.txt", "awk -i inplace 1 a.txt"] {
assert!(passes(&p.bash(command)), "{command}");
}
}
/// Text a certificate file may carry around its blocks is let through: a comment line and
/// an indented attribute. A value spelled as one of them passes.
/// Text a certificate file may carry is let through: a comment, an indented line, `subject=`,
/// `issuer=`, a title above `====`, and whatever a block holds. A value spelled so passes.
#[test]
fn a_comment_or_an_attribute_line_beside_a_certificate_passes() {
const CERT: &str = "-----BEGIN CERTIFICATE-----\nFAKEFAKEfakeFAKEfake\n-----END CERTIFICATE-----\n";
for extra in ["# fake-beside-a-cert\n", " api_token: fake-beside-a-cert\n"] {
for extra in ["# fake-beside-a-cert\n", " api_token: fake-beside-a-cert\n", " fake-beside-a-cert\n", "subject=fake-beside-a-cert\n", "issuer=API_TOKEN=fake-beside-a-cert\n", "fake-beside-a-cert\n====\n", "-----BEGIN CERTIFICATE-----\nAPI_TOKEN=fake-beside-a-cert\n-----END CERTIFICATE-----\n"] {
let content = format!("{extra}{CERT}");
let p = project(&[("server.pem", content.as_bytes())]);
assert!(passes(&p.read("server.pem")), "{extra}");