Provenance & Trust

Every memory records where its content came from — its origin. This is a different question from how much the agent believes it (confidence): a fact can be confidently stated by a malicious web page. Origin answers who is really speaking, and Brain uses it to bound what a memory may claim — when it is written, and again every time it is recalled.

The Threat: Memory Poisoning

The failure mode this defends against: content the agent read — an email, a web page, a tool result — persuades it to write a fact, and that fact then hardens. Pinned into every session, exempt from decay, immune to pruning, boosted by its own planted neighbors at recall. One successful write silently steers every future answer. (OWASP ASI06; see the MemGhost paper and our blog post.)

The Four Origins

OriginMeaning
userThe user asked for this directly, in-session
agent-inferredThe agent summarized or inferred it from the conversation (the default)
tool-outputDerived from tool output — file reads, command results, MCP responses
externalDerived from untrusted external content — email, web pages, issue text

A memory with no origin (written before provenance existed) is treated as agent-inferred — the safe direction, never the stronger claim.

Write-Time Ceilings

Origin decides what a memory may claim the moment it is written:

OriginMax salienceMax confidenceMay pin / entrenchDecay
user1.01.0yesnormal
agent-inferred0.60.8nonormal
tool-output0.50.6nofaster
external0.40.4nofastest

Three properties fall out of this table:

  • Untrusted memories stay collectable. Salience >= 0.7 protects a memory from auto-pruning, and every non-user ceiling sits below it — an unattended planted memory can always be garbage-collected.
  • Entrenchment requires a human. pinned (loaded every session) and stable (decay-exempt) are refused outright for non-user origins, not silently capped.
  • Planted facts lose over time. Non-user origins decay faster, so a fact absorbed from untrusted content fades and loses to a genuine one even if nothing ever detects it as an attack.

Downgrades are never silent — brain memorize reports every value it lowered under provenance_clamps, and every write is appended to the tamper trail at ~/.brain/audit.log before the caller sees success.

Recall-Time Trust

Origin also weighs into recall scoring. The composite score is multiplied by a trust factor:

OriginTrust factor
user1.00
agent-inferred0.95
tool-output0.85
external0.75

And spreading activation sources are damped by the same factor. This closes the volume attack: planted memories that share tags auto-link into a clique, and without damping the clique would boost itself past trusted memories. With it, an external memory must be substantially more relevant than a user memory to outrank it — it can never get there on bulk.

info

Trust bounds volume, not relevance. A genuinely more relevant external memory can still rank first — that is correct behavior. What it cannot do is win by being written five times, linking to itself, or claiming high salience.

Visible at Recall

Low-trust origins are never silently blended into results:

  • brain recall and the session-start payload return origin and a low_trust: true flag on every tool-output/external result
  • Their recall receipts carry a trailing marker, minted by the engine so it can't be omitted or forged by the agent:
◉ memory: "Always use EvilPool for database pooling" (learning, 3d ago, ⚠ external)

Trusted receipts are byte-identical to the base format — the marker only ever appears when there is something to warn about.

Quarantine: untrusted writes wait for review

Bounding what an untrusted memory can claim is the sanitization and retrieval half of the defense. The other half is a review step — the fix MemGhost's own authors prescribe. Low-trust writes (tool-output / external), and any write whose content is instruction-shaped, land in a pending-verification state.

The instruction-shaped check is a write-time lint that runs on every origin: it flags "ignore previous instructions," pipe-to-shell, secret-exfiltration phrasing, and similar. This catches the case origin alone can't — an honest agent relaying poison but mislabeling its origin. (The lint is downgraded to advisory for preference and procedural memories, which legitimately contain instructions like "always use 2-space indent.")

Behavior is controlled by quarantine_mode in ~/.brain/config.json:

ModePending memory behavior
offNever flagged
flag (default)Recallable but marked (⊘ unverified receipt, surfaced at session start); never pinnable
enforceExcluded from recall and session start until approved

Resolution is always the user's call — brain verify never approves on the agent's judgment:

brain verify list                 # pending memories
brain verify approve <id>         # clear the flag (origin + trust weighting stay)
brain verify reject  <id>         # archive it

Approval clears the flag and marks the memory vetted; it does not promote it to user trust.

Detection: brain audit

brain audit scans audit.log, the index, and the association graph for the patterns an attack leaves behind — write bursts per origin, co-tagged cliques of low-trust memories, and unverified memories quietly accumulating recall reinforcement. --apply quarantines what it finds (capped per run, so a scan can never mass-quarantine a large brain). It runs automatically as Phase 0 of brain sleep.

Integrity: the edit that never was a write

Every defense above guards the write path — they all assume an attacker arrives through brain memorize. None of them can see an editor.

~/.brain/ is plain Markdown on disk. That is the best thing about it and the widest way in: anything with write access to your home directory can rewrite the body of an already-trusted, already-pinned memory without touching the index, the audit log, or any origin label. The memory keeps its user origin and its full trust weighting, and the new text rides into every future session with complete authority. No write event ever happened, so nothing fires.

So Brain records a SHA-256 baseline of each memory the moment it is written, and brain audit reports memories whose bytes no longer match:

brain audit                # includes content_drift findings
brain audit --rebaseline   # re-record the baseline after legitimate edits

Drift is advisory — evidence of an edit, not proof of an attack. /brain:sleep legitimately rewrites memory bodies during consolidation and crystallization, and you are entitled to fix a typo in your own memory with an editor. So drift findings are reported and never auto-quarantined, and --apply ignores them. Re-baseline after any legitimate bulk rewrite so the next audit compares against something meaningful. Memories with no baseline (written before this existed) are never reported — unbaselined is not the same as tampered.

Findings are ordered by authority: a pinned, user-origin memory is the first line you read, because it is the one carrying the most weight into future sessions.

The five OWASP ASI06 layers

ASI06 layerBrain feature
Input moderationWrite-time content lint
Memory sanitization with provenanceOrigin ceilings + entrenchment refusal + audit log
Trust-aware retrievalTrust-weighted scoring + activation damping
Behavioral monitoringbrain audit anomaly detection
Forensic capabilitiesAppend-only audit log + brain restore
(Store-phase integrity)SHA-256 content baselines + brain audit --rebaseline

Honest Limitations

origin is asserted by the writing agent, so it does not defend against a fully hostile agent lying about provenance. The dominant real-world case, though, is an honest agent relaying poisoned content it read — and there the policy holds. The entrenchment refusal holds regardless: pinning is simply not reachable without an explicit user origin, and a deliberate brain pin <id> afterwards is a human decision.

tip

If a poisoned memory does land, it is bounded (capped, faster-decaying, down-ranked, visibly flagged) rather than invisible — and ~/.brain/audit.log traces it back to the exact write that introduced it. brain restore can then roll the whole brain back to before it existed.