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.
156 lines
7.0 KiB
Markdown
156 lines
7.0 KiB
Markdown
# fermata
|
|
|
|
**Do not use this software.**
|
|
|
|
> [!CAUTION]
|
|
> This is an experiment. It does not protect your secrets. Secrets can and do reach the model while it is installed. Do not rely on it. Do not install it on a real project.
|
|
|
|
## Known to fail
|
|
|
|
These failures were reproduced with fake values, through the fermata binary. The list is not complete.
|
|
|
|
- **Files on the default secret list are never read.** fermata only parses `.env`, TOML, JSON, YAML, Python and properties files. A Read of anything else on its default list reaches the model, even under `on_parse_error = "deny"`: `terraform.tfstate`, `*.tfstate`, `terraform.tfvars`, `*.auto.tfvars`, `.aws/credentials`, `.netrc`, `.htpasswd`, `*.pem`, `*.key`, `id_rsa`, `id_ed25519`, `id_ecdsa`. `*.p12` and `*.pfx` take the same path.
|
|
- **Many values never enter the list of known secrets.** A commented `.env` line, a symlinked `.env`, a multi-document YAML file, `secrets.py` with a trailing comment or a triple-quoted value, `.env` values with shell quoting inside them, the first value of a duplicate JSON key, a value swallowed by an unclosed quote, a file that cannot be parsed, a secret file outside the working project.
|
|
- **Ordinary config values get masked everywhere, and this can corrupt source.** With `AUTH_ENABLED=true` and `TOKEN_TTL=3600` in `.env`, every `true` and `3600` in every output becomes `*****`. An agent that reads the mask from a source file and writes the file back puts the mask into your code.
|
|
- **`cat .env; false` is unprotected.** According to Claude Code's documentation and bundled code, a failed tool's output goes down a path no hook can rewrite. A `[policy.bash]` deny pattern stops only the spelling it names.
|
|
- **Commands are not checked against path rules.** `.botignore` and `[policy.read]` do not stop `cat .env` in Bash.
|
|
- **A directory pattern in `.botignore` does not match the files below it.** `vendor/` lets a write to `vendor/a` through. `vendor/**` stops it. A relative path never matches `.botignore`.
|
|
|
|
The fuller list: [docs/security-model.md](docs/security-model.md#known-limits). The test suite never runs Claude Code.
|
|
|
|
## What it tries to do
|
|
|
|
AI coding agents read files and run commands, and what they read enters the model's context. The experiment asks whether a tool's output could be filtered before the model sees it, so that an agent could see which keys `.env` holds without seeing their values.
|
|
|
|
fermata runs in hooks around an agent's tool calls:
|
|
|
|
```
|
|
Agent wants to run a tool
|
|
|
|
|
PreToolUse ── .botsecrets [policy] / .botignore
|
|
| a rule matches? → deny or ask
|
|
| otherwise → no answer: Claude Code's permissions decide
|
|
|
|
|
Tool executes
|
|
|
|
|
PostToolUse ── .botsecrets [files] + [keys] + [heuristic]
|
|
| values it parsed? → masked
|
|
| known formats? → a warning, the value stays
|
|
|
|
|
Output enters LLM context, with whatever was missed
|
|
```
|
|
|
|
| Part | Mechanism | What it does |
|
|
|------|-----------|--------------|
|
|
| Known-value masking | `.botsecrets` names secret files; fermata parses those it has a parser for and builds an Aho-Corasick automaton | Masks a value from the manifest in a string of a successful tool's output |
|
|
| Heuristic scan | Regex patterns from gitleaks (AWS keys, JWTs, GitHub PATs, database URLs) | Warns beside the output and masks nothing |
|
|
| Rules | `.botsecrets [policy]` / `.botignore` | Stops the Read, Write and Edit tools on matching paths, and commands whose text matches. No rules, nothing stopped |
|
|
|
|
Each call parses the secret files again. That takes milliseconds for a small file and about 23 s at 1.7 MB. A hook that times out lets the original output through.
|
|
|
|
fermata is no sandbox: see [docs/threat-model.md](docs/threat-model.md).
|
|
|
|
## Trying the experiment
|
|
|
|
Use a throwaway project and fake secrets.
|
|
|
|
```bash
|
|
cargo install --path . --features cli
|
|
```
|
|
|
|
```toml
|
|
# .botsecrets
|
|
[files]
|
|
patterns = [".env", ".env.*", "secrets.*"]
|
|
|
|
[keys]
|
|
include = ["STRIPE_*", "MY_APP_SIGNING_*"]
|
|
|
|
[policy.write]
|
|
patterns = [".claude/**", "vendor/**", "*.lock"]
|
|
|
|
[policy.bash]
|
|
deny = ["rm -rf /", "curl * | sh"]
|
|
```
|
|
|
|
`fermata.toml` is accepted as another name for `.botsecrets`, which wins when both exist. An optional `.botignore` uses gitignore syntax for the Read, Write and Edit tools. See [docs/configuration.md](docs/configuration.md).
|
|
|
|
Add both hooks to `.claude/settings.json`:
|
|
|
|
```json
|
|
{
|
|
"hooks": {
|
|
"PreToolUse": [
|
|
{
|
|
"hooks": [
|
|
{ "type": "command", "command": "fermata hook --harness claude", "onFailure": "block" }
|
|
]
|
|
}
|
|
],
|
|
"PostToolUse": [
|
|
{
|
|
"hooks": [
|
|
{ "type": "command", "command": "fermata hook --harness claude --event post-tool-use" }
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
```
|
|
|
|
PreToolUse is no permission approver: when no rule stops a call it answers nothing, and Claude Code's own prompts stay.
|
|
|
|
Leave out `matcher`: a matcher that omits a tool leaves that tool's output unfiltered.
|
|
|
|
`"onFailure": "block"` (Claude Code v2.1.295 or later; older versions ignore it) stops a tool call when the hook cannot run. Without it Claude Code carries out the call and the output passes unfiltered. On PostToolUse it can hold nothing back, because the tool has already run. With it, a teammate without `fermata` on `PATH` is blocked at every tool 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"`.
|
|
|
|
## Commands
|
|
|
|
```bash
|
|
# Check a path against the rules
|
|
fermata check --op read /path/to/.env # exit 1 = a rule denies it
|
|
fermata check --op write /path/to/src/main.rs # exit 0 = no rule denies it
|
|
|
|
# Run as a hook (reads harness JSON from stdin)
|
|
fermata hook --harness claude
|
|
fermata hook --harness claude --event post-tool-use
|
|
```
|
|
|
|
See [docs/commands.md](docs/commands.md).
|
|
|
|
## Library API
|
|
|
|
```rust
|
|
use std::path::Path;
|
|
use dirigent_fermata::core::secrets::{Manifest, Redactor, Scanner, SecretsConfig};
|
|
|
|
let root = Path::new("/path/to/project");
|
|
let config = SecretsConfig::load(root)?;
|
|
let manifest = Manifest::build(&config, root)?;
|
|
|
|
let redactor = Redactor::new(&manifest, config.redaction.style);
|
|
let clean = redactor.redact("DB_PASSWORD=hunter2");
|
|
// clean.text holds the masked text, if hunter2 made it into the manifest
|
|
|
|
let scanner = Scanner::new(&config.heuristic)?;
|
|
let findings = scanner.scan("Found key: AKIA1234567890ABCDEF");
|
|
```
|
|
|
|
## Harness support
|
|
|
|
| Harness | Status | Mechanism |
|
|
|---------|--------|-----------|
|
|
| Claude Code | Exists, fails as listed above | PreToolUse and PostToolUse hooks |
|
|
| Codex CLI | Not built | Pre-exec hook adapter |
|
|
| Gemini CLI | Not built | MCP server mode |
|
|
| Any MCP agent | Not built | MCP proxy |
|
|
|
|
## Background
|
|
|
|
- [docs/security-model.md](docs/security-model.md): the idea of "reveal", as distinct from read and write, the design, and the known limits
|
|
- [docs/threat-model.md](docs/threat-model.md): what fermata tries to catch and where it stops
|
|
|
|
## License
|
|
|
|
Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or [MIT License](LICENSE-MIT) at your option.
|