Your Stripe key is sitting in the browser
AI tools often paste secret keys into code that runs in the visitor's browser, where anyone can copy them. Here is how to spot it and what to do about it.
4 min readvibe coding issues, security, api keys, stripe
You asked your AI tool to add payments. A few minutes later checkout worked. To get there, the tool needed a Stripe key, you pasted one in, and it wired everything up. Nobody asked where that key ended up.
Often the answer is: in the code that gets sent to every visitor's browser.
What it looks like in your app
Again, nothing. Payments work, the AI features answer, emails go out. The difference is that the key which can charge cards, issue refunds or run up your AI bill is now readable by anyone who opens the browser tools.
Why vibe-coded apps end up here
Keys come in two kinds. A publishable key is made to be public. It can start a checkout, nothing more. A secret key can do almost everything on your account, and it belongs on a server only.
The fastest way to get a feature working is to call the service straight from the page, which means the secret key has to be in the page. The tool takes the fastest path. There is also a naming trap. In many frameworks, any setting whose name starts with NEXT_PUBLIC_ or VITE_ is deliberately copied into the browser code. A secret stored under one of those names is published the moment you deploy.
This is why scans of vibe-coded sites keep finding live keys. Security firms that crawl public sites have reported thousands of exposed secrets, though the exact numbers vary by report and most come from vendors who sell scanning. Treat the totals loosely. The mechanism is not in doubt.
Check it in five minutes
- Open your live app and view the page source, or open the browser tools and go to the Sources or Network tab.
- Search all files for the text
sk_live,sk-,service_role,secretandBearer. - In the Network tab, look for requests going straight from the browser to
api.stripe.com,api.openai.comor similar. Those should come from your own server, not the page. - Check your settings file names. Anything secret under
NEXT_PUBLIC_orVITE_is exposed.
A Stripe key beginning pk_ is fine. One beginning sk_ or rk_ is not.
How to fix it
Order matters here.
- Rotate the key first. In the Stripe dashboard (or wherever the key came from), create a new one and delete the old one. A key that has been in a public page should be treated as already copied.
- Move the call to the server. The page should ask your own server to create the checkout, and the server holds the secret. In most stacks that means a server function or API route.
- Rename the setting. Remove the public prefix from anything secret, and set it only in your hosting provider's environment settings.
- Check your history. If the key was ever committed to a public code repository, rotating it is the only real cure, because deleting the file does not delete the history.
A prompt that works: "Find every secret key in this project. Move any call that uses one into a server-only function, read the key from a private environment variable, and tell me which keys I must rotate."
Then look at your provider's logs. Stripe and OpenAI both show recent activity by key. If you see charges, models or locations you do not recognise, tell them quickly.
What to put in place afterwards
Set a spending limit on any pay-per-use service such as an AI provider. Turn on alerts for unusual activity. And turn on secret scanning in your code host if it offers it, so the next paste gets caught before it ships.
Not sure what is exposed? The free website scan looks for secrets in the scripts your site sends to visitors and shows any it finds with the middle blanked out. If it finds something, or you would like us to check the server side too, send us a link.