PatchPaste · Guides

Last updated 13 November 2026

Cursor shipped an API key in my frontend

If Cursor (or another AI editor) put an OpenAI, Stripe, Anthropic or Supabase secret key in a NEXT_PUBLIC_ or VITE_ variable, or pasted it into a component, that key is in the JavaScript every visitor downloads. Scan your live app free to see whether it's still there.

Short answer: Cursor doesn't “leak” keys on its own. The usual path is an AI suggestion that uses a public env prefix, or a key pasted into client code while testing. Confirm on the live site (not only in the editor), move the call to the server, redeploy with a new key, then revoke the old one. Removing the line from source without rotating the key is not enough.

Why Cursor apps often ship secrets

Cursor writes the same patterns other AI builders do. Three common ones:

This is the same trap as in Lovable and Bolt apps that use Vite. For the general VITE_ / NEXT_PUBLIC_ rule, see Are VITE_ environment variables secret?

Which keys are fine in the browser

Fine to be publicMust stay on the server
Supabase URL and anon / publishable key (only with RLS on every table)Supabase service_role or sb_secret_... key
Stripe publishable key (pk_live_... / pk_test_...)Stripe secret or restricted key (sk_ / rk_)
Analytics and public config IDsOpenAI (sk-...), Anthropic (sk-ant-...), AWS, GitHub and other AI or cloud keys

Stripe says only publishable keys belong in the browser; secret keys must stay server-side (Stripe docs: API keys). Supabase says secret and service_role keys “bypass Row Level Security, so use them in Edge Functions and never in a browser” (Supabase docs: Edge Function secrets). More: Is my Stripe secret key exposed? and service_role key exposed.

Check your live Cursor app in 2 minutes

  1. Open the deployed URL in a private window (not localhost, not the editor preview).
  2. Open DevTools → Sources and search all files (Ctrl+Shift+F, or Cmd+Option+F on a Mac) for:
    • sk- and sk-ant- (OpenAI / Anthropic)
    • sk_live and rk_live (Stripe secret / restricted)
    • service_role and sb_secret_ (Supabase admin keys)
    • dangerouslyAllowBrowser
    • NEXT_PUBLIC_ and VITE_ combined with words like KEY, SECRET, TOKEN
  3. Click through login, chat, checkout and any AI features so lazy-loaded chunks load, then search again.
  4. In the Network tab, look for browser requests straight to api.openai.com, api.anthropic.com or api.stripe.com with an Authorization header. That means the key left with the request.

Finding nothing in source does not prove the old key is safe: revoke it if it was ever in a build that went live.

Fix it in this order

  1. Move the call to the server. In Next.js, a Route Handler or Server Action. With Supabase, an Edge Function. The browser should call your own endpoint; your endpoint calls the provider.
  2. Create a new key in the provider dashboard and store it only in a server env var — no NEXT_PUBLIC_ or VITE_ prefix.
  3. Redeploy, then search the live JavaScript again (or run a free outside-in scan).
  4. Revoke the old key. Deleting the line from git is not enough; old visitors and caches may still have it.
  5. Add limits. Require a signed-in user on the new endpoint, rate-limit it, and set a spend cap at the provider if one exists. A server function that forwards anything to OpenAI is just a leaked key with extra steps.

A prompt you can paste into Cursor

My app calls <service> from the browser using a key in a NEXT_PUBLIC_ or VITE_
variable, or a key hardcoded in a component. Move this to the server:
1. Create a server function (Next.js Route Handler, Server Action or Supabase
   Edge Function) that reads the key from a server-only env var (no NEXT_PUBLIC_
   or VITE_ prefix).
2. Change the frontend to call that function instead of <service> directly.
3. Require a signed-in user in the function and add a simple rate limit.
4. Remove the old variable, any hardcoded key, and any dangerouslyAllowBrowser setting.
Show me the changes before applying them. I will create and revoke keys myself.

Also check you didn't leave a .env or .git folder on the live host (Is my .env file publicly accessible?) and that Supabase tables aren't open to the public key (Supabase RLS check). Before launch, run the pre-launch checklist.

Cursor frontend secrets FAQ

Did Cursor leak my API key?

Cursor itself doesn't publish your key. What happens is the AI suggests code that puts a secret in a NEXT_PUBLIC_ or VITE_ variable, or pastes the key into a component. When you build and deploy, that value is copied into the JavaScript every visitor downloads.

Are NEXT_PUBLIC_ and VITE_ variables secret?

No. Next.js inlines NEXT_PUBLIC_ values into the browser JavaScript at build time. Vite exposes VITE_ variables in client-side source after bundling. Both docs say not to put API keys in them.

I deleted the key from my code. Am I safe?

Not yet. Anyone who loaded the old build could have copied it, and caches or archives may still hold it. Make a new key on the server, redeploy, then revoke the old one.

Is my Supabase anon key a Cursor leak?

No. The anon (or publishable) key is meant to be public. The problem is a service_role or sb_secret_ key in the frontend, or tables readable with the public key because Row Level Security is off or using (true).

How do I know if my live Cursor app still has a secret key?

Open the live site in a private window, search Sources for sk-, sk-ant-, sk_live, service_role, sb_secret_ and dangerouslyAllowBrowser, or run a free outside-in scan with PatchPaste. It searches the JavaScript your site sends and shows any keys it finds masked.

Can I hide the key by encoding it or splitting it?

No. If the browser can rebuild the key to use it, anyone else can. Only server-side code keeps it secret.

If the key is an OpenAI API key, use the revoke-then-move order in OpenAI API key in the frontend.

Check your Cursor app for free

Paste your live URL for a free A to F report. PatchPaste searches the JavaScript your site sends for Stripe, OpenAI, Anthropic, AWS, GitHub and Supabase admin keys (shown masked), and checks for open Supabase tables, exposed .env/.git/source maps and missing headers. Fix prompts for that report are a one-off £9 (or £29 for 10). Scans are free to rerun after you redeploy.

Free. No login. No code access.

Want to see one first? View a sample report.

Sources (checked 5 Nov 2026): Vite, Env Variables and Modes (VITE_ exposed after bundling; do not put API keys in them); Next.js, Environment Variables (NEXT_PUBLIC_ inlined into browser JS); OpenAI, openai-node README (dangerouslyAllowBrowser exposes credentials); Supabase, Edge Function secrets (secret/service_role keys never in a browser); Stripe, API keys (only publishable keys in the browser).