fix(fermata): a path call's leading ~/ is expanded, so Grep with path ~/.ssh/id_rsa meets the gate

This commit is contained in:
2026-11-07 09:02:27 +01:00
parent 8998540375
commit 33e330a4eb
5 changed files with 30 additions and 17 deletions
+12
View File
@@ -221,6 +221,18 @@ fn a_command_naming_a_file_in_home_meets_the_read_gate() {
assert_eq!(call("ls ~/.ssh/id_rsa"), json!({}));
}
/// A path call's leading `~/` is the same home.
#[test]
fn a_path_call_naming_a_file_in_home_meets_the_read_gate() {
let p = project(&[]);
let home = tempfile::tempdir().unwrap();
write(home.path(), &[(".ssh/id_rsa", PEM), (".ssh/config", "Host x\n")]);
let call = |tool: &str, input: Value| hook_in(p.path(), home.path(), json!({"tool_name": tool, "tool_input": input}));
assert_eq!(verdict(&call("Grep", json!({"pattern": "x", "path": "~/.ssh/id_rsa"}))), "deny");
assert_eq!(verdict(&call("Read", json!({"file_path": "~/.ssh/id_rsa"}))), "deny");
assert_eq!(call("Grep", json!({"pattern": "x", "path": "~/.ssh/config"})), json!({}));
}
/// The session's directory resolves the words, not this process's.
#[test]
fn the_payloads_cwd_resolves_a_commands_words() {
-9
View File
@@ -466,15 +466,6 @@ fn a_comment_or_an_attribute_line_beside_a_certificate_passes() {
}
}
/// Only `~` in a command is expanded. In Grep's `path` it stays text, so the file is not found.
#[test]
fn a_tilde_in_a_greps_path_is_not_expanded() {
let p = project(&[]);
put(p.home.path(), &[(".ssh/id_rsa", b"fake key text\n")]);
assert!(denied(&p.pre("Grep", json!({"pattern": "x", "path": p.home.path().join(".ssh/id_rsa")}))), "control");
assert!(passes(&p.pre("Grep", json!({"pattern": "x", "path": "~/.ssh/id_rsa"}))));
}
/// The default list names `terraform.tfvars` and `*.auto.tfvars`, no other `*.tfvars`.
#[test]
fn a_tfvars_file_off_the_list_is_not_masked() {