Exposed API Key in the Frontend
Glossary
An exposed API key is a secret key for a service, such as OpenAI, Anthropic, Stripe or AWS, that sits in the shipped JavaScript. Every visitor downloads everything in the frontend, so anyone can read the key in the dev tools and use it on your bill. Hiding it no longer helps at that point: the key has to be rotated and the call moved behind your own server endpoint.
The typical route into the bundle is a prefix. Every bundler has one that means “may go to the browser”: NEXT_PUBLIC_ in Next.js, VITE_ in Vite (and therefore in Lovable and Bolt), REACT_APP_ in Create React App. Values with this prefix are baked into the JavaScript every visitor downloads at build time. If such a variable holds a secret, say VITE_OPENAI_API_KEY, it is published. The second route: the app calls an AI API straight from the browser. That call needs a key, which is therefore reachable.
The damage is not abstract. Whoever pulls an AI key from the dev tools keeps generating on your bill until the budget or the limit runs out, and that often only surfaces on the invoice. A leaked Stripe secret key can trigger real payments, a cloud key can spin up real servers.
Not every key in the browser is a leak. Some are designed for it: the Supabase anon key (bound to Row Level Security) or Google browser keys for Maps and Firebase, which you should restrict to your domain in the Google Cloud console. The free decivo Scan searches the shipped code for the patterns of real secrets, including Stripe, OpenAI, Anthropic, AWS, GitHub and Supabase secret keys, and for AI provider addresses in the app's own code.