From b9e8e527319a270e9cec9b29a578f61d9c1de567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabor=20K=C3=B6rber?= Date: Sat, 7 Nov 2026 09:48:21 +0100 Subject: [PATCH] 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. --- CLAUDE.md | 2 +- docs/configuration.md | 8 +++--- docs/known-failures.md | 14 ++++++----- docs/security-model.md | 2 +- tests/known_limits.rs | 57 ++++++++++++++++++++++++++++++++++-------- 5 files changed, 61 insertions(+), 22 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 408a1dc..403e070 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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. - **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. -- **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. - **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. diff --git a/docs/configuration.md b/docs/configuration.md index 3bcb21c..d2710a5 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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) | | `*.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 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 | 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 (`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 -`-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; 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 `$`, `*` 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 -first argument of `eval` are read as a command line, also behind a wrapper (`sudo bash -c`, +the list that opens the file itself are not seen. The line given to a shell's `-c` and to +`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 commands a rule stops, are in [Known failures](known-failures.md). diff --git a/docs/known-failures.md b/docs/known-failures.md index 62a4c15..957742d 100644 --- a/docs/known-failures.md +++ b/docs/known-failures.md @@ -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. - 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 < 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 -/// an indented attribute. A value spelled as one of them passes. +/// Text a certificate file may carry is let through: a comment, an indented line, `subject=`, +/// `issuer=`, a title above `====`, and whatever a block holds. A value spelled so passes. #[test] fn a_comment_or_an_attribute_line_beside_a_certificate_passes() { 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 p = project(&[("server.pem", content.as_bytes())]); assert!(passes(&p.read("server.pem")), "{extra}");