Files
fermata/docs/security-model.md
T
g4borg fe041051ca docs(fermata): the promises Known limits allows, and the limits named (I-2, N-3, N-4, M-4)
A failed command's output is stated as the largest limit: only a [policy.bash] deny stops
it, and only for the spelling it names. Monitor output and changed-file attachments added.
fermata is documented as no permission approver. Recovery from onFailure block.
2026-11-06 23:36:57 +01:00

16 KiB

fermata Security Model

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.

No AI coding agent ships built-in post-read secret filtering today. The entire industry relies on pre-read access controls -- block the file and hope the agent doesn't find the data through another path. This is insufficient.

The Reveal Triangle

Most security models think about secrets in terms of files: can the agent read this file? Can it write to it? fermata introduces a third dimension that traditional models miss entirely.

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? This is the novel concern. No traditional security model addresses it because the concept did not exist before AI agents. 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. An agent can have read access to .env without the secret values being revealed -- the output is redacted before it reaches the model. This is the default state, not a special configuration: the agent sees file structure, knows which keys exist, can reason about configuration, but never sees actual secret values.

The key insight is that Read and Write operate on file identity (which file). Reveal operates on data content (which values). The reveal problem can only be solved at the data-content level. File identity is necessary but not sufficient.

Defense in Depth

fermata implements a layered security stack. Layers 1 and 2 are the primary defense -- they operate on data content (the actual secret values). Layers 3 and 4 are supplementary -- they 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 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: 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.

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. It warns beside the output and does not mask.

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 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.

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 is provided by your container runtime, VM, or sandboxing tool. fermata's design assumes that structural containment exists as the outermost boundary, and focuses on the data-content layers (1 and 2) that containment cannot address.

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. 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.

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 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.

Harness-agnostic. fermata does not assume any specific AI coding agent. The policy engine is pure logic. Harness adapters are thin translation layers. The .botsecrets format works identically whether fermata runs as a hook script, an MCP proxy, or an in-process library.

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. This is the largest limit. 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 guard the Read tool, not 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. See the threat model.
  • 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. Booleans in a secret file are not secrets. A number in a secret file under 6 characters is not one either: see Spellings.
  • 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 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.

The format is harness-agnostic from day one. It declares what to protect, not how. The "how" is determined by the delivery mode -- hook script, MCP proxy, or library. This means the same .botsecrets works with Claude Code, Codex, Gemini CLI, Cursor, and any future tool that supports lifecycle hooks or MCP.

A typical .botsecrets looks like this:

# Declare files that contain secrets.
# fermata parses them, extracts the values, and redacts those values
# from all tool output before it reaches the model.

[files]
patterns = [".env", ".env.*", "config/credentials.toml", "secrets/*.yaml"]

[keys]
include = ["STRIPE_*", "MY_APP_SIGNING_*"]

[heuristic]
enabled = true

# Access control: write protection and bash safety.
# Reading secret-containing files is allowed -- Layer 1 redacts the values.

[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. The secret extraction, automaton construction, and output scanning happen automatically. Built-in key patterns (*_KEY, *_SECRET, *_PASSWORD, *_TOKEN, DATABASE_URL, etc.) handle most projects without custom [keys] configuration.

fermata is the reference implementation. The format is the standard -- fermata is one way to enforce it.