Files
fermata/docs/security-model.md
T
g4borg 47da98709f docs(fermata): do not use; an experiment, with what it is known to fail at
The public README, crate README, docs, SVGs, crate description and --help no
longer present fermata as protection. The README opens with a warning and a
"Known to fail" list from recheck-2, each item reproduced on this code.

The docs also said things the code does not do: the hook never checks a Bash
command against path rules (threat model L1 to L4), [enforcement] mode has no
effect, [policy.read] takes patterns and not deny, a .botignore directory
pattern misses the files below it, and a relative path never matches.
2026-11-06 23:48:18 +01:00

151 lines
16 KiB
Markdown

# fermata Security Model
> **Do not use this software.** fermata is an experiment. It does not protect your secrets, and secrets can and do reach the model while it is installed. This document describes what fermata tries to do. See [Known limits](#known-limits) for where it fails.
## The Problem
AI coding agents see secrets. Not because they try to -- because secrets are everywhere in a working codebase, and agents read files, run commands, and inspect output as part of their normal workflow.
When an agent reads `.env`, the secret values get tokenized into the LLM's context window. Once there, they can leak into commits, PR descriptions, log messages, or API calls the agent makes. The secret is irrecoverably revealed.
Blocking a file before the read leaves other paths to the same data open. This experiment looks at filtering the output instead.
## The Reveal Triangle
Most security models think about secrets in terms of *files*: can the agent read this file? Can it write to it? This experiment looks at a third dimension.
**Read** -- Can the agent open a file? Handled by policy rules and file access controls. A blunt instrument: blocking `.env` also blocks legitimate tooling that needs configuration values. In fermata's model, read access to secret-containing files is *allowed by default* -- the agent needs to see file structure and key names to reason about configuration.
**Write** -- Can the agent modify a file? Less concerning than it appears, because version control provides full recovery. Write restrictions matter primarily for anti-jailbreak (preventing the agent from modifying its own hooks or policy files).
**Reveal** -- Do secret *values* enter the LLM context? A file read that configures a database is not a security event. The same file read that feeds credentials to an LLM *is*.
These three dimensions are independent. In theory an agent could have read access to `.env` without the secret values being revealed, if the output were masked before it reached the model. The agent would see file structure and key names and not the values. fermata tries this and does not achieve it reliably: see [Known limits](#known-limits).
The key insight is that Read and Write operate on file identity (*which file*). Reveal operates on data content (*which values*). File identity alone does not answer the reveal question.
## Layers
The design has four layers. Layers 1 and 2 operate on data content (the actual secret values). Layers 3 and 4 operate on file and system identity.
### Layer 1: Known-Value Redaction (.botsecrets + Aho-Corasick)
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 layer looks at values, not at how they reached the output: file reads, shell command output, log files. If the value `hunter2` made it into the manifest, every occurrence in a string of a successful tool's output is masked: the Aho-Corasick automaton finds all of them in a single linear pass. Many values never reach the manifest, and much output never reaches the scan: see [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 looks for secrets not covered by the manifest. It warns beside the output and does not mask, so the value still reaches the model.
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])
Stop the tool calls your rules name. 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. Path patterns apply to the Read, Write and Edit tools, and command patterns match the text of a command.
Reading `.env` is allowed by default, and only Layer 1 stands between its values and the model.
**Limitation**: Commands are not checked against path rules. `cat .env` and `source .env && echo $DB_PASSWORD` pass this layer, whatever `.botignore` and `[policy.read]` say. A `.botignore` directory pattern such as `vendor/` does not match the files below it; `vendor/**` does. A relative path never matches `.botignore`.
### Layer 4: Structural Containment (External)
Container-level isolation, filesystem restrictions, dropped capabilities, no-new-privileges. Prevents system modification, privilege escalation, and escape from the execution environment. This layer has no concept of secret values -- it operates on structural boundaries.
fermata does not own this layer. It would come from a container runtime, VM, or sandboxing tool.
## Design Principles
**Fail-open by default.** A parse error in `.botsecrets` or in a secret file does not block the agent from working, and the values of that file then reach the model. An unrecognized file format is passed over without a word, also under `deny`. Two exceptions: under `on_parse_error = "deny"` the hooks refuse instead, and under `"onFailure": "block"` on PreToolUse a `fermata` that cannot run stops every tool.
**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.
**Every occurrence of a value in the manifest.** If a value made it into the secret manifest (loaded from files matched by `.botsecrets`), it is masked in every string of a successful tool's output, or the output is refused. The [known limits](#known-limits) say what never reaches the manifest or the scan.
**Speed.** Hooks fire on every tool call, and each call loads the config and parses the secret files again. For a small secret file that takes milliseconds. It grows quadratically with the file: 0.6 s for an 81 KB JSON file, 23 s at 1.7 MB, over 300 s at 6.9 MB. A hook that times out lets the original output through.
**Harness adapters.** The policy engine knows no specific AI coding agent, and an adapter translates for one harness. Only the Claude Code adapter exists. There is a hook script and an in-process library, and no MCP proxy.
**Single policy file.** `.botsecrets` is the unified configuration interface. One file declares both what to redact (`[files]`, `[keys]`, `[heuristic]`) and what to restrict (`[policy]`).
## 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 value in the manifest 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. This is a narrow promise: the list below is long and not complete.
**Not covered:**
- **Files on the default list that are never parsed.** `terraform.tfstate`, `*.tfstate`, `terraform.tfvars`, `*.auto.tfvars`, `.aws/credentials`, `.netrc`, `.htpasswd`, `*.pem`, `*.key`, `id_rsa`, `id_ed25519`, `id_ecdsa`, `*.p12` and `*.pfx` have no parser. A Read of one reaches the model under every setting, and `deny` refuses nothing, since this is no parse failure. Some of them get a heuristic warning beside the value.
- **Values that never enter the manifest.** A commented `.env` line (`#API_TOKEN=old-prod-value`). A `.env` that is a symlink. A multi-document YAML file: by default the whole file is skipped with a line on stderr, and under `deny` every output is refused for a valid file. `secrets.py` with `SECRET_KEY = "x" # prod` or a triple-quoted value over lines. `.env` values with quoting inside them (`'a'\''b-x'`, `abc"def"-x`), when a program prints the decoded value. The first value of a duplicate JSON key. A `.env` value swallowed by an unclosed quote above it. A secret file outside the working project, such as a Read of `../other/.env`.
- **Files that cannot be parsed.** By default a BOM or a comment in JSON, or a Latin-1 or UTF-16 `.env`, skips the file with only a line on stderr. Neither the model nor the user sees more.
- **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. Fermata does not hook this event and cannot rewrite it. Only a `[policy.bash] deny` pattern stops such a command, and only for the spelling it names: a deny on `cat .env` stops `cat .env; false` but not `cat ./.env; false`, `env; false` or `grep -r TOKEN .; false`. `[policy.read]` and `.botignore` apply to the Read tool, not to what a command prints.
- **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. `[policy.bash]` applies to Monitor's and PowerShell's commands, with the same spelling limit.
- **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. `@`-mentions likely take the same route; that has not been traced.
- **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. Spellings the value has in its own file are known: see [Spellings](#spellings). See the [threat model](threat-model.md).
- **Numbers and booleans in the output.** Only strings are masked. A secret number that a tool returns as a JSON number passes, as text it is masked. In a JSON, TOML or YAML secret file booleans are not treated as secrets, and neither is a number under 6 characters: see [Spellings](#spellings). In a `.env` they are: see the next item.
- **Ordinary words get masked.** A `.env` value keeps the general minimum of 4 characters, whatever it holds. With `AUTH_ENABLED=true` and `TOKEN_TTL=3600` every `true` and `3600` in every output becomes a mask, and `*AUTH*` also matches `AUTHOR`. An agent that reads `enabled: *****` from a source file and writes the file back puts the mask into the source.
- **Binary data.** `base64` in a built-in's output, `data` of 64 or more base64 characters beside `type: image`, `audio` or `base64` in a content block at the top of a result, 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.
### Spellings
A value has one manifest entry per spelling, so that a file read and a program's output both match:
- the decoded text, and the text as the file holds it (`\n` in a JSON string, a YAML block with its indentation, a TOML `\t`, a continued `.properties` line);
- its JSON-escaped form and its `\n`-escaped form, with and without the trailing line end;
- 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 or a `.env` value keeps the general minimum of 4.
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.
**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.
- Fields of the Artifact tool's schema with a pattern (hashes, ids, versions, addresses) or an enum built at run time (`reason`) cannot be listed. A secret in one refuses the output.
- Two things stay unknown, and a secret inside either would make Claude Code reject the mask and use the original, which it reports as a hook error: a later Claude Code's new enum, and flag-gated fields whose values only exist at run time (`RUN_OP_STATUS` and `runOpOutputFields` of Workflow, the `handlers` arms of Artifact).
**Refusals under `on_parse_error = "deny"`.** The secrets are unknown then, so nothing can be masked. Bash, Read and Artifact 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. With it every tool stops, so the agent cannot repair this itself. A teammate without `fermata` on `PATH` is blocked by a committed `.claude/settings.json`, so per-user installs belong in `.claude/settings.local.json`. To recover, edit the settings by hand or set `"continue"`. 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 format
`.botsecrets` is a TOML file. It says which files to parse and which rules to apply, and nothing in it is specific to a harness. fermata reads it for Claude Code only.
A typical `.botsecrets` looks like this:
```toml
# Declare files that contain secrets.
# fermata parses them, extracts the values, and redacts those values
# from tool output, as far as it can.
[files]
patterns = [".env", ".env.*", "config/credentials.toml", "secrets/*.yaml"]
[keys]
include = ["STRIPE_*", "MY_APP_SIGNING_*"]
[heuristic]
enabled = true
# Rules for writes and commands.
# Reading secret-containing files is allowed.
[policy.write]
patterns = [".claude/**", "vendor/**", "*.lock"]
[policy.bash]
deny = ["rm -rf /", "curl * | sh"]
```
No secret values appear in `.botsecrets` itself. It points to the files that contain them. Built-in key patterns (`*PASSWORD*`, `*SECRET*`, `*API_KEY*`, `*TOKEN*`, `DATABASE_URL`, etc.) decide which values count unless `[keys]` adds more.