An incident from n8n community practice: an API key leaked from a chat — within 10 minutes, 200 hijack emails had been sent through someone else’s quota. The cost in time, money, and nerves is out of all proportion to the one minute of hygiene that prevents all of it. This piece walks the incident step by step — how it leaked, how it was exploited, why the owner learned about it last — and assembles the defense on four levels: storage, caps, monitoring, and a response playbook.
Incident timeline: 10 minutes between the leak and exploitation
- The leak. The key ended up in a chat — a support conversation or a forward inside a team. The leak point is typical for “gray” gateways and free tiers, where keys travel in personal chats and get passed around “to try out”.
- Attacker detection. Key scanners monitor leaks automatically: 10 minutes between the key landing in someone else’s hands and the start of exploitation.
- Exploitation. 200 emails on your quota — a mailing or spam in your name; the quota burn and the money land on you.
- Owner detection. Via a blown quota or emails from the service — with a delay of hours or days. While the owner suspects nothing, the key has already done its work.
- Response. Revocation, rebuilding pipelines, the post-mortem — half a day minimum even with “minimal bloodshed”.
| Stage | Time | Initiator |
|---|---|---|
| Key leak | a moment | owner |
| Exploitation | after 10 minutes | attacker |
| Owner detection | hours — days | owner |
| Response and post-mortem | half a day minimum | owner |
The asymmetry in the table is the main argument of the whole piece: the attack is automated and fast, the owner’s defense is manual and slow. For keys of “gray” gateways and free pools, add a question about the platform itself: where does it store your keys, and who else can see them. The gray gateway checklist helps cut the risky options early.
Level 1: keys never leave the secret store
An n8n community case: a member showed a self-built service — a Docker container with encryption and key issuance via a Bearer key — as an alternative to “an open database and Vaultwarden”. The point is not the specific implementation but the principle: keys live in an encrypted store, are issued on request, and every issuance is logged. The level’s rules:
- A key is never pasted into chats, prompts, code comments, or screenshots — never: not “to show”, not “to check”, not “just for a minute”.
- Keys live in .env on a server or in a secrets manager; only references to environment variables, without the values themselves, make it into a repository.
- A hook check on outgoing messages: the patterns sk-, ghp_, nvapi-, AIza block the send. How to attach such a filter to agent operations is covered in a separate breakdown of hooks and guard scripts.
- Review screenshots before publishing: half of all leaks are interface demos with a key open on screen.
Where keys leak most often
Support conversations and team chats are the first place: “toss me the key, let’s check”. Second — interface screenshots: the key is visible in a settings row or in a terminal header. Third — code comments and configuration files committed by inattention. Fourth — request logs, where the key arrives together with the headers. A hook filter on outgoing messages mechanically closes the first two channels; .gitignore and the secret store close the rest.
.env is hidden from git via .gitignore — before the first key lands in a commit:
# .gitignore
.env
.env.*
*.keyFor the hook filter, patterns of common key formats are useful (the boundaries are approximate — adjust them to your providers):
sk-[A-Za-z0-9_-]{20,}
sk-ant-[A-Za-z0-9_-]{20,}
ghp_[A-Za-z0-9]{36}
nvapi-[A-Za-z0-9_-]{20,}
AIza[0-9A-Za-z_-]{35}A separate ritual — before every interface screenshot: switch to a tab without keys or apply a system mask over the area. It is more boring than a revocation, but it is free and takes seconds.
Level 2: keys with caps and rotation
Even a leaked key must be harmless. Separate keys per task, with budgets: the LiteLLM proxy supports virtual keys — virtual keys with individual limits, issued to applications instead of the provider’s real keys. The proxy configuration (schematic):
model_list:
- model_name: mailer
litellm_params:
model: openai/gpt-4o-mini
api_key: os.environ/MAILER_API_KEY
general_settings:
master_key: os.environ/LITELLM_MASTER_KEYA virtual key is created in the proxy’s admin panel or via a key-generation request — with budget parameters and a clear alias, so the log shows exactly who is burning tokens. The provider’s real key stays inside the proxy and is never handed out. Running the proxy on your own machine is the command litellm --config proxy_config.yaml; installation and full setup are in the guide to the LiteLLM proxy on a VPS.
Then — discipline. One-button revocation in the dashboard (find the button in advance, not during the incident). Rotation on a schedule — once a month to a quarter. Caps on every key: a leaked key with a $5/day cap is an annoyance; a leaked key with access to everything is a catastrophe. The rule: one key = one task = one cap.
Level 3: spend monitoring and alerts
The usage log catches anomalies invisible “to the eye”: a spend spike, requests from other regions, models you never use. The minimal setup: a log is mandatory (the method is in the piece on token accounting), alerts on exceeding the daily limit ×2, and a weekly reconciliation of the dashboard counter against the log.
| Signal | What it means |
|---|---|
| A one-day spend spike | someone else’s activity through your key, or a pipeline failure |
| Requests from other regions | the key is working for someone besides you |
| Models absent from your scenarios | someone is probing your limit for you |
| Spend while pipelines are stopped | the key is living its own life |
With this monitoring in place, the incident from the timeline would have been caught at the first hundred emails, not at two hundred — an alert on exceeding the limit would have fired before the quota counter in the dashboard showed the overflow.
Level 4: the response playbook
A playbook written in advance cuts the response from hours to minutes: during an incident there is no time to think through the order of steps — the order must already exist.
If a leak is suspected:
1. Revoke the key immediately (the dashboard button — know in advance where it is).
2. Check the spend: what leaked, how much, to where.
3. New keys: a new secret, a new cap.
4. Find the leak point: where the key was visible (chats, screenshots, logs).
5. Write an incident log entry: date, cause, lesson.Refinements to the steps. At step 2, check where else the leaked key lived: the same secret in other pipelines — a reason to rotate those too. At step 4, honestly record the channel: if the key belonged to a “gray” gateway — notify the platform; they block leaks on their side as well. Step 5 matters most over the long run: an incident that is not turned into a rule will repeat.
Adjacent to this is isolating the machine where the agent lives: keys on an isolated machine can be stolen along with the machine, but they do not open a path to your files and mail. The full architecture is in the breakdown of sandboxes and agent isolation levels.
Frequently asked questions
Is 10 minutes an exaggeration? No: automated leak scanners run continuously; a public key lives for minutes. Private correspondence lasts longer — but not indefinitely: screenshots get forwarded, chats get exported, backups get browsed.
Nobody is hunting for my keys? Scanners hunt for patterns, not for you personally: match the pattern — become a target. A hook filter on outgoing messages catches this scenario too — the key physically cannot leave the machine.
Does two-factor authentication help? For platform accounts — yes. For Application Passwords and API keys — no: they are themselves the second factor; stealing one equals logging in.
What about keys in git history? Even after removal from the commit, a key stays in the repository history: revocation is mandatory; the history is cleaned with filtering utilities, or the repository is recreated from scratch.
An incident in 10 minutes is an argument that needs no explanation: four levels of defense — storage, caps, monitoring, playbook — cost an hour of setup, while the incident costs half a day, money, and reputation. A concrete action for today: open your provider’s dashboard, find the revocation button, and check whether every one of your keys has a cap. The breakdown comes from n8n community practice, fall 2026.
