docs(fermata): true redaction promises, known limits, wiring for every tool
The hook matcher goes: Grep, Glob, WebFetch, Agent and MCP output needs the hook too. onFailure: block on PreToolUse (v2.1.295+) stops a tool when fermata cannot run. A new Known limits section lists what is not covered, including failed tools, whose text no hook can rewrite.
This commit is contained in:
+4
-6
@@ -75,14 +75,14 @@ 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 or the policy cannot be loaded, it writes `{}` to stdout (PreToolUse: an allow) and exits 0 so the agent can continue. Errors are reported on stderr and never quote a file.
|
||||
Fermata follows a **fail-open** policy for hooks: if the payload cannot be parsed or the policy cannot be loaded, it writes `{}` to stdout (PreToolUse: an allow) and exits 0 so the agent can continue. A tool PreToolUse has no rules for answers `{}` without a message. Errors are reported on stderr and never quote a file.
|
||||
|
||||
The exception is a project that sets `on_parse_error = "deny"`. If the config or a secret file cannot be loaded, `post-tool-use` replaces the tool output with a refusal naming the file; 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.
|
||||
The exception is `on_parse_error = "deny"`. 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).
|
||||
|
||||
**Event types**
|
||||
|
||||
- **pre-tool-use** -- Runs before the tool executes. Fermata checks the requested path or command against `.botsecrets [policy]` / `.botignore` and returns an allow, deny, or ask decision to the harness.
|
||||
- **post-tool-use** -- Runs after the tool executes. Fermata loads `.botsecrets`, builds a manifest of known secret values, and redacts any matches from the tool output before it enters the LLM context. A heuristic scanner (regex patterns derived from gitleaks) catches undeclared secrets as a safety net.
|
||||
- **post-tool-use** -- Runs after the tool executes. Fermata loads `.botsecrets`, builds a manifest of known secret values, and masks any matches in every string of the tool output, returning it in the same shape (`updatedToolOutput`), or `{}` if nothing changed. A secret where a built-in tool's schema cannot take a mask (an object key, a fixed field) refuses the whole output under every setting. A heuristic scanner (regex patterns derived from gitleaks) adds a warning beside the output (`additionalContext`) for undeclared secrets; it does not mask them.
|
||||
|
||||
**Examples**
|
||||
|
||||
@@ -164,15 +164,13 @@ Add both hook events to `.claude/settings.json`:
|
||||
"hooks": {
|
||||
"PreToolUse": [
|
||||
{
|
||||
"matcher": "Bash|Read|Edit|Write",
|
||||
"hooks": [
|
||||
{ "type": "command", "command": "fermata hook --harness claude" }
|
||||
{ "type": "command", "command": "fermata hook --harness claude", "onFailure": "block" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "Bash|Read|Edit|Write",
|
||||
"hooks": [
|
||||
{ "type": "command", "command": "fermata hook --harness claude --event post-tool-use" }
|
||||
]
|
||||
|
||||
@@ -126,7 +126,7 @@ style = "named"
|
||||
|
||||
### `[heuristic]` -- Heuristic Secret Scanning
|
||||
|
||||
In addition to known-value redaction, Fermata can scan all tool output for
|
||||
In addition to known-value redaction, Fermata can scan tool output for
|
||||
patterns that look like secrets (AWS keys, JWTs, GitHub PATs, high-entropy
|
||||
strings, database connection URLs). This catches secrets not covered by the
|
||||
`.botsecrets` manifest.
|
||||
@@ -141,8 +141,8 @@ Available modes:
|
||||
|
||||
| Mode | Behavior |
|
||||
|------|----------|
|
||||
| `enforce` | Redact heuristic matches from tool output. Default. |
|
||||
| `report` | Log findings but do not redact. |
|
||||
| `enforce` | Add a warning beside the output, naming the rules that matched. The match itself stays in the output: patterns have too many false positives to mask. Default. |
|
||||
| `report` | Log findings to stderr. The model sees nothing. |
|
||||
| `disabled` | Do not run heuristic scanning at all. |
|
||||
|
||||
```toml
|
||||
@@ -175,13 +175,13 @@ Parse error actions:
|
||||
|--------|----------|
|
||||
| `mask-entire-file` | Default. Warn on stderr and go on without that file's values: they are not redacted. Masking the whole file is not implemented. |
|
||||
| `allow` | Skip the unparseable file (secrets may leak). |
|
||||
| `deny` | The hooks refuse. PostToolUse replaces each tool output with a refusal naming the file, until it parses. |
|
||||
| `deny` | The hooks refuse. PostToolUse answers each tool output with a refusal naming the file, until it parses. See [Known limits](security-model.md#known-limits). |
|
||||
|
||||
Messages name the file and the line, never the line's text.
|
||||
|
||||
If the config itself cannot be read, the setting is unknown. Any layer with an uncommented line setting `deny` counts, even in a file that does not parse, and PreToolUse then refuses too. A layer whose bytes cannot be read counts as `deny`. Otherwise the hooks stay open.
|
||||
If the config itself cannot be read, the setting is unknown. Any layer with an uncommented line setting `deny` counts, even in a file that does not parse, and PreToolUse then refuses too. A layer whose bytes cannot be read says nothing, so it does not count. Otherwise the hooks stay open.
|
||||
|
||||
Editor files never refuse: a discovered `*.swp`, `*.swo`, `*.swn`, `*.swx` or `*~` that cannot be read or parsed is passed over under every setting. If it can be parsed, its values are still redacted. `.bak` and `.env.gpg` follow the setting, and so does anything named in `[[file]]`.
|
||||
Editor files never refuse: a discovered vim swap file (`*.swp`, then `*.swo` and on down to `*.swa`, and `*.swx`), Kate's `*.kate-swp` or a `*~` that cannot be read or parsed is passed over under every setting. If it can be parsed, its values are still redacted. `.bak` and `.env.gpg` follow the setting, and so does anything named in `[[file]]`.
|
||||
|
||||
```toml
|
||||
[enforcement]
|
||||
|
||||
+36
-7
@@ -30,23 +30,23 @@ fermata implements a layered security stack. Layers 1 and 2 are the primary defe
|
||||
|
||||
Parse secret-containing files at startup, extract actual secret values, build an Aho-Corasick automaton. Scan all tool output for those exact byte strings and replace them with redaction markers.
|
||||
|
||||
This is the primary defense layer. It catches secrets regardless of how they appear in output -- direct file reads, shell command output, log files, error messages. If the value `hunter2` is a declared secret, every occurrence in every tool output is redacted before it reaches the model.
|
||||
This is the primary defense layer. It catches secrets regardless of how they reached the output -- direct file reads, shell command output, log files. If the value `hunter2` is a declared secret, every occurrence in a string of a successful tool's output is redacted before it reaches the model.
|
||||
|
||||
**Guarantees**: Zero false negatives for declared secrets. Sub-millisecond per scan. The Aho-Corasick automaton finds all occurrences in a single linear pass over the output.
|
||||
**Guarantees**: Every occurrence of a declared value within a string is found, sub-millisecond per scan: the Aho-Corasick automaton finds all of them in a single linear pass. What reaches the scan has [known limits](#known-limits).
|
||||
|
||||
### Layer 2: Heuristic Detection (Scanner + gitleaks patterns)
|
||||
|
||||
Regex patterns for known secret formats: AWS access keys (`AKIA...`), GitHub PATs (`ghp_...`), JWTs (`eyJ...`), database URLs with embedded passwords, and dozens more derived from industry-standard pattern sets.
|
||||
|
||||
This is the safety net for secrets not covered by the manifest -- secrets in files that `.botsecrets` does not know about, secrets generated at runtime, secrets that appear in unexpected places.
|
||||
This is the safety net for secrets not covered by the manifest -- secrets in files that `.botsecrets` does not know about, secrets generated at runtime, secrets that appear in unexpected places. It warns beside the output and does not mask.
|
||||
|
||||
Higher false-positive rate than Layer 1, but as a secondary safety net, that tradeoff is acceptable.
|
||||
Its false-positive rate is higher than Layer 1's, which is why it warns: masking every high-entropy string would corrupt the output.
|
||||
|
||||
### Layer 3: Access Control (.botignore / .botsecrets [policy])
|
||||
|
||||
Block dangerous write operations and destructive commands. `Write .claude/settings.json` -- denied. `Bash: rm -rf /` -- denied. Uses gitignore-style patterns for write protection and command deny-lists for bash safety.
|
||||
|
||||
This layer is supplementary -- it protects against destructive writes and dangerous commands, not secret reads. Reading `.env` is allowed; the secret values never reach the model because Layer 1 redacts them. Write restrictions remain important for anti-jailbreak (preventing the agent from modifying its own hooks or policy files) and for protecting vendored or generated files.
|
||||
This layer is supplementary -- it protects against destructive writes and dangerous commands, not secret reads. Reading `.env` is allowed; the secret values do not reach the model because Layer 1 redacts them. Write restrictions remain important for anti-jailbreak (preventing the agent from modifying its own hooks or policy files) and for protecting vendored or generated files.
|
||||
|
||||
**Limitation**: Cannot catch indirect access to secret values. An agent running `source .env && echo $DB_PASSWORD` bypasses file-level controls entirely. This is exactly why access control is supplementary and redaction (Layer 1) is primary.
|
||||
|
||||
@@ -58,9 +58,9 @@ fermata does not own this layer. It is provided by your container runtime, VM, o
|
||||
|
||||
## Design Principles
|
||||
|
||||
**Fail-open for availability.** A parse error in `.botsecrets`, an unrecognized file format, or a scanner timeout does not block the agent from working. Redaction failures are logged, not fatal. The agent's productivity is not sacrificed for edge-case security failures. The exception is a project that sets `on_parse_error = "deny"`: there the hooks refuse instead.
|
||||
**Fail-open for availability.** A parse error in `.botsecrets`, an unrecognized file format, or a scanner timeout does not block the agent from working. Redaction failures are logged, not fatal. The agent's productivity is not sacrificed for edge-case security failures. The exception is `on_parse_error = "deny"`: there the hooks refuse instead.
|
||||
|
||||
**Zero false negatives for declared secrets.** If a value appears in the secret manifest (loaded from files matched by `.botsecrets`), it will be redacted from every tool output, every time. The Aho-Corasick automaton guarantees this -- it finds all occurrences in a single pass at memory-bandwidth speed.
|
||||
**No missed occurrence of a declared secret within a string.** If a value appears in the secret manifest (loaded from files matched by `.botsecrets`), it is redacted from every string of a successful tool's output, every time, or the output is refused. The Aho-Corasick automaton finds all occurrences in a single pass at memory-bandwidth speed. The [known limits](#known-limits) say what never reaches it.
|
||||
|
||||
**Sub-millisecond performance.** Hooks fire on every tool call. fermata must not introduce perceptible latency. Policy evaluation is a hashmap lookup. The Aho-Corasick scan runs at memory-bandwidth speed. Cold start (loading secrets + parsing files) takes roughly 10--20ms; subsequent calls are 1--3ms.
|
||||
|
||||
@@ -68,6 +68,35 @@ fermata does not own this layer. It is provided by your container runtime, VM, o
|
||||
|
||||
**Single policy file.** `.botsecrets` is the unified configuration interface. One file declares both what to redact (`[files]`, `[keys]`, `[heuristic]`) and what to restrict (`[policy]`). How protection is delivered is a deployment concern, not a configuration concern.
|
||||
|
||||
## Known limits
|
||||
|
||||
The PostToolUse hook redacts what Claude Code hands it and accepts back. These are the edges. They were read from Claude Code's documentation and the output schemas bundled in v2.1.314, and have not yet been checked in a live session.
|
||||
|
||||
**Covered:** a declared value that appears whole in any string of a successful tool's output, for every built-in tool and MCP tool, nested at any depth. The output comes back in the same shape, with only the values masked.
|
||||
|
||||
**Not covered:**
|
||||
|
||||
- **A tool that fails.** Claude Code sends a failed tool's text through `PostToolUseFailure`, whose hooks can only add a note. By its documentation 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. Fermata does not hook this event. Block reads of secret files with `[policy.read]` or `.botignore` where this matters.
|
||||
- **A value split across strings.** Each string is scanned on its own. A value divided between `stdout` and `stderr`, between two MCP content blocks, or across the lines of a diff (a multi-line value in `structuredPatch`) does not match.
|
||||
- **An encoded or altered value.** Base64, URL encoding, a reversed string or a value cut short does not match. See the [threat model](threat-model.md).
|
||||
- **Numbers and booleans.** Only strings are masked. A numeric secret in a JSON number passes.
|
||||
- **Binary data.** `base64` in a built-in's output, `data` beside `type: image`, `audio` or `base64`, and Bash's image `stdout` stay as they are. A mask there would break the image and the next API request, and a short value can match inside base64 by chance.
|
||||
- **Undeclared secrets.** The heuristic scanner warns beside the output, and leaves the match in place.
|
||||
- **A run outside a project.** With no `.botsecrets` or `.botignore` above the working directory, there is nothing to load and the output passes.
|
||||
|
||||
**Places a mask cannot go.** Claude Code validates a replacement for a built-in tool and, if it fails, uses the original output. So:
|
||||
|
||||
- A listed enum or literal value (`type: "text"`, `status: "completed"`, Bash's `gitOperation.commit.kind`) stays even if a secret equals it. It is one of the schema's fixed words and says nothing about the secret. `harness/claude.rs` holds the list.
|
||||
- A secret anywhere else in such a field, or in an object key of a built-in, replaces the whole output with a refusal, under every setting. A short or common secret such as `file` can therefore refuse every output whose fields contain that word. The refusal names the secret's key, so change the value or leave its file out of `[files]`. The exception is AskUserQuestion's answers, keyed by question text: those keys are masked.
|
||||
- An MCP tool's output has no schema. Its object keys are masked, and only a content block's `type` is kept.
|
||||
- A later Claude Code can add an enum this list does not know. A secret inside such a value would make Claude Code reject the mask and use the original, which it reports as a hook error.
|
||||
|
||||
**Refusals under `on_parse_error = "deny"`.** The secrets are unknown then, so nothing can be masked. Bash and Read answer with a minimal output holding the refusal. Other built-ins keep their shape: strings replaced, lists cut to one item, listed enum values, numbers and booleans kept, answer records emptied. Their keys and numbers pass through, since none of those schemas has other free-text keys. An MCP result becomes the refusal text.
|
||||
|
||||
**When the hook does not run.** `"onFailure": "block"` on PreToolUse (Claude Code v2.1.295 or later) stops the tool if `fermata` cannot start, fails or times out. Without it the call goes ahead. On PostToolUse a hook failure cannot hold anything back, because the tool already ran: a `fermata` that crashes only there lets that output through. So does a matcher that leaves a tool out.
|
||||
|
||||
**Consequences of a mask.** The agent sees `*****`, not the value. If it writes what it read back to a file, it writes the mask over the real value, and an Edit whose `old_string` holds the mask fails. Guard secret files with `[policy.write]`.
|
||||
|
||||
## The .botsecrets Vision
|
||||
|
||||
`.botsecrets` is designed to be the `.gitignore` of AI agent security: a simple, declarative, human-readable file that any project can drop in to protect its secrets from AI agents.
|
||||
|
||||
@@ -28,8 +28,8 @@ Fermata's detection operates on two independent tracks: **value-level redaction*
|
||||
|
||||
Independent of path-level detection, fermata filters tool output before it enters the LLM context:
|
||||
|
||||
- **Known-value redaction** -- `.botsecrets` declares which files contain secrets. Fermata parses those files, extracts the secret values, and replaces them in all tool output using an Aho-Corasick automaton. Sub-millisecond performance. Zero false negatives for declared secrets.
|
||||
- **Heuristic scanning** -- regex patterns (derived from gitleaks) detect undeclared secrets in tool output: AWS access keys, JWTs, GitHub PATs, database connection strings, and similar high-entropy tokens. This is a safety net for secrets not covered by the manifest.
|
||||
- **Known-value redaction** -- `.botsecrets` declares which files contain secrets. Fermata parses those files, extracts the secret values, and replaces them in every string of a successful tool's output using an Aho-Corasick automaton. Sub-millisecond performance. See [Known limits](security-model.md#known-limits).
|
||||
- **Heuristic scanning** -- regex patterns (derived from gitleaks) detect undeclared secrets in tool output: AWS access keys, JWTs, GitHub PATs, database connection strings, and similar high-entropy tokens. This is a safety net for secrets not covered by the manifest. It warns beside the output and does not mask them.
|
||||
|
||||
This is the layer that makes fermata's security model resilient. Even if every path-level check fails -- the agent reaches `.env` through a route fermata didn't parse -- the secret values themselves are scrubbed from the output before the LLM sees them.
|
||||
|
||||
@@ -111,7 +111,7 @@ This is not a failure -- it is a design boundary. Trying to solve L6 within a st
|
||||
|
||||
| Level | Description | Detection | Confidence |
|
||||
|-------|-------------|-----------|------------|
|
||||
| Secret redaction | Known-value + heuristic scanning | Aho-Corasick + regex | High (zero false negatives for declared secrets) |
|
||||
| Secret redaction | Known-value + heuristic scanning | Aho-Corasick + regex | High for declared secrets whole in a string |
|
||||
| L0 | Direct path argument | Full policy check | High |
|
||||
| L1 | Absolute path in Bash | Path extraction + policy | High |
|
||||
| L2 | Bare filename in CWD | CWD resolution + policy | Medium |
|
||||
@@ -130,7 +130,7 @@ Fermata is one layer in a defence-in-depth stack. Here is what it is good at and
|
||||
|
||||
### Fermata alone gives you
|
||||
|
||||
- **Known-secret scrubbing.** Declared secrets (via `.botsecrets`) are redacted from all tool output, always. The agent never "learns" the value, regardless of how it reached the file.
|
||||
- **Known-secret scrubbing.** Declared secrets (via `.botsecrets`) are redacted from the strings of successful tools' output, regardless of how they reached the file. A failed tool's error text is out of reach: see [Known limits](security-model.md#known-limits).
|
||||
- **Heuristic secret detection.** Undeclared secrets matching common formats (AWS keys, tokens, connection strings) are flagged in tool output. Built-in patterns handle most projects without any configuration.
|
||||
- **Command guardrails.** Dangerous shell patterns (`rm -rf /`, `curl | sh`) are caught by configurable deny lists.
|
||||
- **Write protection and access control.** Path-level checks (`.botignore`, `.botsecrets [policy]`) prevent unnecessary file access and unauthorised modifications at L0--L3.
|
||||
|
||||
Reference in New Issue
Block a user