guest@electrichead:~$ get keys
static: the bots found a way to make you pay for their homework. cap your keys.
The API key lockdown
AI agents are out there hunting for API keys people left in public code, then using them to pay for their own work. If your key's exposed, it's your bill. Three moves shut that down.
1. Keep keys out of code and repos
Do this once per project
- Put every key in a
.envfile or your host's secret settings. Never paste one into the code. - Add
.envto.gitignorebefore your first commit, not after. - Turn on secret scanning and push protection in your git host's settings, so a key gets blocked before it's public.
- Check what's already there with the command below. Anything it finds goes straight to step 3.
.env
.env.*
!.env.example
git grep -nIiE 'api[_-]?key|secret[_-]?key|sk-[a-z0-9_-]{20,}' $(git rev-list --all) -- . ':!*.example' | head -50
2. Cap and alert on spend at the provider
In each AI provider's billing settings
- Set a hard monthly spend limit. A cap stops the damage; an alert only tells you about it.
- Add budget alerts at 50% and 90% of that limit, sent somewhere you'll actually see.
- Use one key per app or project, so you can see which one's burning and kill only that.
- Give each key the smallest scope and model access the provider allows.
3. Rotate anything that's leaked, then check usage logs
If a key was ever public, even for a minute
- Revoke it at the provider. Deleting it from the repo isn't enough: it's still in the history and in every copy.
- Make a new key and put it in your
.envfile or secret store, never in the code. - Redeploy everything that used the old key.
- Check the provider's usage logs for calls you didn't make, and the billing page for spikes.
- Spotted charges you didn't make? Contact the provider's support with the dates.
Didn't download? Tap ⋯, then Open in browser.
Source: AWS Security Blog
guest@electrichead:~$ next
Want the next one?
!That email doesn't look right. Check for a typo?
That didn't go through. Try again?
You're in.
Unsubscribe any time. From Electric Head Productions.