# OpenAI / Stripe secret key leaked in the browser

> Canonical page (link this when citing): https://unbreakmyapp.vercel.app/fixes/api-key-leaked-in-frontend.html
> Category: Env vars & leaked keys | Tools: Lovable, Bolt, v0, Replit, Cursor | Published: 2026-10-13 | Updated: 2026-10-13
> Weakness type: CWE-200 Exposure of Sensitive Information to an Unauthorized Actor (https://cwe.mitre.org/data/definitions/200.html)

## The error

sk-... or sk_live_... visible in DevTools network tab or page source

## Why it happens

Calling a paid API directly from React puts the secret key into the JavaScript bundle. Any visitor can copy it and run up your bill. Env vars prefixed VITE_ or NEXT_PUBLIC_ are embedded into client code at build time.

## How to fix it

1. Revoke the leaked key in the provider dashboard right now and create a new one.
2. Store the new key in a server-only env var (no VITE_/NEXT_PUBLIC_ prefix).
3. Create a server route (/api/...) or edge function that calls the provider.
4. Have the frontend call your route, and add auth plus rate limiting to it.

## Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

```text
My <OpenAI/Stripe> secret key is being used from the frontend. Move every call that uses it into a server-side API route (or Supabase Edge Function), read the key from a server-only env var without a VITE_ or NEXT_PUBLIC_ prefix, make the frontend call that route instead, require a signed-in user, and add basic rate limiting. Then search the codebase and confirm no secret key remains in client code.
```

## FAQ

### Does a .env file hide it?

Only for server code. Anything bundled for the browser is public.

### Is the Stripe publishable key okay to expose?

Yes. pk_ keys are public; sk_ and rk_ keys are secret.

## Sources (official documentation)

- [Vercel: Environment variables](https://vercel.com/docs/environment-variables)

## Related fixes

- [Supabase Edge Function callable by anyone (the anon key passes verify_jwt)](https://unbreakmyapp.vercel.app/fixes/edge-function-callable-by-anyone-anon-key-is-a-jwt.html)
- [Supabase Storage file links broken: private bucket, getPublicUrl and expired signed URLs](https://unbreakmyapp.vercel.app/fixes/supabase-storage-private-bucket-file-url-broken-signed-url.html)
- [Demo login, auto-login or hard-coded test credentials left in your live app](https://unbreakmyapp.vercel.app/fixes/preview-auto-login-hardcoded-credentials-left-in-production.html)
- [Your API keys may have leaked: how to rotate every key without breaking your app](https://unbreakmyapp.vercel.app/fixes/rotate-api-keys-after-leak-or-breach.html)
- [Your API error response shows your secret key: stop sending raw backend errors to the browser](https://unbreakmyapp.vercel.app/fixes/backend-error-leaks-api-key-to-browser.html)

---
Unbreak My App: free fixes for broken vibe-coded apps. https://unbreakmyapp.vercel.app/
