|
| 1 | +--- |
| 2 | +title: "The Credential Leak" |
| 3 | +description: An AI agent almost prints API keys to a recorded terminal session. Institutional memory blocks it. |
| 4 | +--- |
| 5 | + |
| 6 | +# The Credential Leak |
| 7 | + |
| 8 | +An agent needs to check whether environment variables are configured. The fastest way? `echo $API_KEY`. But in a recorded session, that value is now permanently stored — in transcripts, recordings, and conversation history. This is the kind of mistake that's invisible until it's catastrophic. |
| 9 | + |
| 10 | +## The Situation |
| 11 | + |
| 12 | +An agent was setting up a deployment pipeline inside a container. It needed to verify that three API keys were available before proceeding: |
| 13 | + |
| 14 | +```bash |
| 15 | +# The agent's first instinct |
| 16 | +echo $PAYMENT_API_KEY |
| 17 | +echo $STORAGE_SECRET |
| 18 | +echo $AUTH_TOKEN |
| 19 | +``` |
| 20 | + |
| 21 | +This would work — the values would print, the agent would confirm they exist, and the deployment would proceed. But the session was being recorded. Every command and its output was captured in: |
| 22 | + |
| 23 | +1. A session transcript stored in a database |
| 24 | +2. An asciinema recording (`.cast` file) synced to shared storage |
| 25 | +3. The conversation history persisted across sessions |
| 26 | + |
| 27 | +If those `echo` commands ran, the actual secret values would be permanently embedded in at least three storage systems. Rotating the keys wouldn't help — the old values would still exist in historical records. |
| 28 | + |
| 29 | +The correct approach uses existence checks that never expose values: |
| 30 | + |
| 31 | +```bash |
| 32 | +# Safe: only checks if the variable is set |
| 33 | +[ -n "$PAYMENT_API_KEY" ] && echo "SET" || echo "MISSING" |
| 34 | +[ -n "$STORAGE_SECRET" ] && echo "SET" || echo "MISSING" |
| 35 | +[ -n "$AUTH_TOKEN" ] && echo "SET" || echo "MISSING" |
| 36 | +``` |
| 37 | + |
| 38 | +## The Scar |
| 39 | + |
| 40 | +After a near-miss where an agent almost printed credentials during a debugging session, this scar was created: |
| 41 | + |
| 42 | +```json |
| 43 | +{ |
| 44 | + "learning_type": "scar", |
| 45 | + "title": "Never print environment variable VALUES — only check existence", |
| 46 | + "description": "When checking if environment variables exist, NEVER run commands that output the actual values (e.g., echo $SECRET, env | grep KEY). Secret values will be captured in session recordings, transcripts, and conversation history. Instead, check existence only: test with [ -n \"$VAR\" ] && echo \"SET\" || echo \"MISSING\".", |
| 47 | + "severity": "critical", |
| 48 | + "scar_type": "incident", |
| 49 | + "counter_arguments": [ |
| 50 | + "You might think showing a prefix is safe — but partial keys are still sensitive and the full value is in the raw output before truncation", |
| 51 | + "You might think CLI sessions are ephemeral — but recordings and transcripts persist them permanently", |
| 52 | + "You might think it's fine because it's a local container — but recordings sync to shared directories and transcripts go to the database" |
| 53 | + ] |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +Three things make this scar effective: |
| 58 | + |
| 59 | +1. **Critical severity** ensures it surfaces with high priority during recall — it won't be buried below medium-severity results. |
| 60 | + |
| 61 | +2. **Three counter-arguments** address three distinct rationalizations. Each one is a real thought process that would lead an agent to print secrets anyway: "partial keys are fine," "sessions are temporary," "containers are isolated." |
| 62 | + |
| 63 | +3. **The scar type is `incident`** (not `process`), meaning it decays over 180 days. If the team later builds infrastructure-level protection (like a pre-execution hook that blocks secret-printing commands), the scar becomes less critical and naturally fades. |
| 64 | + |
| 65 | +## The Save |
| 66 | + |
| 67 | +In a later session, an agent was debugging a failing API integration and needed to verify credentials were loaded. It called `recall` before running diagnostic commands: |
| 68 | + |
| 69 | +``` |
| 70 | +recall({ plan: "check environment variables for API configuration" }) |
| 71 | +``` |
| 72 | + |
| 73 | +GitMem surfaced the scar: |
| 74 | + |
| 75 | +``` |
| 76 | +🧠 INSTITUTIONAL MEMORY ACTIVATED |
| 77 | +
|
| 78 | +Found 2 relevant scars for your plan: |
| 79 | +
|
| 80 | +🔴 Never print environment variable VALUES — only check |
| 81 | + existence (critical, score: 0.82) |
| 82 | + When checking if environment variables exist, NEVER run |
| 83 | + commands that output the actual values... |
| 84 | +``` |
| 85 | + |
| 86 | +The agent confirmed: |
| 87 | + |
| 88 | +``` |
| 89 | +confirm_scars([{ |
| 90 | + scar_id: "...", |
| 91 | + decision: "APPLYING", |
| 92 | + evidence: "Used [ -n \"$VAR\" ] && echo SET || echo MISSING for all three API keys. No secret values were printed to the session.", |
| 93 | + relevance: "high" |
| 94 | +}]) |
| 95 | +``` |
| 96 | + |
| 97 | +Instead of `echo $API_KEY`, the agent ran safe existence checks. The credentials stayed secret. The session recording contained only "SET" or "MISSING" — no actual values. |
| 98 | + |
| 99 | +## The Takeaway |
| 100 | + |
| 101 | +This example demonstrates three properties of effective institutional memory: |
| 102 | + |
| 103 | +**Critical scars justify infrastructure investment.** This scar was so important that it eventually led to a `PreToolUse` hook — an automated gate that blocks commands matching credential-exposure patterns before they execute. The scar came first, proved the risk was real, and justified building the permanent fix. Scars can be the evidence that earns engineering investment. |
| 104 | + |
| 105 | +**Counter-arguments address rationalizations, not just facts.** "Partial keys are safe" and "containers are isolated" aren't factual errors — they're reasonable-sounding arguments that happen to be wrong in this context. By documenting them explicitly, the scar prevents the agent from independently re-deriving the same flawed reasoning. |
| 106 | + |
| 107 | +**Incident scars have built-in expiration.** Unlike process scars (which never decay), this incident scar fades over 180 days. If the team ships a hook that structurally prevents credential exposure, the scar becomes redundant — and the system knows it. This prevents scar accumulation from becoming a burden. |
0 commit comments