docs(fermata): the page lists what stays open after the fixes; the failure diagram leaves the public README

threat-landscape.svg showed specific failures and nothing else used it, so it is gone. The
false entry on runs outside a project now names all four markers, with a test.
This commit is contained in:
2026-11-07 09:48:21 +01:00
parent 67e41c58c3
commit b9e8e52731
5 changed files with 61 additions and 22 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ Developed in this monorepo; planned to be exported as a standalone repo in the f
- **Hooks fail open, except under `on_parse_error = "deny"`.** A broken config layer (a parse error or an unknown field) switches only that layer's rules off, with a note beside text output. With `deny` in effect, PostToolUse answers with a refusal naming the file when the config or a secret file cannot be loaded, and PreToolUse answers `deny` when the config or the rules cannot be loaded or applied. A malformed hook payload and a missing working directory stay open: no payload means nothing to render, no directory means no setting to read. A glob in `[files]` or `[policy]` that does not compile costs only that pattern while open (`SecretsConfig::bad_patterns`, a note naming pattern, section and layer by `bad_pattern_sources`); a `[files]` list with none left leaves the built-in list; under `deny` the manifest and PreToolUse refuse, so `dirigent_server`'s filter, which forces `deny`, stays strict. `fermata check` exits 2 on a broken config or a bad glob. - **Hooks fail open, except under `on_parse_error = "deny"`.** A broken config layer (a parse error or an unknown field) switches only that layer's rules off, with a note beside text output. With `deny` in effect, PostToolUse answers with a refusal naming the file when the config or a secret file cannot be loaded, and PreToolUse answers `deny` when the config or the rules cannot be loaded or applied. A malformed hook payload and a missing working directory stay open: no payload means nothing to render, no directory means no setting to read. A glob in `[files]` or `[policy]` that does not compile costs only that pattern while open (`SecretsConfig::bad_patterns`, a note naming pattern, section and layer by `bad_pattern_sources`); a `[files]` list with none left leaves the built-in list; under `deny` the manifest and PreToolUse refuse, so `dirigent_server`'s filter, which forces `deny`, stays strict. `fermata check` exits 2 on a broken config or a bad glob.
- **A config that cannot be read: the setting is unknown.** `SecretsConfig::denies_on_failure` reads the raw bytes of every layer: an uncommented line setting `deny` counts, broken layer or not; without one the hook stays open as for any default root; a layer whose bytes cannot be read says nothing and does not count, so an unreadable global config cannot stop every project on the machine. - **A config that cannot be read: the setting is unknown.** `SecretsConfig::denies_on_failure` reads the raw bytes of every layer: an uncommented line setting `deny` counts, broken layer or not; without one the hook stays open as for any default root; a layer whose bytes cannot be read says nothing and does not count, so an unreadable global config cannot stop every project on the machine.
- **Replacing output depends on the harness.** Claude Code ignores an `updatedToolOutput` that does not match a built-in tool's output schema and then uses the original. `harness/claude.rs` therefore walks `tool_response` in any shape and masks strings in place. `SCHEMA_VALUES` lists the enum and literal values of the 87 `outputSchema` getters in Claude Code v2.1.314, as far as they have values to list (re-read it when a release adds tools): those exact values stay. Not resolved, because they exist only at run time: Workflow's `RUN_OP_STATUS` and `runOpOutputFields` and Artifact's `handlers` arms, all flag-gated, and Artifact's `reason`. Artifact's pattern fields and that `reason` are `ARTIFACT_PATTERN_FIELDS`: a secret there refuses. A secret elsewhere under those names or in a built-in's object key cannot take a mask, so `OutputEdit::Unmaskable` refuses the output under every setting. Refusals: Bash, Read and Artifact answer a minimal schema-valid output, other built-ins keep their shape, MCP gets the plain text. `tests/cli_hook_redaction.rs` checks shapes against a copy of those schemas, and `TOOL_ENUMS` there lists each tool's enums so that dropping a value fails a test; nothing here runs Claude Code. - **Replacing output depends on the harness.** Claude Code ignores an `updatedToolOutput` that does not match a built-in tool's output schema and then uses the original. `harness/claude.rs` therefore walks `tool_response` in any shape and masks strings in place. `SCHEMA_VALUES` lists the enum and literal values of the 87 `outputSchema` getters in Claude Code v2.1.314, as far as they have values to list (re-read it when a release adds tools): those exact values stay. Not resolved, because they exist only at run time: Workflow's `RUN_OP_STATUS` and `runOpOutputFields` and Artifact's `handlers` arms, all flag-gated, and Artifact's `reason`. Artifact's pattern fields and that `reason` are `ARTIFACT_PATTERN_FIELDS`: a secret there refuses. A secret elsewhere under those names or in a built-in's object key cannot take a mask, so `OutputEdit::Unmaskable` refuses the output under every setting. Refusals: Bash, Read and Artifact answer a minimal schema-valid output, other built-ins keep their shape, MCP gets the plain text. `tests/cli_hook_redaction.rs` checks shapes against a copy of those schemas, and `TOOL_ENUMS` there lists each tool's enums so that dropping a value fails a test; nothing here runs Claude Code.
- **Read gate and write guard.** `SecretFileSet` and `unmaskable_reason` decide which listed files cannot be masked (no parser, a secret as a whole, unparseable, no value to read, tfstate by position); a Read, a Grep with a `path` and a printing command naming one is stopped under every `on_parse_error` unless `on_unparsed_read = "allow"`. `count_masks` backs the write guard: a Write, Edit or MultiEdit that adds a mask is stopped unless `on_mask_write = "allow"`. Commands meet only the session's own project rules, by verb class (`docs/security-model.md`, Layer 3). What a command writes (`Verb::Writes`) meets `.botignore`, `[policy.write]` and `[policy.read]`, also for a file not there yet, and not the read gate. - **Read gate and write guard.** `SecretFileSet` and `unmaskable_reason` decide which listed files cannot be masked (no parser, a secret as a whole, unparseable, no value to read, tfstate by position); a Read, a Grep with a `path` and a printing command naming one is stopped under every `on_parse_error` unless `on_unparsed_read = "allow"`. `count_masks` backs the write guard: a Write, Edit or MultiEdit that adds a mask is stopped unless `on_mask_write = "allow"`. Commands meet only the session's own project rules, by verb class (`docs/security-model.md`, Layer 3). What a command writes (`Verb::Writes`) meets `.botignore`, `[policy.write]` and `[policy.read]`, also for a file not there yet, and not the read gate; a printing verb's write stays `Prints` too.
- **The gate approves nothing.** `render_decision` answers `{}` for `Decision::Allow`, never `permissionDecision: "allow"`, which would skip Claude Code's permission prompt. `allow_prefixes` only skips fermata's own `ask` rules. `[policy.bash]` reaches Bash, PowerShell and Monitor. - **The gate approves nothing.** `render_decision` answers `{}` for `Decision::Allow`, never `permissionDecision: "allow"`, which would skip Claude Code's permission prompt. `allow_prefixes` only skips fermata's own `ask` rules. `[policy.bash]` reaches Bash, PowerShell and Monitor.
- **Redaction limits.** The largest: a failed tool (`PostToolUseFailure`, including a Bash non-zero exit) cannot be rewritten by any hook and is not hooked, so `cat .env; false` reaches the model. Only a `[policy.bash] deny` pattern stops that, and only for the spelling it names. Also out of reach: Monitor's output and changed-file attachments. Values split across strings, encoded values, JSON numbers in a response and binary fields are not masked. `tests/known_limits.rs` pins each limit that the binary can show: when one starts to fail, a limit was fixed and `docs/known-failures.md` must change with it (`tests/docs_known_failures.rs` keeps the two in step and keeps the failure list out of the README). `tests/docs_toml_examples.rs` loads every TOML example of `docs/configuration.md` under `deny_unknown_fields`. Heuristics warn in `additionalContext` and do not mask. Full list: `docs/known-failures.md`. - **Redaction limits.** The largest: a failed tool (`PostToolUseFailure`, including a Bash non-zero exit) cannot be rewritten by any hook and is not hooked, so `cat .env; false` reaches the model. Only a `[policy.bash] deny` pattern stops that, and only for the spelling it names. Also out of reach: Monitor's output and changed-file attachments. Values split across strings, encoded values, JSON numbers in a response and binary fields are not masked. `tests/known_limits.rs` pins each limit that the binary can show: when one starts to fail, a limit was fixed and `docs/known-failures.md` must change with it (`tests/docs_known_failures.rs` keeps the two in step and keeps the failure list out of the README). `tests/docs_toml_examples.rs` loads every TOML example of `docs/configuration.md` under `deny_unknown_fields`. Heuristics warn in `additionalContext` and do not mask. Full list: `docs/known-failures.md`.
- **Errors never quote a file.** `ParseError::Format` and `SecretsConfigError::Parse` keep the format and line number and drop the parser's text, because it can quote the failing line. Patterns (`.botignore`, `[policy]`, `[files]`) can appear in messages: they are not values, and a deny reason names them too. - **Errors never quote a file.** `ParseError::Format` and `SecretsConfigError::Parse` keep the format and line number and drop the parser's text, because it can quote the failing line. Patterns (`.botignore`, `[policy]`, `[files]`) can appear in messages: they are not values, and a deny reason names them too.
+4 -4
View File
@@ -87,7 +87,7 @@ Fermata chooses a parser from the file's name:
| `.env`, `.env.*`, `*.env`, `credentials`, `terraform.tfvars`, `*.auto.tfvars`, `.aws/credentials`, `secrets.{sh,bash,zsh,ini,conf,cfg}` | `.env` style (`KEY=value`, `[section]` lines skipped) | | `.env`, `.env.*`, `*.env`, `credentials`, `terraform.tfvars`, `*.auto.tfvars`, `.aws/credentials`, `secrets.{sh,bash,zsh,ini,conf,cfg}` | `.env` style (`KEY=value`, `[section]` lines skipped) |
| `*.toml`, `*.json`, `*.yaml`, `*.yml`, `*.py`, `*.properties` (also `secrets.*` and `credentials.*` with these extensions) | TOML, JSON, YAML (every document), Python assignments, properties | | `*.toml`, `*.json`, `*.yaml`, `*.yml`, `*.py`, `*.properties` (also `secrets.*` and `credentials.*` with these extensions) | TOML, JSON, YAML (every document), Python assignments, properties |
| `*.tfstate`, `*.tfstate.backup` | JSON. Its secrets sit by position, not by key, so a Read is always stopped | | `*.tfstate`, `*.tfstate.backup` | JSON. Its secrets sit by position, not by key, so a Read is always stopped |
| `*.pem`, `*.key`, `id_rsa`, `id_ed25519`, `id_ecdsa`, `config/master.key`, `config/credentials/*.key` | Opaque text: a secret as a whole. A Read is stopped unless it holds only certificate and public key blocks, and beside them only blank lines, comments, `Bag Attributes` and their indented lines, `subject=`, `issuer=` or the head of `openssl x509 -text`. A PEM private block's body, or a single token of 16 or more characters, becomes a manifest entry | | `*.pem`, `*.key`, `id_rsa`, `id_ed25519`, `id_ecdsa`, `config/master.key`, `config/credentials/*.key` | Opaque text: a secret as a whole. A Read is stopped unless it holds only certificate and public key blocks, and beside them only blank lines, comments, indented lines, `Bag Attributes`, `subject=`, `issuer=`, a title over a `====` line or the output of `openssl x509 -text`, with no assignment. A PEM private block's body, or a single token of 16 or more characters, becomes a manifest entry |
| `.netrc`, `.htpasswd`, `*.p12`, `*.pfx` | No parser. A Read is stopped, and nothing from them is masked | | `.netrc`, `.htpasswd`, `*.p12`, `*.pfx` | No parser. A Read is stopped, and nothing from them is masked |
A `[[file]]` override can name a format. A leading UTF-8 byte order mark is read. UTF-16, Latin-1 and JSON with comments do not parse. A file named `secrets.*` or `credentials.*` takes its parser from its extension (`secrets.yaml`, `secrets.sh`). One with a source or template extension (`rs`, `ts`, `go`, `java`, `md`, `tf`, `example`, `template`, and so on) is taken for code that handles secrets, and is neither parsed nor stopped. A `[[file]]` override can name a format. A leading UTF-8 byte order mark is read. UTF-16, Latin-1 and JSON with comments do not parse. A file named `secrets.*` or `credentials.*` takes its parser from its extension (`secrets.yaml`, `secrets.sh`). One with a source or template extension (`rs`, `ts`, `go`, `java`, `md`, `tf`, `example`, `template`, and so on) is taken for code that handles secrets, and is neither parsed nor stopped.
@@ -342,13 +342,13 @@ fgrep rg awk sed strings xxd od hexdump base64 gc type get-content select-string
meets `.botignore`, `[policy.read]` and the read gate; a metadata verb as a bare word meets `.botignore`, `[policy.read]` and the read gate; a metadata verb as a bare word
(`ls stat file test [ du which echo printf`, `git status`, `git commit`, ...) meets (`ls stat file test [ du which echo printf`, `git status`, `git commit`, ...) meets
nothing; a write (a redirect's target, `cp mv rm touch mkdir tee sed -i`, the value of nothing; a write (a redirect's target, `cp mv rm touch mkdir tee sed -i`, the value of
`-o`, the rest in [Layer 3](security-model.md#layer-3-access-control-botignore--botsecrets-policy)) `-o` on a verb that does not print, the rest in [Layer 3](security-model.md#layer-3-access-control-botignore--botsecrets-policy))
meets `.botignore`, `[policy.write]` and `[policy.read]`, also for a file not there yet; meets `.botignore`, `[policy.write]` and `[policy.read]`, also for a file not there yet;
every other verb (`source`, `python`, `chmod`) meets `.botignore` and `[policy.read]`. Only every other verb (`source`, `python`, `chmod`) meets `.botignore` and `[policy.read]`. Only
a word that names an existing file, an existing path with a separator, a path with `$`, a word that names an existing file, an existing path with a separator, a path with `$`,
`*` or `?` in it, or a file the command writes counts; `$(...)`, scripts and a verb off `*` or `?` in it, or a file the command writes counts; `$(...)`, scripts and a verb off
the list that opens the file itself are not seen. The argument of a shell's `-c` and the the list that opens the file itself are not seen. The line given to a shell's `-c` and to
first argument of `eval` are read as a command line, also behind a wrapper (`sudo bash -c`, `eval` are read as a command line, also behind a wrapper (`sudo bash -c`,
`X=1 bash -c`) or given by path (`/bin/bash -c`). The forms that pass, and the harmless `X=1 bash -c`) or given by path (`/bin/bash -c`). The forms that pass, and the harmless
commands a rule stops, are in [Known failures](known-failures.md). commands a rule stops, are in [Known failures](known-failures.md).
+8 -6
View File
@@ -21,13 +21,15 @@ This is the largest limit for values fermata knows.
The check reads the command's text, not what the shell makes of it. The check reads the command's text, not what the shell makes of it.
- A substitution that builds the name, and a script that opens the file: `cat $(printf '.e%s' nv)`, `python -c "print(open('.env').read())"`, `sh run.sh`. (Test: `a_variable_a_substitution_and_a_script_hide_the_file_from_the_command_rules`.) - A substitution that builds the name, and a script that opens the file: `cat $(printf '.e%s' nv)`, `python -c "print(open('.env').read())"`, `sh run.sh`. (Test: `a_variable_a_substitution_and_a_script_hide_the_file_from_the_command_rules`.)
- A form where the name is not a word of its own: `echo "$(cat .env)"`, `bash <<EOF` with `cat .env` in its body, `find . -name .env -exec cat {} \;`, `curl -d @.env`, `curl -F file=@.env`, `git show HEAD:.env`, `git show :.env`, `cat .{env,x}`. (Test: `a_command_that_names_the_file_in_a_form_the_check_does_not_read_passes`.) - A form where the name is not a word of its own: `echo "$(cat .env)"`, `bash <<EOF` with `cat .env` in its body, `find . -name .env -exec cat {} \;`, `curl -d @.env`, `curl -F file=@.env`, `git show HEAD:.env`, `git show :.env`, `cat .{env,x}`, and a short flag's attached value (`git commit -F.env`, `tool -f.env`). (Test: `a_command_that_names_the_file_in_a_form_the_check_does_not_read_passes`.)
- A command line the check does not read as one: `bash -c -- 'cat .env'`, `eval` past its first argument (`eval 'true' 'cat .env'`), and a shell behind a wrapper's flag value (`sudo -u root bash -c 'cat .env'`). (Test: `a_command_line_the_check_does_not_read_as_one_passes`.) - A command line the check does not read as one: a shell behind a wrapper's flag value (`sudo -u root bash -c 'cat .env'`), a shell or language off the list (`rc -c`, `python3 -c`), and an encoded line (`pwsh -EncodedCommand`). (Test: `a_command_line_the_check_does_not_read_as_one_passes`.)
- A flag named `--exclude=`, `--exclude-dir=`, `--ignore=` or `--grep=` hides its value, for any program, since what a script does with it is not read: `tool --exclude=.env`. (Test: `a_flag_named_like_an_exclude_hides_its_value_for_any_program`.)
- A script given by an absolute path cannot be told from the real wrapper: `/home/me/scripts/env ls .env` passes, as `/usr/bin/env ls .env` should. (Test: `a_script_given_by_an_absolute_path_passes_when_its_first_word_is_a_metadata_verb`.)
- A printing verb off the list: `python -c`, `perl -e`. (Test: `a_printing_verb_off_the_list_is_not_checked_against_the_rules_unless_it_names_the_file`.) - A printing verb off the list: `python -c`, `perl -e`. (Test: `a_printing_verb_off_the_list_is_not_checked_against_the_rules_unless_it_names_the_file`.)
- A ruled file run as the program itself: `./.env`, `sudo vendor/bin/x` under a rule on `vendor/`. (Test: `a_ruled_file_run_as_the_program_passes`.) - A ruled file run as the program itself: `./.env`, `sudo vendor/bin/x` under a rule on `vendor/`. (Test: `a_ruled_file_run_as_the_program_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 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 new file named to a verb off the writing list: `git clone https://example.invalid/x vendor/new`, `unzip a.zip -d vendor/new`, `python make.py vendor/new`, and a flag's value such as `cp --target-directory=vendor/new a.txt`. (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`.)
## Secret files fermata cannot mask ## Secret files fermata cannot mask
@@ -35,10 +37,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; `eval cat id_rsa`, where only the first argument is read as a command line; `cat <&3 id_rsa`, where `<&` ends the segment; `cat */id_rsa` and `cat ./s*/a.key`, a glob over directories. 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; `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`.)
- 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 certificate file may hold comment lines and indented attribute lines beside its blocks, so a value spelled as one of them passes: `# fake-value`, ` api_token: fake-value`. (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`.)
## Values that never enter the list of known secrets ## Values that never enter the list of known secrets
@@ -57,7 +59,7 @@ These values then reach the model.
- A secret number that an MCP tool returns as a JSON number. (Test: `a_secret_number_in_mcp_structured_content_is_not_masked`.) - A secret number that an MCP tool returns as a JSON number. (Test: `a_secret_number_in_mcp_structured_content_is_not_masked`.)
- A secret equal to a plain setting word (`true`, `3600`, a short duration). It makes no entry. (Test: `tests/core_value_class.rs`.) - A secret equal to a plain setting word (`true`, `3600`, a short duration). It makes no entry. (Test: `tests/core_value_class.rs`.)
- A secret file outside the working project: a Read of `../other/.env` and `cat ../other/.env` pass. (Test: `a_secret_file_outside_the_project_is_not_masked_and_a_read_of_it_passes`.) - A secret file outside the working project: a Read of `../other/.env` and `cat ../other/.env` pass. (Test: `a_secret_file_outside_the_project_is_not_masked_and_a_read_of_it_passes`.)
- A run with no `.botsecrets` or `.botignore` above the working directory: there is nothing to load, and the output passes. (From the code: `find_project_root` finds no root.) - A run with no `.git`, `.botsecrets`, `.botignore` or `fermata.toml` above the working directory: nothing is loaded, and the output passes. (Test: `a_run_outside_any_project_is_not_masked`.)
## Masks that do too much or too little ## Masks that do too much or too little
+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 argument of a shell's `-c` (`bash sh zsh dash ksh mksh ash yash fish csh tcsh pwsh powershell`, also PowerShell's `-Command` and `cmd /c`) and of `eval` is read as a command line of its own, 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 writing verb meets `.botignore`, `[policy.write]` and `[policy.read]`, also for a file that is not there yet, and not the read gate: a redirect's target, every path of `mv rm rmdir touch mkdir tee truncate shred set-content add-content out-file new-item remove-item move-item` and of `sed -i`, the last path of `cp ln install rsync scp copy-item`, `dd of=`, and the value of `-o` or `--output` (`wget -O`). 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, 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.
- **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.
+47 -10
View File
@@ -396,6 +396,8 @@ fn a_command_that_names_the_file_in_a_form_the_check_does_not_read_passes() {
"git show HEAD:.env", "git show HEAD:.env",
"git show :.env", "git show :.env",
"cat .{env,x}", "cat .{env,x}",
"git commit -F.env",
"tool -f.env",
"echo \"$(cat .env)\"", "echo \"$(cat .env)\"",
] { ] {
let out = p.bash(command); let out = p.bash(command);
@@ -412,9 +414,10 @@ fn a_command_line_the_check_does_not_read_as_one_passes() {
let p = ruled(rule); let p = ruled(rule);
assert!(denied(&p.bash("sudo bash -c 'cat .env'")), "control"); assert!(denied(&p.bash("sudo bash -c 'cat .env'")), "control");
for command in [ for command in [
"bash -c -- 'cat .env'",
"eval 'true' 'cat .env'",
"sudo -u root bash -c 'cat .env'", "sudo -u root bash -c 'cat .env'",
"rc -c 'cat .env'",
"pwsh -EncodedCommand Y2F0IC5lbnY=",
"python3 -c 'cat .env'",
] { ] {
let out = p.bash(command); let out = p.bash(command);
assert!(passes(&out), "{rule:?}: {command}: {out}"); assert!(passes(&out), "{rule:?}: {command}: {out}");
@@ -422,16 +425,17 @@ 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, `eval` past its first /// A wrapper's flag whose value is a word makes that word the verb, `-o`'s value before a
/// argument is text, `<&` ends the segment and a glob over directories is no file: the /// shell's line is taken for its first word, `<&` ends the segment, a glob over directories
/// read gate sees none of them. A rule on the file's name still reads each. /// 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.
#[test] #[test]
fn a_flag_value_as_verb_and_a_glob_over_directories_pass_the_read_gate() { fn a_flag_value_as_verb_and_a_glob_over_directories_pass_the_read_gate() {
let files: [(&str, &[u8]); 3] = [("id_rsa", b"fake key text\n"), ("sub/id_rsa", b"fake key text\n"), ("sub/a.key", b"fake key text\n")]; let files: [(&str, &[u8]); 3] = [("id_rsa", b"fake key text\n"), ("sub/id_rsa", b"fake key text\n"), ("sub/a.key", b"fake key text\n")];
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", "eval cat id_rsa", "cat <&3 id_rsa", "cat */id_rsa", "cat ./s*/a.key"]; 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"];
for command in commands { for command in commands {
assert!(passes(&p.bash(command)), "{command}"); assert!(passes(&p.bash(command)), "{command}");
} }
@@ -452,6 +456,35 @@ fn a_ruled_file_run_as_the_program_passes() {
} }
} }
/// A wrapper given by an absolute path may be a script, and it cannot be told from the real
/// one: its first word counts as a path, and if that is a metadata verb the file passes.
#[test]
fn a_script_given_by_an_absolute_path_passes_when_its_first_word_is_a_metadata_verb() {
let p = ruled(RULES[0]);
assert!(denied(&p.bash("/home/me/scripts/env .env")), "control");
assert!(passes(&p.bash("/home/me/scripts/env ls .env")));
}
/// `--exclude=`, `--exclude-dir=`, `--ignore=` and `--grep=` are taken at their word, for any
/// program: what a script does with such a flag's value is not read.
#[test]
fn a_flag_named_like_an_exclude_hides_its_value_for_any_program() {
let p = ruled(RULES[0]);
for command in ["tool --exclude=.env", "tool --ignore=.env", "python x.py --grep=.env"] {
assert!(passes(&p.bash(command)), "{command}");
}
}
/// With no `.git`, `.botsecrets`, `.botignore` or `fermata.toml` above the working directory
/// nothing is loaded, and the output passes.
#[test]
fn a_run_outside_any_project_is_not_masked() {
let p = project(&env_file(&format!("API_TOKEN={VALUE}\n")));
assert!(p.after_bash(VALUE).contains(MASK), "control: a .git alone makes a project");
fs::remove_dir_all(p.dir().join(".git")).unwrap();
assert!(p.after_bash(VALUE).contains(VALUE));
}
/// 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() {
@@ -474,19 +507,23 @@ fn a_harmless_command_a_rule_still_stops() {
#[test] #[test]
fn a_new_file_named_to_a_verb_off_the_writing_list_is_not_checked() { fn a_new_file_named_to_a_verb_off_the_writing_list_is_not_checked() {
let p = project(&[(".botignore", b"vendor/\n"), ("vendor/a", b"x"), ("a.txt", b"x")]); let p = project(&[(".botignore", b"vendor/\n"), ("vendor/a", b"x"), ("a.txt", b"x")]);
for command in ["git clone https://example.invalid/x vendor/new", "unzip a.zip -d vendor/new", "python make.py vendor/new", "cp --target-directory=vendor/new a.txt"] { for command in ["git clone https://example.invalid/x vendor/new", "unzip a.zip -d vendor/new", "python make.py vendor/new", "tar cf vendor/new a.txt", "touch vend*/new", "perl -pi -e 1 vendor/new"] {
assert!(passes(&p.bash(command)), "{command}"); assert!(passes(&p.bash(command)), "{command}");
} }
assert!(denied(&p.bash("cp a.txt vendor/new")), "control"); assert!(denied(&p.bash("cp a.txt vendor/new")), "control");
assert!(denied(&p.bash("tool > vendor/new")), "control"); assert!(denied(&p.bash("tool > vendor/new")), "control");
let p = project(&[(".botsecrets", b"[policy.write]\npatterns = [\"a.txt\"]\n"), ("a.txt", b"x")]);
for command in ["perl -pi -e 1 a.txt", "awk -i inplace 1 a.txt"] {
assert!(passes(&p.bash(command)), "{command}");
}
} }
/// Text a certificate file may carry around its blocks is let through: a comment line and /// Text a certificate file may carry is let through: a comment, an indented line, `subject=`,
/// an indented attribute. A value spelled as one of them passes. /// `issuer=`, a title above `====`, and whatever a block holds. A value spelled so passes.
#[test] #[test]
fn a_comment_or_an_attribute_line_beside_a_certificate_passes() { fn a_comment_or_an_attribute_line_beside_a_certificate_passes() {
const CERT: &str = "-----BEGIN CERTIFICATE-----\nFAKEFAKEfakeFAKEfake\n-----END CERTIFICATE-----\n"; const CERT: &str = "-----BEGIN CERTIFICATE-----\nFAKEFAKEfakeFAKEfake\n-----END CERTIFICATE-----\n";
for extra in ["# fake-beside-a-cert\n", " api_token: fake-beside-a-cert\n"] { for extra in ["# fake-beside-a-cert\n", " api_token: fake-beside-a-cert\n", " fake-beside-a-cert\n", "subject=fake-beside-a-cert\n", "issuer=API_TOKEN=fake-beside-a-cert\n", "fake-beside-a-cert\n====\n", "-----BEGIN CERTIFICATE-----\nAPI_TOKEN=fake-beside-a-cert\n-----END CERTIFICATE-----\n"] {
let content = format!("{extra}{CERT}"); let content = format!("{extra}{CERT}");
let p = project(&[("server.pem", content.as_bytes())]); let p = project(&[("server.pem", content.as_bytes())]);
assert!(passes(&p.read("server.pem")), "{extra}"); assert!(passes(&p.read("server.pem")), "{extra}");