docs(fermata): the page drops bash -c -o pipefail and names an indented private block and the = and : write forms

This commit is contained in:
2026-11-07 10:05:18 +01:00
parent 549cfd1ae3
commit d679aec6c3
3 changed files with 33 additions and 5 deletions
+3 -1
View File
@@ -30,6 +30,7 @@ The check reads the command's text, not what the shell makes of it.
- A change of directory: `cd ../other && cat .env`. A secret file in no project has no rules at all. (Test: `a_command_that_prints_a_secret_file_outside_the_project_passes`.) - A change of directory: `cd ../other && cat .env`. A secret file in no project has no rules at all. (Test: `a_command_that_prints_a_secret_file_outside_the_project_passes`.)
- A command run in one project does not meet another project's rules: `cat ../other/x` passes, while a Read of that file is stopped. (Test: `a_command_in_one_project_is_not_stopped_by_another_projects_rule`.) - A command run in one project does not meet another project's rules: `cat ../other/x` passes, while a Read of that file is stopped. (Test: `a_command_in_one_project_is_not_stopped_by_another_projects_rule`.)
- A write by a verb off the writing list: `git clone https://example.invalid/x vendor/new`, `unzip a.zip -d vendor/new`, `tar cf vendor/new a.txt`, `python make.py vendor/new`, `perl -pi`, `awk -i inplace`. A glob over directories in the target (`touch vend*/new`) is not read either. (Test: `a_new_file_named_to_a_verb_off_the_writing_list_is_not_checked`.) - A write by a verb off the writing list: `git clone https://example.invalid/x vendor/new`, `unzip a.zip -d vendor/new`, `tar cf vendor/new a.txt`, `python make.py vendor/new`, `perl -pi`, `awk -i inplace`. A glob over directories in the target (`touch vend*/new`) is not read either. (Test: `a_new_file_named_to_a_verb_off_the_writing_list_is_not_checked`.)
- An output flag's value given with `=` or `:` (`tool -o=vendor/new`, `sort -o=vendor/new`, `Copy-Item a.txt -Destination:vendor\new`), and BSD's `sed -I`. (Test: `a_write_given_by_an_equals_sign_a_colon_or_sed_capital_i_is_not_checked`.)
## Secret files fermata cannot mask ## Secret files fermata cannot mask
@@ -37,9 +38,10 @@ A Read, a Grep with that `path` and a printing command that names such a file ar
- A route that does not name the file: `grep -r TOKEN .`, `ls -R`, `tar cf x.tar .`, a script that opens it. This holds for `*.p12`, `*.pfx`, `.netrc`, `.htpasswd` and a text `*.key`. (Test: `an_unmaskable_file_is_reached_by_a_route_that_does_not_name_it`.) - A route that does not name the file: `grep -r TOKEN .`, `ls -R`, `tar cf x.tar .`, a script that opens it. This holds for `*.p12`, `*.pfx`, `.netrc`, `.htpasswd` and a text `*.key`. (Test: `an_unmaskable_file_is_reached_by_a_route_that_does_not_name_it`.)
- A printing verb off the list: `dd if=server.p12`, `perl -ne print server.p12`, `python3 show.py server.p12`. (Test: `a_printing_verb_not_on_the_list_passes_the_read_gate`.) - A printing verb off the list: `dd if=server.p12`, `perl -ne print server.p12`, `python3 show.py server.p12`. (Test: `a_printing_verb_not_on_the_list_passes_the_read_gate`.)
- A form the gate does not read: `sudo -u root cat id_rsa`, where the flag's value becomes the verb; `bash -c -o pipefail 'cat id_rsa'`, where that word does; `cat <&3 id_rsa`, where `<&` ends the segment; `cat */id_rsa` and `cat ./s*/a.key`, a glob over directories; `./env cat id_rsa`, `bin/sudo cat id_rsa` and `./busybox cat id_rsa`, each a script as far as the check knows. A rule on the file's name still stops each of them. (Test: `a_flag_value_as_verb_and_a_glob_over_directories_pass_the_read_gate`.) - A form the gate does not read: `sudo -u root cat id_rsa`, where the flag's value becomes the verb; `cat <&3 id_rsa`, where `<&` ends the segment; `cat */id_rsa` and `cat ./s*/a.key`, a glob over directories; `./env cat id_rsa`, `bin/sudo cat id_rsa` and `./busybox cat id_rsa`, each a script as far as the check knows. A rule on the file's name still stops each of them. (Test: `a_flag_value_as_verb_and_a_glob_over_directories_pass_the_read_gate`.)
- The stop needs the PreToolUse hook. Without it a Read reaches the model, and PostToolUse has nothing to mask in it. (Test: `the_read_gate_stands_only_in_a_pre_tool_use_hook`.) - The stop needs the PreToolUse hook. Without it a Read reaches the model, and PostToolUse has nothing to mask in it. (Test: `the_read_gate_stands_only_in_a_pre_tool_use_hook`.)
- A text with `{{` or `{%` that does not parse passes as a template, and a literal value in it reaches the model. (Test: `a_template_holding_a_literal_value_passes_a_read`.) - A text with `{{` or `{%` that does not parse passes as a template, and a literal value in it reaches the model. (Test: `a_template_holding_a_literal_value_passes_a_read`.)
- A private block indented beside a certificate is taken for the certificate file's text, so a Read passes. Its body is still masked in what the Read shows. (Test: `an_indented_private_block_beside_a_certificate_passes_a_read`.)
- A certificate file may hold other text, so a value spelled as that text passes: a comment (`# fake-value`), an indented line (` api_token: fake-value`), `subject=` or `issuer=`, a title above a `====` line, and whatever a certificate block holds. (Test: `a_comment_or_an_attribute_line_beside_a_certificate_passes`.) - A certificate file may hold other text, so a value spelled as that text passes: a comment (`# fake-value`), an indented line (` api_token: fake-value`), `subject=` or `issuer=`, a title above a `====` line, and whatever a certificate block holds. (Test: `a_comment_or_an_attribute_line_beside_a_certificate_passes`.)
- A UTF-16 or Latin-1 `.env`, and JSON with comments, are stopped on a Read. Their values are not masked in the output of other commands. (Test: `a_utf16_or_latin1_file_or_json_with_comments_is_not_masked_when_no_command_names_it`.) - A UTF-16 or Latin-1 `.env`, and JSON with comments, are stopped on a Read. Their values are not masked in the output of other commands. (Test: `a_utf16_or_latin1_file_or_json_with_comments_is_not_masked_when_no_command_names_it`.)
+1 -1
View File
@@ -46,7 +46,7 @@ Its false-positive rate is higher than Layer 1's, which is why it warns: masking
Stop the tool calls your rules name, and a Read of a secret file that fermata cannot mask. With `[policy.write]` on `.claude/**`, `Write .claude/settings.json` is denied. With `[policy.bash] deny = ["rm -rf /"]`, `Bash: rm -rf /` is denied. Without rules nothing is stopped, apart from the two gates below. Path patterns apply to the Read, Write and Edit tools (and Grep with a `path`, which counts as a Read), and command patterns match the text of a command. A `~/` in a tool's path is the home directory. Stop the tool calls your rules name, and a Read of a secret file that fermata cannot mask. With `[policy.write]` on `.claude/**`, `Write .claude/settings.json` is denied. With `[policy.bash] deny = ["rm -rf /"]`, `Bash: rm -rf /` is denied. Without rules nothing is stopped, apart from the two gates below. Path patterns apply to the Read, Write and Edit tools (and Grep with a `path`, which counts as a Read), and command patterns match the text of a command. A `~/` in a tool's path is the home directory.
- **Commands that name a file.** A command is split into segments, and each word that names an existing file, an existing path with a separator, a path with `$`, `*` or `?` in it, or a file the command writes is checked. So `composer require vendor/package` and `git checkout build/fix` name nothing under a rule on `vendor/` or `build/`. The command line given to a shell (`bash rbash sh zsh dash ksh rksh mksh oksh pdksh ash yash osh fish csh tcsh nu elvish xonsh pwsh powershell cmd`, by a short flag cluster holding `c` such as `-ce`, `--command`, PowerShell's `-Command` by any abbreviation, or `cmd /c` and `/k`) and to `eval` is read as a command line of its own, with all the words after the flag, and `sudo env time nohup command exec timeout nice ionice stdbuf xargs busybox` before a verb do not hide it. A wrapper counts by its file name only as a bare word or an absolute path, so `./do .env` is a script called on the file. After an absolute path (`/home/me/env .env`) the next word still counts as a path, because that may be a script too. Which check depends on the segment's verb. A printing verb (`cat head tail less more bat nl tac cut sort uniq grep egrep fgrep rg awk sed strings xxd od hexdump base64 gc type get-content select-string`) meets the path rules and the read gate. A write meets `.botignore`, `[policy.write]` and `[policy.read]`, also for a file that is not there yet: a redirect's target, every path of `mv rm rmdir touch mkdir tee truncate shred set-content sc add-content ac out-file tee-object new-item remove-item rename-item move-item` and of `sed` with `-i` in any spelling, the last path of `cp ln install rsync scp copy-item` unless it is remote, `dd of=`, and the value of `-o` or `--output` on a verb that neither prints nor is metadata and on `sort`, `wget -O`, `cp -t`, `-Destination`, attached or not. A write does not meet the read gate, and a printing verb's write still counts as printing: `sed -i` and `sort -o` meet the gate. Any other verb (`source`, `python`, `chmod`) meets `.botignore` and `[policy.read]`. A metadata verb (`ls stat file test [ du which echo printf`, and `git status`, `git check-ignore`, `git ls-files`, `git commit`) given as a bare word meets nothing. So with `.env` in `.botignore`, `cat .env`, `cat ./.env; false` and `source .env` are denied, while `env`, `grep -r TOKEN .` and `git commit -m ".env loading"` pass. - **Commands that name a file.** A command is split into segments, and each word that names an existing file, an existing path with a separator, a path with `$`, `*` or `?` in it, or a file the command writes is checked. So `composer require vendor/package` and `git checkout build/fix` name nothing under a rule on `vendor/` or `build/`. The command line given to a shell (`bash rbash sh zsh dash ksh rksh mksh oksh pdksh ash yash osh fish csh tcsh nu elvish xonsh pwsh powershell cmd`, by a short flag cluster holding `c` such as `-ce`, `--command`, PowerShell's `-Command` by any abbreviation, or `cmd /c` and `/k`) and to `eval` is read as a command line of its own, when the flag stands among the shell's leading options (before a script's name, or PowerShell's `-File`). `eval`, `cmd` and PowerShell join the words after the flag; a POSIX shell's words after its line are its arguments and are read as what it may print, and `sudo env time nohup command exec timeout nice ionice stdbuf xargs busybox` before a verb do not hide it. A wrapper counts by its file name only as a bare word or an absolute path, so `./do .env` is a script called on the file. After an absolute path (`/home/me/env .env`) the next word still counts as a path, because that may be a script too. Which check depends on the segment's verb. A printing verb (`cat head tail less more bat nl tac cut sort uniq grep egrep fgrep rg awk sed strings xxd od hexdump base64 gc type get-content select-string`) meets the path rules and the read gate. A write meets `.botignore`, `[policy.write]` and `[policy.read]`, also for a file that is not there yet: a redirect's target, every path of `mv rm rmdir touch mkdir tee truncate shred set-content sc add-content ac out-file tee-object new-item remove-item rename-item move-item` and of `sed` with `-i` in any spelling, the last path of `cp ln install rsync scp copy-item` unless it is remote, `dd of=`, and the value of `-o` or `--output` on a verb that neither prints nor is metadata and on `sort`, `wget -O`, `cp -t`, `-Destination`, attached or not. A write does not meet the read gate, and a printing verb's write still counts as printing: `sed -i` and `sort -o` meet the gate. Any other verb (`source`, `python`, `chmod`) meets `.botignore` and `[policy.read]`. A metadata verb (`ls stat file test [ du which echo printf`, and `git status`, `git check-ignore`, `git ls-files`, `git commit`) given as a bare word meets nothing. So with `.env` in `.botignore`, `cat .env`, `cat ./.env; false` and `source .env` are denied, while `env`, `grep -r TOKEN .` and `git commit -m ".env loading"` pass.
- **Read gate.** A Read (or a Grep with a `path`, or a printing command that names the file) of a file on the secret list that fermata cannot mask is stopped under every `on_parse_error`. The reason names the file and the setting `[enforcement] on_unparsed_read` and says to ask the user. The files are: a file with no parser (`.netrc`, `.htpasswd`, `.p12`, `.pfx`), a key file that is a secret as a whole (`*.pem`, `*.key`, `id_rsa`, `id_ed25519`, `id_ecdsa`, unless it holds only certificates), `*.tfstate` (its secrets sit by position, not by key), and a file that cannot be parsed (a broken file, a UTF-16 or Latin-1 file, JSON with comments, text with a NUL). `on_unparsed_read = "allow"` turns the gate off. - **Read gate.** A Read (or a Grep with a `path`, or a printing command that names the file) of a file on the secret list that fermata cannot mask is stopped under every `on_parse_error`. The reason names the file and the setting `[enforcement] on_unparsed_read` and says to ask the user. The files are: a file with no parser (`.netrc`, `.htpasswd`, `.p12`, `.pfx`), a key file that is a secret as a whole (`*.pem`, `*.key`, `id_rsa`, `id_ed25519`, `id_ecdsa`, unless it holds only certificates), `*.tfstate` (its secrets sit by position, not by key), and a file that cannot be parsed (a broken file, a UTF-16 or Latin-1 file, JSON with comments, text with a NUL). `on_unparsed_read = "allow"` turns the gate off.
- **Write guard.** A Write, Edit or MultiEdit that adds a mask to a file is stopped, because the mask stands for a value fermata hid and writing it back corrupts the file. `[enforcement] on_mask_write = "allow"` turns it off. - **Write guard.** A Write, Edit or MultiEdit that adds a mask to a file is stopped, because the mask stands for a value fermata hid and writing it back corrupts the file. `[enforcement] on_mask_write = "allow"` turns it off.
- **`.botignore` and relative paths.** A directory pattern such as `vendor/` matches the files below it, and a relative path is taken against the project root. The path is also checked as the file system resolves it, so a symlink does not hide what it points at. - **`.botignore` and relative paths.** A directory pattern such as `vendor/` matches the files below it, and a relative path is taken against the project root. The path is also checked as the file system resolves it, so a symlink does not hide what it points at.
+29 -3
View File
@@ -425,8 +425,7 @@ 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, `-o`'s value before a /// A wrapper's flag whose value is a word makes that word the verb, `<&` ends the segment, a glob over directories
/// 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 /// 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. /// them. A rule on the file's name still reads each.
#[test] #[test]
@@ -435,7 +434,7 @@ fn a_flag_value_as_verb_and_a_glob_over_directories_pass_the_read_gate() {
let p = project(&files); let p = project(&files);
assert!(denied(&p.bash("sudo cat id_rsa")), "control"); assert!(denied(&p.bash("sudo cat id_rsa")), "control");
assert!(denied(&p.bash("cat sub/id_rsa")), "control"); assert!(denied(&p.bash("cat sub/id_rsa")), "control");
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"]; let commands = ["sudo -u root 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 { for command in commands {
assert!(passes(&p.bash(command)), "{command}"); assert!(passes(&p.bash(command)), "{command}");
} }
@@ -485,6 +484,33 @@ fn a_run_outside_any_project_is_not_masked() {
assert!(p.after_bash(VALUE).contains(VALUE)); assert!(p.after_bash(VALUE).contains(VALUE));
} }
/// An output flag's value given with `=` or `:`, and BSD's `sed -I`, are not read as writes.
#[test]
fn a_write_given_by_an_equals_sign_a_colon_or_sed_capital_i_is_not_checked() {
let p = project(&[(".botignore", b"vendor/\n"), ("vendor/a", b"x"), ("a.txt", b"x")]);
for command in ["tool -o=vendor/new", "sort -o=vendor/new a.txt"] {
assert!(passes(&p.bash(command)), "{command}");
}
assert!(passes(&p.pre("PowerShell", json!({"command": "Copy-Item a.txt -Destination:vendor\\new"}))));
assert!(denied(&p.bash("tool -o vendor/new")), "control");
let p = project(&[(".botsecrets", b"[policy.write]\npatterns = [\"a.txt\"]\n"), ("a.txt", b"x")]);
assert!(passes(&p.bash("sed -I '' s/a/b/ a.txt")));
assert!(denied(&p.bash("sed -i s/a/b/ a.txt")), "control");
}
/// A private block indented beside a certificate is read as the certificate file's text, so a
/// Read passes. Its body is still a known value, and is masked in what the Read shows.
#[test]
fn an_indented_private_block_beside_a_certificate_passes_a_read() {
const CERT: &str = "-----BEGIN CERTIFICATE-----\nFAKEFAKEfakeFAKEfake\n-----END CERTIFICATE-----\n";
let content = format!("{CERT} -----BEGIN PRIVATE KEY-----\n fakeIndentedPrivateBody123\n -----END PRIVATE KEY-----\n");
let p = project(&[("server.pem", content.as_bytes())]);
assert!(passes(&p.read("server.pem")));
assert!(is_masked(&p.after_read("server.pem", &content), "fakeIndentedPrivateBody123"));
let p = project(&[("server.pem", format!("{CERT}-----BEGIN PRIVATE KEY-----\nfakeIndentedPrivateBody123\n-----END PRIVATE KEY-----\n").as_bytes())]);
assert!(denied(&p.read("server.pem")), "control");
}
/// The over-denials that stay. Each errs towards stopping a command. /// The over-denials that stay. Each errs towards stopping a command.
#[test] #[test]
fn a_harmless_command_a_rule_still_stops() { fn a_harmless_command_a_rule_still_stops() {