Files
fermata/docs/threat-model.md
T
g4borg 999ed6ba4e docs(fermata): known limits, config reference and READMEs say what the tests show
Known to fail holds only what known_limits.rs pins or Claude Code's docs state;
the multi-line quoted value gets its own limit test. configuration.md follows the
code (unknown fields, [enforcement] settings, marks, plain settings, verb classes)
and every TOML example of it is loaded by tests/docs_toml_examples.rs. Speed
numbers are measured with a release build. matrix.md notes the new refusals.
2026-11-07 01:38:19 +01:00

136 lines
9.8 KiB
Markdown

# Fermata Threat 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](security-model.md#known-limits) for where it fails.
What fermata tries to catch, and where it stops.
---
## Framing: an experiment, not a sandbox
Fermata does nothing against a deliberate, optimising adversary trying to escape the box. The experiment looks at:
- **Statistical agent behaviour** -- the playbook of moves an LLM-driven coding agent reaches for when solving a class of tasks, including its mistakes: overly-broad globs, "let me just `cat` everything", picking up a stray `.env` because it pattern-matched the rest of the directory.
- **Non-malicious harnesses** -- Claude Code, Codex, Gemini and similar agents that are not actively trying to circumvent policy.
- **Prompt-driven mistakes** -- the user's prompt or a tool's output nudges the model into touching something it shouldn't, without anyone meaning to.
This shifts the design centre from "what can a smart attacker hide?" to "what does an unguided LLM commonly do, and how do we catch the dangerous fraction of that?" Static analysis becomes tractable when grounded in **what is usual**, not what is adversarially possible.
Most of what fermata tries rests on **value masking**, not on path checks. When a command reaches a file no rule looks at, a value in the manifest can still be masked in the output of a tool that succeeds. Many values never reach the manifest: see [Known limits](security-model.md#known-limits).
---
## What fermata tries to catch
Fermata works on two independent tracks: **value-level masking** and **rules for tool calls**.
### Secret masking (PostToolUse)
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 that it has a parser for, extracts the secret values, and replaces them in every string of a successful tool's output using an Aho-Corasick automaton. 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 tokens. It warns beside the output and does not mask them, so they reach the model.
### Rules for tool calls (PreToolUse)
The levels below are organised by how the agent names the path it is about to access. Lower levels are easier to detect statically; higher levels require progressively more runtime information.
### L0: Direct path arguments
The agent calls a path-typed tool (Read, Write, Edit, MultiEdit, or Grep with a `path`) with an explicit file path.
> `Read({"file_path": "/home/user/.env"})` -- `.botignore` matches -- deny.
Both `.botignore` (deepest directory wins, negation patterns work as in git) and `.botsecrets [policy]` rules are evaluated against the path, relative or absolute, and against the path as the file system resolves it. A `.botignore` directory pattern such as `vendor/` matches the files below it, as in git. A Read of a listed secret file that fermata cannot mask (no parser, a secret as a whole, unparseable) is stopped too, whatever the rules say, and a Write or Edit that adds a mask to a file is stopped.
### L1: Absolute paths inside Bash commands
The agent runs a shell command that mentions a full path -- one containing a directory separator or drive letter.
> `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.
### L2: Bare filenames resolvable in the working directory
The agent names a file without any path separator, relying on the shell's working directory to resolve it.
> `cat .env`, `cat README.md`
**Checked**, as in L1, when the word names an existing file in the session's working directory. `cd ../other && cat .env` is not: the `cd` is not followed.
### L3: Static wildcards in commands
The agent uses shell glob patterns in a command that could expand to match sensitive files.
> `cat .env*`, `grep SECRET *.toml`, `find . -name '*.pem'`
**Checked.** A glob is matched against the entries of its one directory, and a dotfile matches only when the glob starts with `.`, as in a shell: `cat .env*` is checked and `cat *` does not reach `.env`. `find` is a verb whose `-name` pattern is read as a glob.
---
## What fermata does NOT catch
### L4: Shell indirection
Variable expansion (`cat $SECRET_FILE`), command substitution (`cat $(ls .env*)`), tool composition (`xargs cat < file_list`), and pipelines that route content through intermediate steps.
A real `bash` parser would handle the syntax, but cannot resolve runtime values. Fermata sees the command string, not the expanded result. A variable assigned in the same command with the file name in it (`F=.env; cat $F`) is seen, since the name is in the text; one built apart from the name (`cat $(printf '.e%s' nv)`), `"$(cat .env)"` and a script that opens the file are not. Neither is a printing verb off the list (`python -c`, `dd`, `perl`).
### L5: Derived or out-of-band names
The agent computes a path from sources fermata never sees: its own reasoning, an HTTP response, a previous tool's stdout that the harness reused as input.
> The agent reads a config file, learns about `/etc/app/signing.key`, then reads it in a subsequent call.
**Important:** most derived-name scenarios collapse back to L0 at the moment of the dangerous call. If the second read is a direct path-typed tool call, a `.botignore` rule that matches stops it. If it is a shell command, it is checked only for the files it names.
### L6: Application-protocol exfiltration -- out of scope by design
The agent uses a legitimate tool (HTTP client, git push, shell with network access) to move forbidden content to a destination fermata cannot inspect. The content travels as the *payload* of an allowed call, not as a path.
> The agent reads a secret (masked at L0), but then reconstructs it character-by-character and sends it via an HTTP request.
This is the network-firewall analogy: **you cannot block exfiltration over an allowed application protocol from outside the application.** A packet filter cannot inspect encrypted traffic without MITM; a static rule check cannot inspect the semantic intent of an allowed tool's payload. Fermata does not try this.
---
## Coverage summary
| Level | Description | Detection | Confidence |
|-------|-------------|-----------|------------|
| Secret masking | Known-value masking + heuristic warning | Aho-Corasick + regex | Only for values in the manifest, whole in a string of a successful tool. See [Known limits](security-model.md#known-limits) |
| L0 | Direct path argument | Policy check on Read, Write, Edit, Grep with a path; read gate; write guard | Only if a rule matches, a listed file cannot be masked, or a Write adds a mask |
| L1 | Absolute path in Bash | Path rules and read gate, by the verb | Only for a path a rule or the gate covers, and a verb on the lists |
| L2 | Bare filename in CWD | The same, in the session's directory | The same; `cd` elsewhere is not followed |
| L3 | Wildcards in commands | The same, with the glob matched in its directory | The same |
| L4 | Shell indirection | None | None for a name built apart from the file |
| L5 | Derived names | L0 if the final call is a path tool | Depends on final call |
| L6 | Protocol exfiltration | Out of scope | N/A |
---
## Practical implications
Do not use fermata on a real project. If you try it anyway, this is what it attempts.
### What fermata attempts
- **Masking known secrets.** Values in the manifest are masked in the strings of successful tools' output. A failed tool's error text is out of reach, and many values never enter the manifest: see [Known limits](security-model.md#known-limits).
- **Heuristic warnings.** Undeclared secrets matching common formats (AWS keys, tokens, connection strings) get a warning beside the output, and stay in it.
- **Command rules.** Shell patterns you list (`rm -rf /`, `curl * | sh`) stop a command whose text matches.
- **Path rules.** `.botignore` and `.botsecrets [policy]` stop the Read, Write and Edit tools at L0, and commands that name a matching file at L1 to L3.
- **The read gate and the write guard.** A Read of a listed file that cannot be masked is stopped, and so is a Write that adds a mask.
### What real secrets would need instead
- **Network-level controls** for L6 scenarios. If your threat model includes data exfiltration by a compromised or misbehaving agent, restrict outbound network access at the OS or container level. Fermata cannot inspect what an HTTP client sends.
- **Sandboxing / containerisation** for hard isolation. Fermata is not a sandbox. For filesystem isolation, run the agent in a container with a restricted mount, and do not mount secrets into it.
- **Secret rotation.** If a real secret was in a project with an agent, assume it reached the model and rotate it.
### Design constraints worth knowing
- **Latency.** Fermata fires on every tool call and parses the secret files each time, which grows with the size of the files: see [Speed](security-model.md#design-principles).
- **No writes.** The hook reads its config and the secret files, walks the project for them, and writes no files.
- **False deny vs false allow.** A false deny breaks the agent's workflow and is noticed immediately. A false allow may go undetected.