How to check if your API key is exposed on your website
If a secret API key is in your website's JavaScript, anyone can copy it in seconds, and bots scan new sites for exactly that. Here's how to check your own site, what the common key formats look like, and what to do if you find one.
Check your site in two minutes
- Open your live website in Chrome, Edge or Firefox.
- Open DevTools (F12, or Cmd+Option+I on a Mac) and go to Sources.
- Press Ctrl+Shift+F (Cmd+Option+F on a Mac) to search across all files.
- Search for each of the prefixes below. A secret key should never appear.
What leaked keys look like
| Service | Secret key starts with | Risk |
|---|---|---|
| OpenAI | sk-proj-, sk- | Usage billed to you |
| Anthropic | sk-ant- | Usage billed to you |
| Stripe | sk_live_, rk_live_ | Refunds, payouts, customer data |
| AWS | AKIA, ASIA | Whatever the key can reach |
| Supabase | service_role JWT, sb_secret_ | Your whole database |
| GitHub | ghp_, github_pat_ | Your repositories |
AIza | Depends on restrictions |
Some keys are meant to be public: Stripe publishable keys (pk_live_) and the Supabase anon key are fine in the browser.
Why keys end up in the frontend
In apps built with Vite, Next.js or Create React App, environment variables starting with VITE_, NEXT_PUBLIC_ or REACT_APP_ are bundled into the JavaScript every visitor downloads. AI coding tools often use these prefixes to make a feature work quickly. Other common leaks are a public .env file (try opening yoursite.com/.env) and public source maps.
If you find a leaked key
- Rotate it now in the provider's dashboard. Deleting it from your code is not enough: it's already been downloaded.
- Move the call to a server, such as a serverless function or Supabase Edge Function, that reads the key from a secret.
- Set a spend limit for AI providers so a future leak can't run up an unlimited bill.
- Check the provider's usage logs for anything you don't recognise.
LeakPatrol does this check automatically: paste your site's address and it searches every JavaScript file it loads for more than 10 kinds of secret key, plus public .env files, .git folders and source maps. It's free and read-only, and any key it finds is masked.
Check your app in a minute
Free, read-only, no sign-up. Every problem comes with a plain-English fix and a prompt for your AI tool.
Get the 10-point checklist
Every check we run on AI-built apps, with how to do each one yourself. Straight to your inbox.
Plus the odd security tip. Unsubscribe any time.
Questions
How do I know if my API key is exposed?
Open your live website, go to DevTools, search all JavaScript files for key prefixes such as sk-, sk_live_, AKIA and service_role, or use a free read-only scanner like LeakPatrol.
Is it safe to put an API key in frontend JavaScript?
Only public keys such as Stripe publishable keys or the Supabase anon key. Secret keys must stay on a server, because anything in frontend JavaScript can be read by every visitor.
What should I do if my OpenAI API key was exposed?
Revoke it in the OpenAI dashboard immediately, create a new one, move OpenAI calls to a server-side function, and set a monthly spend limit.
More guides
- Supabase RLS policy generator (free)
- Is this API key safe in my frontend? Free key checker
- Security scan MCP server for Claude Code, Cursor and other AI agents
- Supabase October 30 grants change: what it fixes for your app's security, and what it doesn't
- Supabase "42501 permission denied for table": the safe fix (not GRANT ALL)
- Supabase "new row violates row-level security policy": 5 causes and the safe fix
- Supabase service_role key exposed? What to do in the next hour
- Supabase select returns an empty array but the data is there: the RLS fix
- Supabase "Database error saving new user": find the cause and fix it safely
- Supabase Storage upload: "new row violates row-level security policy" fixed
- Supabase "infinite recursion detected in policy for relation" fixed
- Supabase Edge Function "blocked by CORS policy" fixed
- Supabase "Forbidden use of secret API key in browser" (401) fixed
- Supabase "Legacy API keys are disabled" or "Invalid API key": what it means and the fix
- Supabase login or magic link redirects to localhost:3000 (fixed)
- Is your Supabase storage bucket public? What anyone can see, and the fix
- Where to put your OpenAI API key in a Lovable app (so nobody can copy it)
- Supabase "Function Search Path Mutable" warning: what it means and the one-line fix
- Supabase "email rate limit exceeded" fixed (and "you can only request this after 60 seconds")
- Lovable data exposure study: is your app one of the 24,664?
- Lovable security check: is your Lovable app safe?
- Bolt.new security check: is your Bolt app safe?
- Launch checklist for apps built with Lovable, Bolt and Cursor
- Supabase security check: is your anon key safe? (RLS checker)
- Are VITE_ env variables secret? How to hide API keys
- Stop users giving themselves your paid plan (Supabase)