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.
Why Cursor apps often ship secrets
Cursor writes the same patterns other AI builders do. Three common ones:
- Public env prefixes. Next.js apps (common with Cursor and v0) use
NEXT_PUBLIC_for values that must reach the browser. Vite apps useVITE_. Next.js says public variables are “inlined into the JavaScript sent to the browser” at build time (Next.js docs). Vite saysVITE_variables are “exposed in client-side source code after Vite bundling” and “should not contain sensitive information such as API keys” (Vite docs). An AI that has seenNEXT_PUBLIC_OPENAI_API_KEYin training data will happily suggest it again. - Keys pasted into components. A key typed into a chat or a temporary component while debugging can be copied into committed code. Once built, it sits in the bundle as a plain string.
dangerouslyAllowBrowser: true. The OpenAI Node SDK refuses to run in a browser unless you set this flag. Its own README says that does “expose your secret API credentials in the client-side code” (openai-node README). If Cursor added it to make a chat feature work, treat the key as public.
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 public | Must 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 IDs | OpenAI (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
- Open the deployed URL in a private window (not localhost, not the editor preview).
- Open DevTools → Sources and search all files (Ctrl+Shift+F, or Cmd+Option+F on a Mac) for:
sk-andsk-ant-(OpenAI / Anthropic)sk_liveandrk_live(Stripe secret / restricted)service_roleandsb_secret_(Supabase admin keys)dangerouslyAllowBrowserNEXT_PUBLIC_andVITE_combined with words likeKEY,SECRET,TOKEN
- Click through login, chat, checkout and any AI features so lazy-loaded chunks load, then search again.
- In the Network tab, look for browser requests straight to
api.openai.com,api.anthropic.comorapi.stripe.comwith anAuthorizationheader. 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
- 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.
- Create a new key in the provider dashboard and store it only in a server env var — no
NEXT_PUBLIC_orVITE_prefix. - Redeploy, then search the live JavaScript again (or run a free outside-in scan).
- Revoke the old key. Deleting the line from git is not enough; old visitors and caches may still have it.
- 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.
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).