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
+2 -2
View File
@@ -29,7 +29,7 @@ fermata check [OPTIONS] <PATHS>...
|------|---------|
| 0 | Allowed (or Ask -- the agent may prompt the user) |
| 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.
@@ -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. |
| 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).
+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,
terraform.tfvars, *.auto.tfvars, terraform.tfstate, *.tfstate,
*.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
```
@@ -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) |
| `*.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 |
| `*.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 |
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).
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
[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
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
words that name an existing file or hold a path separator count; `$VAR`, `$(...)`,
scripts and a verb off the list that opens the file itself are not seen. `[policy.write]`
is not applied to commands.
a word that names an existing file, an existing path with a separator, a path with `$`,
`*` or `?` in it, or a redirect's target counts; `$(...)`, scripts and a verb off the
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.
- `*` 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.
- **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.
- **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.
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)
@@ -63,7 +73,7 @@ fermata does not own this layer. It would come from a container runtime, VM, or
## 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.
@@ -84,19 +94,20 @@ The PostToolUse hook redacts what Claude Code hands it and accepts back. These a
**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).
- **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.
- **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).
- **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, 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 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.
- **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.**
- 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).
- 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).
- 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 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 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 (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).
- **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.
@@ -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;
- 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.
+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`
**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