Fixes › Env vars & leaked keys
OpenAI / Stripe secret key leaked in the browser
Published
Weakness type: CWE-200 (Exposure of Sensitive Information to an Unauthorized Actor)
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
- Revoke the leaked key in the provider dashboard right now and create a new one.
- Store the new key in a server-only env var (no VITE_/NEXT_PUBLIC_ prefix).
- Create a server route (/api/...) or edge function that calls the provider.
- Have the frontend call your route, and add auth plus rate limiting to it.
Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)
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
Based on the official documentation:
Related fixes
- Supabase Edge Function callable by anyone (the anon key passes verify_jwt)
- Supabase Storage file links broken: private bucket, getPublicUrl and expired signed URLs
- Demo login, auto-login or hard-coded test credentials left in your live app
- Your API keys may have leaked: how to rotate every key without breaking your app
- Your API error response shows your secret key: stop sending raw backend errors to the browser
Want the full checklist for this area? Get a Fix Kit ($29)
Featured slot available: reach thousands of vibe coders. Sponsor this week →
Get one new fix a week
Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.
We only use your email to send the newsletter. Unsubscribe any time. See privacy.