docs(fermata): name the command forms that pass, the harmless ones stopped and what a bad glob costs

Both READMEs, security-model.md, configuration.md, commands.md, threat-model.md, the crate
CLAUDE.md and the filter section of matrix.md. Each stated form has a row in
tests/known_limits.rs. The Edit claim now says it comes from Claude Code's documentation, and
"by no other route" is gone. cli_hook_fail_closed's open control asserts that .botignore and
the read gate stay on and that a note names the bad pattern.
This commit is contained in:
2026-11-07 02:02:42 +01:00
parent 6bf602aa6a
commit bfe83165a7
7 changed files with 53 additions and 25 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ Developed in this monorepo; planned to be exported as a standalone repo in the f
## Failure behaviour and known limits ## Failure behaviour and known limits
- **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. `fermata check` does not refuse on a broken config. - **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 by name); 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). - **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).
+13 -4
View File
@@ -10,17 +10,26 @@
These failures were reproduced with fake values, through the fermata binary, and each is a test that asserts the failure happens, except where it says it comes from Claude Code's documentation. The list is not complete. These failures were reproduced with fake values, through the fermata binary, and each is a test that asserts the failure happens, except where it says it comes from Claude Code's documentation. The list is not complete.
- **`cat .env; false` is unprotected.** According to Claude Code's documentation and bundled code, a failed tool's output goes down a path no hook can rewrite. With `.env` in `.botignore` or `[policy.read]`, a command that names the file (`cat .env; false`, `cat ./.env; false`) is stopped, and `env; false` and a failing `npm test` that prints its environment are not. On the default configuration a parseable `.env` is not stopped at all. - **`cat .env; false` is unprotected.** According to Claude Code's documentation and bundled code, a failed tool's output goes down a path no hook can rewrite. With `.env` in `.botignore` or `[policy.read]`, a command that names the file (`cat .env; false`, `cat ./.env; false`) is stopped, and `env; false` and a failing `npm test` that prints its environment are not. On the default configuration a parseable `.env` is not stopped at all.
- **Commands are checked only for the files they name.** A variable or substitution that builds the name, a script that opens the file, a printing verb that is not on the list (`python -c`, `dd`, `perl`) and `cd ../other && cat .env` pass. - **Commands are checked only for the files they name, in the forms the check reads.** These pass, with `.env` under a rule:
- **A secret file fermata cannot mask is stopped when a Read names it, and by no other route.** `*.p12`, `*.pfx`, `.netrc`, `.htpasswd` and a text `*.key` pass `grep -r TOKEN .`, `tar cf x.tar .` and a script that opens them. The stop needs the PreToolUse hook: without it a Read reaches the model. A text with `{{` or `{%` that does not parse passes as a template, and a literal value in it reaches the model. - a substitution that builds the name (`cat $(printf '.e%s' nv)`), and `echo "$(cat .env)"`, since a substitution inside double quotes is one word
- a script that opens the file, a printing verb that is not on the list (`python -c`, `dd`, `perl`), and a heredoc fed to a shell (`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` and `cat .{env,x}`
- `cd ../other && cat .env`, and a file a command is about to make (`cp a.txt vendor/new` under `vendor/`)
- **Some harmless commands are stopped under a rule.** With `.env` under a rule, `grep -A 2 .env a.txt`, `rg -t py .env`, `grep -r TOKEN --exclude=.env .`, `tar --exclude=.env -cf x.tar .` and `git --no-pager status .env` are denied.
- **A secret file fermata cannot mask is stopped only when a call names it.** That means a Read, a Grep with that `path`, or a printing command naming `*.p12`, `*.pfx`, `.netrc`, `.htpasswd` or a text `*.key`.
- `grep -r TOKEN .`, `tar cf x.tar .` and a script that opens the file pass. So do `sudo -u root cat id_rsa`, `cat */id_rsa` and a Grep with `path = "~/.ssh/id_rsa"`.
- The stop needs the PreToolUse hook: without it a Read reaches the model.
- A text with `{{` or `{%` that does not parse passes as a template, and a literal value in it reaches the model.
- A `.pem` is judged by its armor labels: with only certificate labels it passes, whatever other text it holds.
- **Many values never enter the list of known secrets.** - **Many values never enter the list of known secrets.**
- a key the key filter does not match, in a parsed file; a `.tfvars` heredoc; a comment in a TOML or YAML file - a key the key filter does not match, in a parsed file; a `.tfvars` heredoc; a `*.tfvars` other than `terraform.tfvars` and `*.auto.tfvars`; a comment in a TOML or YAML file
- the first value of a duplicate JSON key - the first value of a duplicate JSON key
- a `.env` value inside a quoted value that spans several lines, when a program prints it alone - a `.env` value inside a quoted value that spans several lines, when a program prints it alone
- Python triple quotes, and shell-quoted spellings such as `'a'\''b-x` and `abc"def"-x`, when a program prints the decoded value - Python triple quotes, and shell-quoted spellings such as `'a'\''b-x` and `abc"def"-x`, when a program prints the decoded value
- a number under 6 characters, and a secret number that a tool returns as a JSON number - a number under 6 characters, and a secret number that a tool returns as a JSON number
- a UTF-16 or Latin-1 file, or JSON with comments, when no command names it - a UTF-16 or Latin-1 file, or JSON with comments, when no command names it
- a secret file outside the working project - a secret file outside the working project
- **A short password's word is masked everywhere**, in other files too, and an Edit that names such a line in source can fail. A short line of a multi-line value passes when printed alone. - **A short password's word is masked everywhere**, in other files too. An Edit copied from such masked text fails, since Claude Code's Edit needs the real text (from its documentation). A short line of a multi-line value passes when printed alone.
- **Other routes that stay open:** Monitor's output, a changed file's attachment and a hook that times out (all from Claude Code's documentation), values split across strings, encoded values, binary fields, and any secret the heuristic scanner finds, since it only warns. - **Other routes that stay open:** Monitor's output, a changed file's attachment and a hook that times out (all from Claude Code's documentation), values split across strings, encoded values, binary fields, and any secret the heuristic scanner finds, since it only warns.
- **The write guard is narrow.** It stops a Write or Edit that adds a mask. A shell command that writes a mask, the `absent` style, and a real run of exactly five asterisks are not handled. - **The write guard is narrow.** It stops a Write or Edit that adds a mask. A shell command that writes a mask, the `absent` style, and a real run of exactly five asterisks are not handled.
+2 -2
View File
@@ -29,7 +29,7 @@ fermata check [OPTIONS] <PATHS>...
|------|---------| |------|---------|
| 0 | Allowed (or Ask -- the agent may prompt the user) | | 0 | Allowed (or Ask -- the agent may prompt the user) |
| 1 | Denied -- the policy blocks this operation | | 1 | Denied -- the policy blocks this operation |
| 2 | Internal error (could not load policy, bad arguments, a config layer or a `[files]` pattern that does not load, etc.) The message names the file and line. | | 2 | Internal error (could not load policy, bad arguments, a config layer that does not load, or a `[files]` or `[policy]` pattern that does not compile, etc.) The message names the file and line. |
When multiple paths are provided, fermata evaluates each one independently and returns the **worst** result. If any path is denied, the exit code is 1. When multiple paths are provided, fermata evaluates each one independently and returns the **worst** result. If any path is denied, the exit code is 1.
@@ -79,7 +79,7 @@ The hook payload is always read from **stdin** as JSON. The response is written
| 0 | Success. The JSON response on stdout tells the harness what to do. | | 0 | Success. The JSON response on stdout tells the harness what to do. |
| 2 | Internal error (unknown harness, unknown event type, stdin read failure) | | 2 | Internal error (unknown harness, unknown event type, stdin read failure) |
Fermata follows a **fail-open** policy for hooks: if the payload cannot be parsed, it writes `{}` to stdout and exits 0 so the agent can continue. If a config layer cannot be loaded (including a field fermata does not know), only that layer's rules are off, and PostToolUse adds a note beside text output naming the file and line. A tool PreToolUse has no rules for answers `{}` without a message. Errors are reported on stderr and never quote a file. Fermata follows a **fail-open** policy for hooks: if the payload cannot be parsed, it writes `{}` to stdout and exits 0 so the agent can continue. If a config layer cannot be loaded (including a field fermata does not know), only that layer's rules are off, and PostToolUse adds a note beside text output naming the file and line. A glob that does not compile costs only that pattern, with a note naming it. A tool PreToolUse has no rules for answers `{}` without a message. Errors are reported on stderr and never quote a file.
The exception is `on_parse_error = "deny"` (the default is `allow`). If the config or a secret file cannot be loaded, `post-tool-use` answers with a refusal naming the file, in a form the tool's output schema accepts; if the config or the rules cannot be loaded or applied, `pre-tool-use` answers deny. See [`on_parse_error`](configuration.md) for what happens when the config itself is the broken file. Claude Code drops a replacement that its schema rejects and uses the original: see [Known limits](security-model.md#known-limits). The exception is `on_parse_error = "deny"` (the default is `allow`). If the config or a secret file cannot be loaded, `post-tool-use` answers with a refusal naming the file, in a form the tool's output schema accepts; if the config or the rules cannot be loaded or applied, `pre-tool-use` answers deny. See [`on_parse_error`](configuration.md) for what happens when the config itself is the broken file. Claude Code drops a replacement that its schema rejects and uses the original: see [Known limits](security-model.md#known-limits).
+9 -6
View File
@@ -76,7 +76,7 @@ key-value pairs, and uses the values for exact-match redaction.
id_rsa, id_ed25519, id_ecdsa, Secrets.toml, Secrets.*.toml, id_rsa, id_ed25519, id_ecdsa, Secrets.toml, Secrets.*.toml,
terraform.tfvars, *.auto.tfvars, terraform.tfstate, *.tfstate, terraform.tfvars, *.auto.tfvars, terraform.tfstate, *.tfstate,
*.tfstate.backup, .docker/config.json, config/master.key, *.tfstate.backup, .docker/config.json, config/master.key,
config/credentials/*.key, .aws/credentials, .netrc, .htpasswd, config/credentials/*.key, .aws/credentials, credentials, .netrc, .htpasswd,
service-account.json, service-account-key.json service-account.json, service-account-key.json
``` ```
@@ -87,14 +87,14 @@ 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 the file holds only certificates. 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 its armor labels are only certificates and public keys (other text in the file is not looked at). 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.
**The read gate.** A Read, a Grep with a `path`, or a printing command (`cat`, `grep`, ...) naming an existing file on this list that fermata cannot mask is stopped, under every `on_parse_error`: the file has no parser, is a secret as a whole, cannot be parsed, holds lines no value can be read from, or marks its secrets by position. The setting is `[enforcement] on_unparsed_read`. Other routes (`grep -r`, a script that opens the file, a verb off the list) pass the gate, and the file's values are not masked there. A file with `{{` or `{%` that fails to parse passes as a template. See [Known limits](security-model.md#known-limits). **The read gate.** A Read, a Grep with a `path`, or a printing command (`cat`, `grep`, ...) naming an existing file on this list that fermata cannot mask is stopped, under every `on_parse_error`: the file has no parser, is a secret as a whole, cannot be parsed, holds lines no value can be read from, or marks its secrets by position. The setting is `[enforcement] on_unparsed_read`. Other routes (`grep -r`, a script that opens the file, a verb off the list) pass the gate, and the file's values are not masked there. A file with `{{` or `{%` that fails to parse passes as a template. See [Known limits](security-model.md#known-limits).
Setting `files.patterns` in a layer **replaces** the defaults entirely. Setting `files.patterns` in a layer **replaces** the defaults entirely. A glob here or in `[policy]` that does not compile costs only that pattern, with a note naming it beside text output, and a list with no usable pattern leaves the built-in list. Under `on_parse_error = "deny"` it refuses instead, and `fermata check` exits 2.
```toml ```toml
[files] [files]
@@ -342,9 +342,12 @@ 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 (`ls stat file meets `.botignore`, `[policy.read]` and the read gate; a metadata verb (`ls stat file
test [ du which echo printf`, `git status`, `git commit`, ...) meets nothing; every other test [ du which echo printf`, `git status`, `git commit`, ...) meets nothing; every other
verb (`source`, `cp`, `rm`, `python`) meets the rules but not the read gate. Only verb (`source`, `cp`, `rm`, `python`) meets the rules but not the read gate. Only
words that name an existing file or hold a path separator count; `$VAR`, `$(...)`, a word that names an existing file, an existing path with a separator, a path with `$`,
scripts and a verb off the list that opens the file itself are not seen. `[policy.write]` `*` or `?` in it, or a redirect's target counts; `$(...)`, scripts and a verb off the
is not applied to commands. list that opens the file itself are not seen. The argument of `bash -c` and `eval` is
read as a command line. `[policy.write]` is not applied to commands. The forms that
pass, and the harmless commands a rule stops, are in
[Layer 3](security-model.md#layer-3-access-control-botignore--botsecrets-policy).
- Blank lines and lines starting with `#` are ignored. - Blank lines and lines starting with `#` are ignored.
- `*` matches anything except `/`. - `*` matches anything except `/`.
+20 -9
View File
@@ -46,14 +46,24 @@ 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. 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.
- **Commands that name a file.** A command is split into segments, and each word that names an existing file (or holds a path separator) is checked. 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. Any other verb (`source`, `cp`, `rm`, `python`) meets the path rules only. A metadata verb (`ls stat file test [ du which echo printf`, and `git status`, `git check-ignore`, `git ls-files`, `git commit`) 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 redirect's target is checked. So `composer require vendor/package` and `git checkout build/fix` name nothing under a rule on `vendor/` or `build/`. The argument of `bash -c`, `sh -c`, `zsh -c` and `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. 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. Any other verb (`source`, `cp`, `rm`, `python`) meets the path rules only. A metadata verb (`ls stat file test [ du which echo printf`, and `git status`, `git check-ignore`, `git ls-files`, `git commit`) 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.
Reading `.env` is allowed by default, and only Layer 1 stands between its values and the model. On the default configuration a parseable `.env` is not stopped at all, by any route. Reading `.env` is allowed by default, and only Layer 1 stands between its values and the model. On the default configuration a parseable `.env` is not stopped at all, by any route.
**Limitations of the command check.** It sees the command's text, not what the shell makes of it. A variable or a command substitution that builds the file name (`cat $(printf '.e%s' nv)`), `"$(cat .env)"`, a script that opens the file (`sh run.sh`, `python -c "print(open('.env').read())"`), `cd ../other && cat .env` and a printing verb that is not on the list (`dd`, `perl`, `python -c`) pass. A command run in one project is not stopped by another project's rules. A secret file outside every project has no rules at all. **Limitations of the command check.** It sees the command's text, not what the shell makes of it. These pass:
- A substitution that builds the file name (`cat $(printf '.e%s' nv)`), and `echo "$(cat .env)"`: a substitution inside double quotes is one word.
- A script that opens the file (`sh run.sh`, `python -c "print(open('.env').read())"`), a heredoc fed to a shell (`bash <<EOF` with `cat .env` in its body), and a printing verb that is not on the list (`dd`, `perl`, `python -c`).
- `find . -name .env -exec cat {} \;`, `curl -d @.env`, `curl -F file=@.env`, `git show HEAD:.env`, `git show :.env` and `cat .{env,x}`: the name is not a word of its own.
- `cd ../other && cat .env`, and a command run in one project under another project's rules. A secret file outside every project has no rules at all.
- A file a command is about to make (`cp a.txt vendor/new`, `touch vendor/new`) is not there to check. A redirect's target is.
The read gate also misses `sudo -u root cat id_rsa`, where the flag's value `root` becomes the verb, and `cat */id_rsa` and `cat ./s*/a.key`, a glob over directories, which is no file. A rule on the name still reads the first two.
**Harmless commands it stops.** Under a rule on `.env`: `grep -A 2 .env a.txt`, `grep -m 1 .env a.txt` and `rg -t py .env`, where a flag's value takes the pattern's place; `grep -r TOKEN --exclude=.env .`, `tar --exclude=.env -cf x.tar .`, `rsync --exclude=.env a b` and `npm test -- --grep=.env`, where the text after `=` counts as a path; and `git --no-pager status .env`, where a flag before `status` loses the metadata class.
### Layer 4: Structural Containment (External) ### Layer 4: Structural Containment (External)
@@ -63,7 +73,7 @@ fermata does not own this layer. It would come from a container runtime, VM, or
## Design Principles ## Design Principles
**Fail-open by default.** A parse error in a `.botsecrets` layer turns that layer's rules off, with a note beside text output that names the file and line and says so; the other layers stay in force. A field that fermata does not know (a typo, or a setting that no longer exists) is a parse error: the layer is off until the field is fixed. A parse error in a secret file lets the values of that file reach the model, with a note beside text output, except that a Read of a listed file that cannot be masked is stopped (the read gate above). Two exceptions to fail-open: under `on_parse_error = "deny"` the hooks refuse instead, and under `"onFailure": "block"` on PreToolUse a `fermata` that cannot run stops every tool. `on_parse_error` is `allow` unless you set `deny`. **Fail-open by default.** A parse error in a `.botsecrets` layer turns that layer's rules off, with a note beside text output that names the file and line and says so; the other layers stay in force. A field that fermata does not know (a typo, or a setting that no longer exists) is a parse error: the layer is off until the field is fixed. A glob in `[files]` or `[policy]` that does not compile costs only that pattern, with a note naming it beside text output; a `[files]` list with no usable pattern leaves the built-in list. A parse error in a secret file lets the values of that file reach the model, with a note beside text output, except that a Read of a listed file that cannot be masked is stopped (the read gate above). Two exceptions to fail-open: under `on_parse_error = "deny"` the hooks refuse instead, and under `"onFailure": "block"` on PreToolUse a `fermata` that cannot run stops every tool. `on_parse_error` is `allow` unless you set `deny`.
**Not a permission approver.** PreToolUse can stop a call or ask, and otherwise says nothing. It never answers `allow`, because Claude Code would then skip its own permission prompt, and installing a guard must not remove one. `allow_prefixes` only skips fermata's own `ask` rules. **Not a permission approver.** PreToolUse can stop a call or ask, and otherwise says nothing. It never answers `allow`, because Claude Code would then skip its own permission prompt, and installing a guard must not remove one. `allow_prefixes` only skips fermata's own `ask` rules.
@@ -84,19 +94,20 @@ The PostToolUse hook redacts what Claude Code hands it and accepts back. These a
**Not covered:** **Not covered:**
- **A tool that fails. This is the largest limit for values in the manifest.** Claude Code sends a failed tool's text through `PostToolUseFailure`, whose hooks can only add a note. That includes a Bash command with a non-zero exit code, whose error text holds the command's output, and an MCP error result. `cat .env; false` reaches the model unredacted, and so does a failing `npm test` that prints its environment, `curl -v -f` with a token header on a 500, or any failing `set -x` script. This is from Claude Code's documentation and bundle; fermata does not hook the event (test: the event is no hook event here). Only a rule stops such a command, and only for what names the file. With `.env` in `.botignore` or `[policy.read]`, `cat .env; false`, `cat ./.env; false` and `source .env; false` are denied, while `env; false`, `grep -r TOKEN .; false`, `printenv; false` and a failing `npm test` pass. On the default configuration a parseable `.env` is not stopped at all (test). - **A tool that fails. This is the largest limit for values in the manifest.** Claude Code sends a failed tool's text through `PostToolUseFailure`, whose hooks can only add a note. That includes a Bash command with a non-zero exit code, whose error text holds the command's output, and an MCP error result. `cat .env; false` reaches the model unredacted, and so does a failing `npm test` that prints its environment, `curl -v -f` with a token header on a 500, or any failing `set -x` script. This is from Claude Code's documentation and bundle; fermata does not hook the event (test: the event is no hook event here). Only a rule stops such a command, and only for what names the file. With `.env` in `.botignore` or `[policy.read]`, `cat .env; false`, `cat ./.env; false` and `source .env; false` are denied, while `env; false`, `grep -r TOKEN .; false`, `printenv; false` and a failing `npm test` pass. On the default configuration a parseable `.env` is not stopped at all (test).
- **Commands are checked only for the files they name.** A variable or substitution that builds the name, a script that opens the file, a printing verb that is not on the list (`python -c`, `dd`, `perl`), `cd ../other && cat .env`, and a project's rule meeting a command run from another project pass (tests). See Layer 3. - **Commands are checked only for the files they name, in the forms the check reads.** Every form listed under Layer 3 has a test, as do the read gate's misses and the harmless commands it stops.
- **Secret files that cannot be masked, reached by a route that does not name them.** `.p12`, `.pfx`, `.netrc`, `.htpasswd` and a text `.key` are stopped when a Read names them, but `grep -r TOKEN .`, `ls -R` and `tar cf x.tar .` pass, and so does a printing command off the verb list (test). The read gate stands in a PreToolUse hook only: without PreToolUse wired, a Read of such a file reaches the model, and PostToolUse has nothing to mask in it (test). - **Secret files that cannot be masked, reached by a route that does not name them.** `.p12`, `.pfx`, `.netrc`, `.htpasswd` and a text `.key` are stopped when a Read, a Grep with that `path` or a printing command names them, but `grep -r TOKEN .`, `ls -R` and `tar cf x.tar .` pass, and so does a printing command off the verb list (test). A `~` in Grep's `path` is not expanded, so `path = "~/.ssh/id_rsa"` passes (test). The read gate stands in a PreToolUse hook only: without PreToolUse wired, a Read of such a file reaches the model, and PostToolUse has nothing to mask in it (test).
- **A template that holds a literal value.** Text with `{{` or `{%` that fails to parse passes a Read as a template, with a note that the file was skipped. A literal value in it reaches the model (test). - **A template that holds a literal value.** Text with `{{` or `{%` that fails to parse passes a Read as a template, with a note that the file was skipped. A literal value in it reaches the model (test).
- **A key file holding only certificate labels.** A `.pem` is judged by its armor labels: only `CERTIFICATE` and `PUBLIC KEY` blocks and it passes a Read and `cat`, whatever other text it holds, such as `API_TOKEN=x`, a lowercase `-----begin private key-----` or a raw key with no armor (test). Real PEMs carry text such as `Bag Attributes`, so a stricter check would stop those.
- **Files that cannot be parsed, reached by a route that does not name them.** A UTF-16 or Latin-1 `.env`, and JSON with comments, are stopped on a Read but their values are not masked in the output of other commands (test). A UTF-8 byte order mark is read, and does not count here. - **Files that cannot be parsed, reached by a route that does not name them.** A UTF-16 or Latin-1 `.env`, and JSON with comments, are stopped on a Read but their values are not masked in the output of other commands (test). A UTF-8 byte order mark is read, and does not count here.
- **A secret file outside the working project.** Values in `../other/.env` are not in the manifest, and a Read, a `cat ../other/.env` and `cd ../other && cat .env` pass (test). - **A secret file outside the working project.** Values in `../other/.env` are not in the manifest, and a Read, a `cat ../other/.env` and `cd ../other && cat .env` pass (test).
- **Values that never enter the manifest.** - **Values that never enter the manifest.**
- A key the key filter does not match, in a parsed file (test); a `.tfvars` heredoc (test); a comment in a TOML or YAML secret file (test). - A key the key filter does not match, in a parsed file (test); a `.tfvars` heredoc (test); a `*.tfvars` other than `terraform.tfvars` and `*.auto.tfvars` (test); a comment in a TOML or YAML secret file (test).
- The first value of a duplicate JSON key (test). - The first value of a duplicate JSON key (test).
- A `.env` value inside a quoted value that spans several lines, when a program prints it alone: with `API_TOKEN="abc` over a line `DB_PASSWORD=fake-pass` and a closing quote on a later line, `echo $DB_PASSWORD` prints the second value, which has no entry of its own (test). - A `.env` value inside a quoted value that spans several lines, when a program prints it alone: with `API_TOKEN="abc` over a line `DB_PASSWORD=fake-pass` and a closing quote on a later line, `echo $DB_PASSWORD` prints the second value, which has no entry of its own (test).
- Python triple quotes, on one line or over several (test), and shell-quoted spellings such as `'a'\''b-x` and `abc"def"-x`, when a program prints the decoded value (test). - Python triple quotes, on one line or over several (test), and shell-quoted spellings such as `'a'\''b-x` and `abc"def"-x`, when a program prints the decoded value (test).
- A number under 6 characters (test), and a secret number that an MCP tool returns as a JSON number (test). - A number under 6 characters (test), and a secret number that an MCP tool returns as a JSON number (test).
- A secret equal to a plain setting word (`true`, `3600`, a duration): it makes no entry. Values equal to a schema's fixed enum word are not masked in that field (test). - A secret equal to a plain setting word (`true`, `3600`, a short duration): it makes no entry. Values equal to a schema's fixed enum word are not masked in that field (test).
- **A short password's word is masked everywhere.** `DB_PASSWORD=postgres` masks `postgres` in every output, and an Edit that names such a line in source can fail (test). - **A short password's word is masked everywhere.** `DB_PASSWORD=postgres` masks `postgres` in every output (test). An Edit copied from such masked text fails, since Claude Code's Edit needs the real text (Claude Code's documentation).
- **Short lines of a multi-line value.** A line of fewer than 8 characters of a multi-line value passes when printed alone, by a grep or a line range (test). - **Short lines of a multi-line value.** A line of fewer than 8 characters of a multi-line value passes when printed alone, by a grep or a line range (test).
- **Monitor's output.** Each line of a Monitor's command goes to the model as an event, and PostToolUse only sees `{taskId, timeoutMs}`. `tail -f server.log` passes logged tokens straight through (Claude Code's documentation). `[policy.bash]` and the path rules apply to Monitor's and PowerShell's commands, with the limits above. A WebSocket Monitor (`ws`, no `command`) has no rule and no output: the hook leaves it alone. - **Monitor's output.** Each line of a Monitor's command goes to the model as an event, and PostToolUse only sees `{taskId, timeoutMs}`. `tail -f server.log` passes logged tokens straight through (Claude Code's documentation). `[policy.bash]` and the path rules apply to Monitor's and PowerShell's commands, with the limits above. A WebSocket Monitor (`ws`, no `command`) has no rule and no output: the hook leaves it alone.
- **A changed file's attachment.** After a Read, a file that changes on disk comes back to the model as an attachment with a snippet, which no tool call and no hook handles. Read `.env`, rotate the token, and the next turn carries the new value (Claude Code's bundle). `@`-mentions likely take the same route; that has not been traced. - **A changed file's attachment.** After a Read, a file that changes on disk comes back to the model as an attachment with a snippet, which no tool call and no hook handles. Read `.env`, rotate the token, and the next turn carries the new value (Claude Code's bundle). `@`-mentions likely take the same route; that has not been traced.
@@ -117,7 +128,7 @@ A value has one manifest entry per spelling, so that a file read and a program's
- each line of a multi-line value of 8 characters or more, for a Read with a line range, a grep or a diff. PEM and base64 lines have 64 or 76 characters; below 8 sit words of ordinary text (`end`, `prod`), and a line matches everywhere. PEM armor (`-----BEGIN ...`) and lines with no letter or digit are left out, since scripts and docs hold them too. So the last line of a key shorter than 8 characters passes when read away from the rest of it; - each line of a multi-line value of 8 characters or more, for a Read with a line range, a grep or a diff. PEM and base64 lines have 64 or 76 characters; below 8 sit words of ordinary text (`end`, `prod`), and a line matches everywhere. PEM armor (`-----BEGIN ...`) and lines with no letter or digit are left out, since scripts and docs hold them too. So the last line of a key shorter than 8 characters passes when read away from the rest of it;
- the text of a number in a JSON, TOML or YAML secret file, from 6 characters. Shorter numbers under a matching key are mostly settings (`CACHE_KEY_TTL = 3600`), and masking `3600` everywhere does more harm than a secret that short can suffer. A quoted value keeps the general minimum of 4. - the text of a number in a JSON, TOML or YAML secret file, from 6 characters. Shorter numbers under a matching key are mostly settings (`CACHE_KEY_TTL = 3600`), and masking `3600` everywhere does more harm than a secret that short can suffer. A quoted value keeps the general minimum of 4.
**Plain settings make no entry.** Before an entry is made, a value is dropped when it is a boolean or null word (`true false yes no on off null none nil enabled disabled`, any case, quoted or not), a number under 6 characters (`3600`, `0.5`) or a duration (`30s`, `15m`, `2d`). This holds for a `.env` too, and also for a key named in `keys.include` or a `[[file]]` override. Without such a naming, a value is also dropped when the key's last word (split at `.`, `_` or `-`) is a setting word: `ENABLED`, `TTL`, `TIMEOUT`, `LIMIT`, `MODE`, `PORT`, `HOST`, `POLICY`, `NAME`, `USER` and similar (the list is in `core/secrets/value_class.rs`). So `AUTH_ENABLED=true` and `API_TOKEN_TTL=604800` mask nothing, while `DB_PASSWORD=postgres` does, as it is no setting word. The built-in key pattern `*AUTH*` is three patterns (`*AUTH`, `*AUTH[!O]*`, `*AUTHORIZATION*`), so `AUTHOR`, `AUTHORITY` and `AUTHORIZED_*` no longer match; `exclude = ["*AUTH*"]` removes all three. **Plain settings make no entry.** Before an entry is made, a value is dropped when it is a boolean or null word (`true false yes no on off null none nil enabled disabled`, any case, quoted or not), a number or a duration under 6 characters (`3600`, `0.5`, `30s`, `15m`, `2d`). This holds for a `.env` too, and also for a key named in `keys.include` or a `[[file]]` override. Without such a naming, a value is also dropped when the key's last word (split at `.`, `_` or `-`) is a setting word: `ENABLED`, `TTL`, `TIMEOUT`, `LIMIT`, `MODE`, `PORT`, `HOST`, `POLICY`, `NAME`, `USER` and similar (the list is in `core/secrets/value_class.rs`). So `AUTH_ENABLED=true` and `API_TOKEN_TTL=604800` mask nothing, while `DB_PASSWORD=postgres` does, as it is no setting word. The built-in key pattern `*AUTH*` is three patterns (`*AUTH`, `*AUTH[!O]*`, `*AUTHORIZATION*`), so `AUTHOR`, `AUTHORITY` and `AUTHORIZED_*` no longer match; `exclude = ["*AUTH*"]` removes all three.
Overlapping matches become one mask, named after the longest. A multi-line value in a `.env` needs its closing quote at the end of a line. An opening quote without one is read as the plain value of that line, and the next assignment is still read. A closing quote that does come later swallows the assignments in between: see Known limits. Overlapping matches become one mask, named after the longest. A multi-line value in a `.env` needs its closing quote at the end of a line. An opening quote without one is read as the plain value of that line, and the next assignment is still read. A closing quote that does come later swallows the assignments in between: see Known limits.
+1 -1
View File
@@ -49,7 +49,7 @@ The agent runs a shell command that mentions a full path -- one containing a dir
> `cat /home/user/.env`, `type C:\Users\me\secret.toml` > `cat /home/user/.env`, `type C:\Users\me\secret.toml`
**Checked, by the verb.** The command is split into segments, and a word that holds a separator or names an existing file is checked against the path rules (and, for a printing verb such as `cat`, the read gate). A metadata verb (`ls`, `echo`, `git commit`) is not checked. Only the session's own project's rules apply to a command: a rule in another project, or a secret file in no project, does not. **Checked, by the verb.** The command is split into segments, and a word that names an existing file, an existing path with a separator or a path with `$`, `*` or `?` in it is checked against the path rules (and, for a printing verb such as `cat`, the read gate). A metadata verb (`ls`, `echo`, `git commit`) is not checked. Only the session's own project's rules apply to a command: a rule in another project, or a secret file in no project, does not.
### L2: Bare filenames resolvable in the working directory ### L2: Bare filenames resolvable in the working directory
+7 -2
View File
@@ -405,10 +405,15 @@ fn the_gate_refuses_when_rules_cannot_be_loaded_under_deny() {
assert!(deny_reason(&p.pre_read("safe.txt")).contains("rules")); assert!(deny_reason(&p.pre_read("safe.txt")).contains("rules"));
assert!(deny_reason(&p.pre_bash()).contains("rules")); assert!(deny_reason(&p.pre_bash()).contains("rules"));
// The control: the same rules with no `deny` stay open. // The same rules with no `deny` stay open for what no rule names, and the bad pattern
let p = project(&[(".botsecrets", bad_rules), ("safe.txt", "")]); // costs only itself: `.botignore` and the read gate still stand, and a note names it.
let p = project(&[(".botsecrets", bad_rules), (".botignore", "ignored.txt\n"), ("ignored.txt", ""), ("id_rsa", "fake key text\n"), ("safe.txt", "")]);
assert_silent(&p.pre_read("safe.txt")); assert_silent(&p.pre_read("safe.txt"));
assert_silent(&p.pre_bash()); assert_silent(&p.pre_bash());
assert!(deny_reason(&p.pre_read("ignored.txt")).contains(".botignore"));
assert!(deny_reason(&p.pre_read("id_rsa")).contains("id_rsa"));
let (out, _) = p.post(json!("clean"));
assert!(out["hookSpecificOutput"]["additionalContext"].as_str().unwrap().contains("a["), "{out}");
} }
#[test] #[test]