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:
@@ -167,6 +167,13 @@ fn what_can_be_masked_or_is_source_passes() {
|
||||
("secrets.tpl", "{{ x }}\n".to_string()),
|
||||
("credentials.example", "API_TOKEN=\n".to_string()),
|
||||
("secrets.d.ts", "export {};\n".to_string()),
|
||||
("secrets.pyi", "def load() -> str: ...\n".to_string()),
|
||||
("credentials.pyi", "def load() -> str: ...\n".to_string()),
|
||||
("secrets.mdx", "# x\n".to_string()),
|
||||
("secrets.scss", "a {}\n".to_string()),
|
||||
("secrets.less", "a {}\n".to_string()),
|
||||
("secrets.ps1", "Get-Date\n".to_string()),
|
||||
("secrets.bat", "echo\n".to_string()),
|
||||
("notes.txt", "x\n".to_string()),
|
||||
] {
|
||||
let p = project(setting, &[(name, content.as_bytes())]);
|
||||
@@ -274,20 +281,21 @@ fn the_gate_follows_the_projects_list() {
|
||||
assert!(reason(&p.read("private/notes.txt")).contains("notes.txt"));
|
||||
}
|
||||
|
||||
/// A bad `[files]` pattern costs the gate, not the rules beside it, and says so.
|
||||
/// A `[files]` list with no usable pattern leaves the built-in list, keeps the rules beside
|
||||
/// it and says so.
|
||||
#[test]
|
||||
fn a_bad_files_pattern_turns_the_gate_off_and_keeps_the_rules() {
|
||||
fn a_files_list_with_no_usable_pattern_leaves_the_default_list_and_keeps_the_rules() {
|
||||
let config = "[files]\npatterns = [\"a[\"]\n[policy.read]\npatterns = [\"blocked.txt\"]\n";
|
||||
let files: &[(&str, &[u8])] = &[(".botignore", b"ignored.txt\n"), ("ignored.txt", b"x"), ("blocked.txt", b"x"), ("id_rsa", b"fake key text")];
|
||||
let p = project(config, files);
|
||||
assert_eq!(p.read("id_rsa"), json!({}));
|
||||
assert!(reason(&p.read("id_rsa")).contains("id_rsa"));
|
||||
assert!(reason(&p.read("ignored.txt")).contains(".botignore"));
|
||||
assert!(reason(&p.read("blocked.txt")).contains("blocked.txt"));
|
||||
assert_eq!(p.check("id_rsa"), 2);
|
||||
|
||||
let response = json!({"stdout": "x", "stderr": "", "interrupted": false});
|
||||
let note = p.hook("post-tool-use", json!({"tool_name": "Bash", "tool_input": {"command": "x"}, "tool_response": response}));
|
||||
assert!(note["hookSpecificOutput"]["additionalContext"].as_str().unwrap().contains("[files]"), "{note}");
|
||||
assert!(note["hookSpecificOutput"]["additionalContext"].as_str().unwrap().contains("a["), "{note}");
|
||||
assert!(note["hookSpecificOutput"].get("updatedToolOutput").is_none(), "{note}");
|
||||
// A tool that shows no text pays nothing for it.
|
||||
let quiet = p.hook("post-tool-use", json!({"tool_name": "Write", "tool_input": {}, "tool_response": {"type": "create"}}));
|
||||
|
||||
Reference in New Issue
Block a user