How to find leaked API keys in your frontend JavaScript
Step-by-step: search your live JS bundle for exposed secrets, know which keys are safe to be public, and rotate and move the ones that aren't.
Every file your site sends to the browser can be downloaded and read. That includes minified bundles and source maps. If a secret key is in there, it's public, and bots look for exactly this.
Which keys are fine to be public?
| Usually public by design | Must stay on the server |
|---|---|
| Supabase URL + publishable/anon key | Supabase service_role / sb_secret_ |
Stripe publishable key pk_live_ |
Stripe secret sk_live_ / restricted rk_live_ |
Firebase web config (apiKey); access is controlled by security rules |
Firebase service-account JSON |
| Google Maps browser key with HTTP-referrer restrictions | OpenAI sk-..., Anthropic sk-ant-..., Resend re_..., AWS AKIA... + secret, GitHub ghp_... |
| Sources: Supabase API keys, Stripe API keys, Firebase API keys, OpenAI key safety. |
Why build tools leak keys
Vite puts every VITE_* variable into the client bundle. Next.js does the same with NEXT_PUBLIC_* (Vite env docs, Next.js env docs). AI assistants often add that prefix just to make a demo work.
Step 1: Search your live bundle (browser)
- Open your production site and go to DevTools → Sources.
- Press Ctrl/Cmd+Shift+F to search all files for:
sk-,sk_live_,rk_live_,service_role,sb_secret_,AKIA,ghp_,re_,-----BEGIN. - If you find a
service_rolekey, it's a JWT, so decode it at a trusted local tool and check theroleclaim.
Step 2: Search from the command line
mkdir bundle && cd bundle
wget -q -r -l2 -A js,map https://your-app.com/
grep -rEo "(sk-[A-Za-z0-9_-]{20,}|sk_live_[A-Za-z0-9]{10,}|AKIA[0-9A-Z]{16}|ghp_[A-Za-z0-9]{36}|sb_secret_[A-Za-z0-9_-]+)" .
Also scan your repo and its history with an open-source tool such as gitleaks or TruffleHog. A key that was deleted from the code but is still in a git commit has still leaked.
Step 3: Check for exposed files
Request https://your-app.com/.env, /.git/config, and /assets/*.js.map. Source maps aren't secrets, but they reveal your original source code. Turn them off in production (Vite: build.sourcemap: false).
Step 4: If you find a key, do these in this order
- Rotate it in the provider's dashboard. Deleting it from the code isn't enough, because it's already public.
- Check the provider's usage and billing for activity you don't recognize. Set spend limits where the provider offers them.
- Move the call to the server: an Edge Function, API route or serverless function that reads the key from env/secrets and checks the user (an open proxy just moves the problem).
- Remove the
VITE_/NEXT_PUBLIC_prefix from secret variables and redeploy. - Add a pre-commit secret scan so it doesn't happen again.
GitHub also runs secret scanning on repos, which helps for code you push. It doesn't see your deployed bundle.
Or scan your live site free
KeyMoat downloads your deployed page and up to 25 same-site JavaScript files (as a visitor's browser would, without running them) and checks them for common secret-key patterns (OpenAI, Anthropic, Stripe, AWS, GitHub, Slack, SendGrid, Resend, Supabase secret/service_role, private keys and more). It also checks for exposed .env/.git/source maps, missing security headers, and Supabase tables that can be read anonymously. It's read-only and needs only a URL. Only scan sites you own.
Scan my site for leaked keys →
New keys can slip in with any AI-generated change. Monitoring (from $5/mo) re-scans weekly and emails you a fix prompt when something new shows up.
Run a free, read-only scan of your live app
Paste your URL. Checks leaked keys, exposed files, security headers and anonymous Supabase access. Only scan sites you own.
Scan my site free →