Agent 工具外洩事件後,我追查 API 金鑰究竟存放在哪裏
After the agent-tool breach, I asked: where do my API keys actually live?
TECHDEV 開發了 keymap,讓用戶以單一命令在本機盤點 Agent 工具、CLI、Shell 等位置儲存的 API 金鑰。它掃描配置檔、Shell 歷史及其他憑證檔,檢查金鑰是否散落多處、檔案是否對所有用戶可讀,以及是否可能隨 git add . 加入提交或已被 Git 追蹤;工具只讀、不連網,也不顯示金鑰內容,並列出相應供應商的撤銷頁面。
After the agent-tool breach, I asked: where do my API keys actually live?
A few days ago, an agent-tool vendor disclosed a breach that exposed
provider API keys stored in its console workspaces. My first thought
wasn't about their infrastructure. It was much more embarrassing:
Which keys do I even have, and where are they stored?
I couldn't answer that in under a minute. And I suspect most developers
can't. A provider key gets pasted into one agent tool's config, then
another's, then an .env file, then shell history — and every copy is
another place it can leak from, and another line on the bill if someone
abuses it.
So I built a small tool that answers the question locally: keymap.
What it does
One command, no dependencies, no network:
python -m keymap
It scans the config files your agent tools, CLIs and shells actually
read — ~/.claude.json, ~/.codex/config.toml, ~/.env, shell rc
files and history, ~/.aws/credentials, and friends — and reports:
- where each provider key sits (Anthropic, OpenAI, Google, GitHub, AWS,
Slack, Stripe — plus anything assigned to a
*_API_KEY/*_TOKEN/*_SECRETvariable it doesn't recognise), - whether the same key is sprawled across files,
- whether its file is world-readable (
chmod 600it), - whether it landed in shell history,
- whether it's one careless
git add .away from a commit — or already tracked.
It finishes with a rotation checklist: the exact revoke page for every
provider it found. After a vendor breach, that's the difference
between a scavenger hunt and a checklist.
What it never does
-
Never prints key material. Reports show only the public prefix
(
sk-ant-…) plus a SHA-256 fingerprint prefix, so you can recognise the same key across files without seeing it. - Never sends anything anywhere. No network, no telemetry.
- Never writes. Read-only. It tells you what to fix; you fix it.
Try it on a fake home first
The repo ships examples/demo-home/ — a fake home with the same
Anthropic key in two files, an OpenAI key in .env and shell
history, a GitHub token, and a world-readable .env:
sh examples/run-demo.sh
If you run it on your real home and find a key in five places, you're
not careless — you're normal. That's exactly why I built it.
來源:DEV Community · dev.to