docs(fermata): the page lists the command holes left for the shell parser, each with a test
N-1b (a shell line ending in a backslash), S-1b (grep -fe clusters), R-1 (writes through a shell's positional arguments), R-2 (bash -oc pipefail), R-3 (PowerShell short switches) as known failures, and the echo-only positional argument as an over-denial. Command checks are marked best effort until the shell parser round. security-model.md says positional arguments are read only as printed. No src change.
This commit is contained in:
@@ -574,6 +574,130 @@ fn a_printing_verb_off_the_list_is_not_checked_against_the_rules_unless_it_names
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Commands: holes left for the shell parser (goal 2026-11-07-fermata-command-ast)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// N-1b: a shell's arguments are read through a line appended to its own. A line that ends
|
||||
/// in a backslash joins that appended line back into its last command, so the argument
|
||||
/// becomes a word of `echo`. Real bash takes the backslash as a literal and prints the file.
|
||||
#[test]
|
||||
fn a_shell_line_ending_in_a_backslash_hides_its_arguments() {
|
||||
for rule in RULES {
|
||||
let p = ruled(rule);
|
||||
assert!(denied(&p.bash("bash -c 'cat \"$1\"; echo ok' _ .env")), "control");
|
||||
let out = p.bash("bash -c 'cat \"$1\"; echo \\' _ .env");
|
||||
assert!(passes(&out), "{rule:?}: {out}");
|
||||
}
|
||||
let p = project(&[("id_rsa", b"fake key text\n")]);
|
||||
assert!(denied(&p.bash("bash -c 'cat \"$1\"; echo ok' _ id_rsa")), "control");
|
||||
assert!(passes(&p.bash("bash -c 'cat \"$1\"; echo \\' _ id_rsa")));
|
||||
}
|
||||
|
||||
/// S-1b: in a cluster where `f` comes before a final `e`, `f` takes `e` as its pattern file,
|
||||
/// yet the check gives the next word to `e` as the pattern. The file is then no file to it.
|
||||
#[test]
|
||||
fn a_pattern_flag_after_a_file_flag_in_one_cluster_hides_the_file() {
|
||||
for rule in RULES {
|
||||
let p = ruled(rule);
|
||||
assert!(denied(&p.bash("grep -f e .env")), "control");
|
||||
for command in ["grep -fe .env", "grep -wfe .env", "grep -rfe .env", "rg -fe .env", "sed -n -fe .env", "sed -nfe .env", "awk -fe .env"] {
|
||||
let out = p.bash(command);
|
||||
assert!(passes(&out), "{rule:?}: {command}: {out}");
|
||||
}
|
||||
}
|
||||
let p = project(&[("id_rsa", b"fake key text\n")]);
|
||||
assert!(denied(&p.bash("grep -f e id_rsa")), "control");
|
||||
for command in ["grep -fe id_rsa", "sed -n -fe id_rsa", "rg -fe id_rsa"] {
|
||||
assert!(passes(&p.bash(command)), "{command}");
|
||||
}
|
||||
}
|
||||
|
||||
/// R-1: a shell's arguments are read only as what it may print, so a write the line does
|
||||
/// to `"$1"` meets no write rule.
|
||||
#[test]
|
||||
fn a_write_through_a_shells_positional_arguments_is_not_checked() {
|
||||
let write = b"[policy.write]\npatterns = [\"a.txt\", \"vendor/**\", \"Cargo.lock\"]\n";
|
||||
let p = project(&[(".botsecrets", write), ("a.txt", b"x"), ("b.txt", b"x"), ("Cargo.lock", b"x")]);
|
||||
assert!(denied(&p.bash("rm a.txt")), "control");
|
||||
assert!(denied(&p.bash("cp b.txt vendor/new")), "control");
|
||||
for command in [
|
||||
"bash -c 'rm \"$1\"' _ a.txt",
|
||||
"bash -c 'rm -f \"$1\"' _ a.txt",
|
||||
"bash -c 'cp b.txt \"$1\"' _ vendor/new",
|
||||
"bash -c 'mv \"$1\" \"$2\"' _ b.txt vendor/new",
|
||||
"bash -c 'sed -i s/a/b/ \"$1\"' _ a.txt",
|
||||
"bash -c 'touch \"$@\"' _ vendor/new",
|
||||
"sh -c 'rm \"$0\"' a.txt",
|
||||
"bash -c 'tee \"$1\"' _ Cargo.lock",
|
||||
] {
|
||||
let out = p.bash(command);
|
||||
assert!(passes(&out), "{command}: {out}");
|
||||
}
|
||||
let p = project(&[(".botignore", b"target/\n"), ("a.txt", b"x")]);
|
||||
assert!(denied(&p.bash("cp a.txt target/y")), "control");
|
||||
assert!(passes(&p.bash("bash -c 'cp a.txt \"$1\"' _ target/y")));
|
||||
}
|
||||
|
||||
/// R-2: in a cluster that holds `c`, each `o` or `O` takes a word too. The check skips only
|
||||
/// one when the cluster ends in `o`, so with `-oc` it takes the option's value for the line.
|
||||
#[test]
|
||||
fn a_shell_cluster_with_o_before_c_takes_the_options_value_for_the_line() {
|
||||
for rule in RULES {
|
||||
let p = ruled(rule);
|
||||
assert!(denied(&p.bash("bash -o pipefail -c 'cat .env'")), "control");
|
||||
for command in ["bash -oc pipefail 'cat .env'", "bash -Oc extglob 'cat .env'", "bash -xoc pipefail 'cat .env'"] {
|
||||
let out = p.bash(command);
|
||||
assert!(passes(&out), "{rule:?}: {command}: {out}");
|
||||
}
|
||||
}
|
||||
let p = project(&[("id_rsa", b"fake key text\n")]);
|
||||
assert!(passes(&p.bash("bash -oc pipefail 'cat id_rsa'")));
|
||||
}
|
||||
|
||||
/// R-3: PowerShell switches are an exact list, and every other flag takes a value. A switch
|
||||
/// by its documented short form (`-nol`, `-noe`, `-i`) or another prefix pwsh accepts takes
|
||||
/// the `-c` after it as its value. Only fermata's verdict is checked: pwsh was not run.
|
||||
#[test]
|
||||
fn a_powershell_switch_by_a_short_form_hides_the_command() {
|
||||
for rule in RULES {
|
||||
let p = ruled(rule);
|
||||
assert!(denied(&p.bash("pwsh -NoLogo -c 'cat .env'")), "control");
|
||||
for command in [
|
||||
"pwsh -nol -c 'cat .env'",
|
||||
"pwsh -noe -c 'cat .env'",
|
||||
"pwsh -i -c 'cat .env'",
|
||||
"pwsh -NoProfileLoadTime -c 'cat .env'",
|
||||
"pwsh -NoProf -c 'cat .env'",
|
||||
"pwsh -NonInter -c 'cat .env'",
|
||||
"powershell -nol -c 'cat .env'",
|
||||
"powershell -noe -c 'cat .env'",
|
||||
] {
|
||||
let out = p.bash(command);
|
||||
assert!(passes(&out), "{rule:?}: {command}: {out}");
|
||||
}
|
||||
}
|
||||
let p = project(&[("id_rsa", b"fake key text\n")]);
|
||||
assert!(denied(&p.bash("pwsh -NoLogo -c 'cat id_rsa'")), "control");
|
||||
for command in ["pwsh -nol -c 'cat id_rsa'", "pwsh -noe -c 'cat id_rsa'", "pwsh -i -c 'cat id_rsa'"] {
|
||||
assert!(passes(&p.bash(command)), "{command}");
|
||||
}
|
||||
}
|
||||
|
||||
/// M-a: every argument after a shell's line is read as printed, also one the line only
|
||||
/// echoes or tests. An over-denial; it errs towards stopping.
|
||||
#[test]
|
||||
fn a_shell_argument_its_line_only_echoes_is_stopped() {
|
||||
for rule in RULES {
|
||||
let p = ruled(rule);
|
||||
for command in ["bash -c 'echo \"$1\"' _ .env", "bash -c 'test -f \"$1\"' _ .env"] {
|
||||
assert!(denied(&p.bash(command)), "{rule:?}: {command}");
|
||||
}
|
||||
}
|
||||
let p = project(&[("id_rsa", b"fake key text\n")]);
|
||||
assert!(denied(&p.bash("bash -c 'echo \"$1\"' _ id_rsa")));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Failed tools, and other routes no hook sees
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user