fix(fermata): a bad glob costs only itself; commands read what is there, behind a wrapper or a shell
- A glob in [files] or [policy] that does not compile costs only that pattern while open, with a note by name beside text output. A [files] list with none left leaves the built-in list. Under deny the refusal stays, and the channel filter stays strict. - A file named `credentials` is on the default list, at any depth. - A word with a separator counts only if the path is there, the shell may expand it, or a redirect names it: packages, branches and hosts' paths are not denied. - timeout, nice, ionice, stdbuf, xargs and busybox are prefixes; `2>&1` stays in its segment. - `bash|sh|zsh -c` and `eval` arguments are read as command lines. - A `<<` with no closing line is no heredoc. A commented line's own comment is dropped. Text holding NUL fails to parse. The unknown-field message says so. Durations are bound to under 6 characters. More source extensions pass the gate. - Removed: HarnessAdapter::post_tool_op (dead since 3C was dropped), tool_op back inline.
This commit is contained in:
@@ -229,3 +229,56 @@ fn a_path_in_the_sessions_own_project_stays_as_it_was() {
|
||||
assert_eq!(verdict(&read_from(p.path(), home.path(), &p.path().join(".env"))), "deny");
|
||||
assert_eq!(read_from(p.path(), home.path(), &p.path().join("a.txt")), json!({}));
|
||||
}
|
||||
|
||||
/// A word with a separator names a path only if the path is there. A package, a branch, an
|
||||
/// image or a host's path is no file under a directory rule.
|
||||
#[test]
|
||||
fn a_word_with_a_separator_that_is_no_existing_path_is_not_denied() {
|
||||
let p = project(&[(".botignore", "vendor/\nbuild/\n"), ("vendor/a", "x"), ("build/x", "x")]);
|
||||
for command in ["composer require vendor/package", "git checkout build/fix", "git log build/fix", "docker build -t build/img .", "curl example.com/vendor/a"] {
|
||||
assert_eq!(bash(p.path(), command), json!({}), "{command}");
|
||||
}
|
||||
// What is there, what a variable or glob may reach, and a redirect's target still count.
|
||||
for command in ["cat vendor/a", "cat ./vendor/a", "cp vendor/a b", "cat < vendor/a", "tool > vendor/new", "tool $X/vendor/a", "tool */vendor/a", "cat vendor/?", "rm -rf vendor/"] {
|
||||
assert_eq!(verdict(&bash(p.path(), command)), "deny", "{command}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A listed printing verb behind a wrapper or an early redirect is still that verb.
|
||||
#[test]
|
||||
fn a_wrapper_or_an_early_redirect_does_not_hide_a_printing_verb() {
|
||||
let p = project(&[("id_rsa", PEM)]);
|
||||
for command in [
|
||||
"timeout 5 cat id_rsa",
|
||||
"timeout 5s cat id_rsa",
|
||||
"timeout -k 1 5 cat id_rsa",
|
||||
"nice cat id_rsa",
|
||||
"nice -n 10 cat id_rsa",
|
||||
"ionice -c 2 cat id_rsa",
|
||||
"stdbuf -o0 cat id_rsa",
|
||||
"xargs cat id_rsa",
|
||||
"xargs -n 1 cat id_rsa",
|
||||
"busybox cat id_rsa",
|
||||
"cat 2>&1 id_rsa",
|
||||
"cat 1>&2 id_rsa",
|
||||
"cat >&2 id_rsa",
|
||||
] {
|
||||
assert_eq!(verdict(&bash(p.path(), command)), "deny", "{command}");
|
||||
}
|
||||
// The wrapper's own program is no printing verb, and a background job still splits.
|
||||
for command in ["timeout 5 ssh -i id_rsa x", "nice chmod 600 id_rsa", "sleep 1 & ls id_rsa"] {
|
||||
assert_eq!(bash(p.path(), command), json!({}), "{command}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A shell's `-c` argument and `eval`'s are command lines, and are read as such.
|
||||
#[test]
|
||||
fn a_command_line_given_to_a_shell_or_eval_is_read() {
|
||||
let p = project(&[(".botignore", "vendor/\n.env\n"), (".env", ENV), ("vendor/a/b", "x"), ("id_rsa", PEM)]);
|
||||
for command in ["bash -c 'cat .env'", "sh -c 'cat vendor/a/b'", "zsh -c 'cat .env'", "bash -lc 'cat .env'", "eval 'cat .env'", "bash -c 'ls; cat id_rsa'", "bash -c \"bash -c 'cat .env'\""] {
|
||||
assert_eq!(verdict(&bash(p.path(), command)), "deny", "{command}");
|
||||
}
|
||||
for command in ["bash -c 'echo hello'", "sh run.sh", "bash -c 'ls .env'", "eval 'true'", "bash"] {
|
||||
assert_eq!(bash(p.path(), command), json!({}), "{command}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user