# Fix: plaintext API keys in config files

Find keys in configs, .env files and memory files. Move them out. Rotate them.

Check: secrets at rest. Controls: ASI03, MCP01. A live leaked key is critical.

## Detect

List files that hold a key. This prints file names only:

```bash
grep -rEl "sk-ant-[A-Za-z0-9_-]{20,}|sk-[A-Za-z0-9]{32,}|AKIA[0-9A-Z]{16}|ghp_[A-Za-z0-9]{36}|sk_live_[A-Za-z0-9]{20,}" \
  ~/.config ~/.claude ~/.codex ~/.cursor ~/.openclaw ~/.env ./ \
  --include='*.json' --include='*.env' --include='.env*' --include='*.md' --include='*.yaml' --include='*.yml' --include='*.toml' \
  2>/dev/null | head -50
```

Check shell history too:

```bash
grep -cE "sk-ant-|AKIA|ghp_" ~/.zsh_history ~/.bash_history 2>/dev/null
```

Never paste a found key into chat, a ticket or an upload. The Checkup uploads a sha256 fingerprint and a redacted path, not the value.

## Fix

```bash
sma fix --vault
```

This moves plaintext secrets into Agent Secret Store and rewrites configs to use scoped tokens.

Without the vault:

1. Put the key in the OS keychain or an env var set at launch.
2. Replace the file value with a reference such as `${OPENAI_API_KEY}`.
3. Add `.env*` to `.gitignore`. Check history: `git log -p -S'sk-ant-' | head`.
4. Lock file modes: `chmod 600 ~/.env`.

## Rotate

Every key that sat in plaintext counts as exposed. Create a new one at the provider, update the reference, then revoke the old one.

Background: [The Moltbook token leak](https://securemyagent.ai/articles/moltbook-token-leak).

## Sources

- [Infosecurity on the Moltbook leak](https://www.infosecurity-magazine.com/news/moltbook-exposes-user-data-api/)
- [OWASP MCP Top 10](https://owasp.org/projects/mcp-top-10)
- [OWASP Top 10 for Agentic Applications 2026](https://genai.owasp.org/2025/12/09/owasp-top-10-for-agentic-applications/)
