What is an API key leak?
An API key leak is when a secret credential, such as a payment, AI, cloud or database key, becomes readable by people who should not have it. Common places are front-end JavaScript, public repositories, source maps and logs. Anyone holding the key can use the service at your cost.
How it works
Everything in the JavaScript sent to a browser is public: anyone can open dev tools and read it. Build tools embed variables with a public prefix, such as NEXT_PUBLIC_ or VITE_, straight into the bundle, so a secret placed there ships to every visitor. Keys also leak when .env files are committed to git, when source maps expose original files, and when an AI coding assistant pastes a key into client code. A leaked payment or AI key lets others spend your money or read your customers' data.
# .env
NEXT_PUBLIC_OPENAI_KEY=sk-live-... # shipped to every visitor
OPENAI_KEY=sk-live-... # stays on the server
// client code
fetch("https://api.openai.com/v1/...", {
headers: { Authorization: "Bearer " + process.env.NEXT_PUBLIC_OPENAI_KEY },
});How to tell if your site is affected
- Search your built JavaScript (dev tools, Sources tab) for key prefixes such as sk_live_, sk-, AKIA, ghp_ or "service_role".
- A secret variable name starts with NEXT_PUBLIC_, VITE_, REACT_APP_ or EXPO_PUBLIC_.
- The browser calls a paid API directly and sends an Authorization header you can see in the Network tab.
- A .env file or its contents are in git history, a public repo or a shared screenshot.
- The provider sent a usage alert or a "key found on GitHub" notice.
How to fix it
Revoke and regenerate the exposed key at the provider first. Removing it from code does not make the old key safe.
Check the provider's usage logs for calls you did not make and, if payments are involved, review recent activity.
Move the call to a server route or Edge Function that holds the key and checks who is asking. Keep secrets in server-only environment variables.
Where a key must be in the browser (maps, anon keys): restrict maps keys by domain and quota; for Supabase anon keys rely on row-level security.
Add a secret scanner to your repo or CI, stop publishing source maps and set spending caps.
How ScanAnt checks for it
The free quick scan reads your page, JavaScript and source maps and matches them against patterns for payment, AI, cloud, e-mail and database keys. Each hit shows its location and a masked value; ScanAnt never stores a key in full, never sends it to an AI model and never uses it. The deep scan watches a real browser session for keys sent in request addresses or kept in storage, and the code scan finds hard-coded secrets in an uploaded ZIP.
Questions
Which keys are safe to expose?
Keys that are designed to be public: Supabase anon keys, Firebase web config, Stripe publishable keys. Their safety depends on rules and restrictions behind them.
I deleted the key from my code. Am I safe?
No. Old builds, caches, source maps and git history may still hold it. Rotate it.
How fast do leaked keys get abused?
Bots scan public repositories and sites continuously, and abuse can start within minutes.
Can obfuscating the key help?
No. The browser must send the real value with each request, so anyone can read it from the network tab.
Related terms
Exposed source maps
Public .map files hand over your original front-end source.
Read →JWT
A signed token that proves who the user is.
Read →Supabase Row Level Security (RLS)
Postgres policies that decide who can read and write each row.
Read →Check your own site
Leaked Stripe, OpenAI, AWS and database keys in public JavaScript.
Open the matching check →
See if your site is affected
Free for any public site, no signup. Need the verified or deep scan? Choose the level on the scan page.
Choose a scan level →