LeakLatch

For Lovable, Bolt, Cursor and v0 apps

Leaked your OpenAI API key? Do this, in order

Direct answer

If your OpenAI key (it starts with sk-) is in your frontend JavaScript, anyone who opens your site can copy it and make requests billed to your account. Revoke it in the OpenAI dashboard and create a new one, check your usage, set a spend limit with hard enforcement, and move the OpenAI call into a server function so the new key never reaches the browser.

LeakLatch is a free, read-only scan of a live URL you own. It reports leaked secret keys in your JS bundles, Supabase tables that answer with your public anon key, and missing security headers. You get a risk score, redacted findings, and a fix prompt for Lovable, Cursor, or Claude.

What to do

Five steps for your own project

Use these on a project you own. The commands only read your own files; nothing here changes your app. Source for OpenAI's guidance: OpenAI Help Center, Best practices for API key safety.

  1. Step 1

    Revoke the leaked key first

    Open the API keys page in your OpenAI dashboard, create a replacement key, and revoke the old one. OpenAI's own guidance is to rotate a key immediately if you believe it leaked. Until it is revoked, anyone with a copy can keep using it.

  2. Step 2

    Check usage and set a spend limit

    Look at the Usage page for traffic you do not recognise. OpenAI recommends monthly spend limits for your organization or projects with hard enforcement; spend alerts alone do not stop API traffic. If you see misuse, contact OpenAI through help.openai.com.

  3. Step 3

    Move the OpenAI call to a server function

    OpenAI says never to deploy your key in client-side environments like browsers or mobile apps; requests should go through your own backend. In a vibe-coded app that means a Supabase Edge Function, a Vercel or Netlify function, or a Next.js route handler that holds the key and calls OpenAI for the browser.

  4. Step 4

    Store the new key in a server-only variable

    Anything with a VITE_ or NEXT_PUBLIC_ prefix is copied into the JavaScript every visitor downloads. Put the new key in a variable without those prefixes (for example OPENAI_API_KEY) in your hosting or Supabase secrets settings, and never in the frontend code or a committed .env file.

  5. Step 5

    Rebuild and check the live site

    Old bundles can stay cached, and your hosting dashboard can hold different values than your local .env. After redeploying, search the build output with the commands below, then check the live URL to confirm no sk- key ships to visitors.

# Run in your own project folder after a production build.
# Vite (Lovable, Bolt): output in dist/   Next.js (Cursor, v0): output in .next/static/

# 1. OpenAI-style keys (sk-..., including sk-proj-...). Prints only the first characters.
grep -rEoh "sk-(proj-)?[A-Za-z0-9_-]{6}" dist .next/static 2>/dev/null | sort -u

# 2. Where your code talks to OpenAI directly from the client:
grep -rnE "api\.openai\.com|new OpenAI\(|dangerouslyAllowBrowser" src app 2>/dev/null

# 3. Public env variables that hold an OpenAI key (these are built into the bundle):
grep -rnE "(VITE_|NEXT_PUBLIC_)[A-Z_]*OPENAI" . --include=*.env* --include=*.ts --include=*.tsx --include=*.js 2>/dev/null

Copy-paste fix

Move the OpenAI call server-side with one prompt

Paste this into Lovable, Cursor, or Claude and point it at your own project. Review each change before you apply it, and revoke the old key if it already shipped.

You are helping me remove the OpenAI API key from the client side of my own app. Keep existing features working.

1. Find every place the app calls OpenAI (api.openai.com, the openai SDK, dangerouslyAllowBrowser) and every env var or hard-coded string that holds an OpenAI key (sk-...), including VITE_ and NEXT_PUBLIC_ variables.
2. Move each OpenAI call into a server function (Supabase Edge Function, Vercel/Netlify function, or Next.js route handler) that reads the key from a server-only env var named OPENAI_API_KEY with no VITE_ or NEXT_PUBLIC_ prefix.
3. In that function, check the caller is signed in or otherwise allowed, validate the input, and add a simple per-user rate limit.
4. Change the frontend to call my server function instead of OpenAI directly.
5. Remove the key from the frontend and committed files, rebuild, confirm no sk- string is in the build output, and remind me to revoke the old key in the OpenAI dashboard and set a project spend limit.

FAQ

Straight answers about a leaked OpenAI key

Is it safe to put my OpenAI API key in the frontend if the app is private or behind a login?

No. A login screen does not hide your JavaScript files; the bundle is downloaded before or alongside the login, and anyone can open it in the browser's developer tools. OpenAI's help center says exposing the key in browsers or mobile apps lets malicious users make requests on your behalf, which may lead to unexpected charges or compromise of certain account data.

What can someone do with my leaked OpenAI key?

They can send API requests that are billed to your account and use your quota. OpenAI lists data loss, unexpected charges, a depleted monthly quota, and interruption of your API access as possible results of a compromised key.

Is deleting the key from my code enough?

No. Copies of the old bundle, git history, and forks still contain the key, and it keeps working until you revoke it in the OpenAI dashboard. Revoke and replace it first, then clean up the code.

How do I call OpenAI from a Lovable or Bolt app without exposing the key?

Create a server function (for example a Supabase Edge Function) that reads the key from a server-side secret, checks that the caller is allowed, and calls OpenAI. Your frontend calls that function instead of api.openai.com. Adding a per-user rate limit in the function also limits abuse of your own endpoint.

What does LeakLatch check here?

LeakLatch loads the live URL you give it and its JavaScript bundles, read-only, and looks for known secret key patterns, including OpenAI sk- keys, plus Stripe, Anthropic, AWS, Resend, GitHub and Supabase service_role keys. It also checks whether Supabase tables answer with your public anon key. Secret values are redacted in the report. You must confirm you own the site or have permission to scan it.

Is this a substitute for a full security audit?

No. LeakLatch is a pre-ship check for leaked secrets, open Supabase tables, and basic headers. It does not replace a penetration test or a careful code review.

Want this check done for you, read-only?

Paste a URL you own. LeakLatch returns a score, redacted findings, and a fix prompt.

Scan my site free