Deleted Your API Key and Pushed Again, but It's Still Exposed? Here's Why
Removed a leaked key from your code and redeployed, but scanners still find it? Git history, old deploys, build env vars, source maps, and caches keep it alive. How to end it.
Updated 2026-11-11
Deleting the line does not delete the key
A common story: a secret key slips into an app, you notice, delete it, push a new commit, and redeploy. Days later a scanner, a provider warning email, or a surprise bill says the key is still out there.
That is because the key was copied the moment it went public. Removing it from the newest version of your code does nothing to the copies that already exist. The only change that ends the problem is making the old key stop working.
Where the old key is still hiding
If the key keeps showing up after you deleted it, check these places:
- Git history: every earlier commit still has the key. If the repo is public, or was public for even a minute, bots that watch GitHub may already have it.
- An environment variable that still exists: if the key lives in a NEXT_PUBLIC_ or VITE_ variable in your host's settings, every new build writes it back into the browser bundle, even after you delete it from the code.
- Old or preview deployments: hosts like Vercel and Netlify keep earlier builds and preview links online, and those still serve the old JavaScript.
- Public source maps: a .map file can contain your original source, including a key you thought was hidden by the build.
- Caches: a CDN, the browser, or a service worker can keep serving the old JavaScript file for a while after you redeploy.
- Other copies: screenshots, logs, chat messages, forks, and AI-tool share links you made while debugging.
End it in this order
- Revoke or roll the leaked key in the provider's dashboard and create a new one. After this step, every copy above is useless.
- Put the new key only in a server-only environment variable (no NEXT_PUBLIC_ or VITE_ prefix) and delete the old public variable from your host's settings.
- Move the code that uses the key into a server route or function, then redeploy.
- Delete or protect old preview deployments you do not need, and turn off public source maps unless you mean to share them.
- Check the provider's usage and billing pages for activity you did not cause.
- Rewriting git history (for example with git filter-repo) is optional cleanup after you rotate, not the fix.
A prompt you can paste into your coding agent
After you have rotated the key, paste this into Cursor, Lovable, or Claude:
A secret key leaked from this app and has been rotated. Search the whole project, including config files and environment variable names, for anything that would put a secret into browser code. Rename any secret variable that starts with NEXT_PUBLIC_ or VITE_ to a server-only name and move the code that uses it into a server route. Turn off production browser source maps. List every change you made.
Check your live app for free
After you rotate and redeploy, run Freedom Check's free scan on your live URL. It checks the page, up to 8 same-site scripts it loads, and any public source maps for OpenAI, Anthropic, Stripe, AWS, GitHub, Slack, and SendGrid key patterns, private keys, and Supabase service_role keys, and it flags a public /.git folder. It only sees the deployment at that URL: it cannot see your git history, other preview deployments, or whether the key was already used.
The free scan shows how many issues turned up and explains the most serious one with a fix prompt. The full report is $19 one time, or $29/month for unlimited.
Run a free scan →See pricing