KeyDrift
Free scan
criticalCursor·Stripe secret key

Cursor put a stripe secret key in a client component — here's the fix

Charge cards, issue refunds, and read every customer record on the account.

Why Cursor does this

Cursor edits the file you have open. Ask it to "call the OpenAI API" from a component and it writes exactly that — a client component holding a key — because the request named a file, not an architecture. The agent has no way to know the module is bundled for the browser.

Confirm it first

Before rotating anything, check whether the key is actually being served. Paste your deployed URL — KeyDrift downloads the same JavaScript a visitor gets and tells you what is in it.

No account. Read-only — the scanner only ever issues GET requests, and never stores a key: findings carry a masked prefix and a fingerprint.

Rotate the key

Do this before changing any code. The key has been served to browsers, cached by CDNs and very likely scraped already — removing it from the source does not un-publish it.

  1. 1Roll the key in the Stripe dashboard. Rolling issues a replacement and revokes the old key.
  2. 2Review recent charges, refunds and payouts for anything you did not initiate.
  3. 3Move the Stripe call into a server route. The browser only ever needs the publishable key.
Open the revocation page

Move the call to a server

The replacement key must not follow the old one into the bundle, which means the code that uses it cannot live in the browser.

Before — shipped to the browser

// src/components/Chat.tsx
// Vite substitutes the literal value here at build time.
const key = import.meta.env.VITE_STRIPE_SECRET_KEY;
const result = await new Stripe(key).checkout.sessions.create(body);

After — stays on a route handler or server action

// supabase/functions/checkout/index.ts  — runs on a route handler or server action
Deno.serve(async (request) => {
  const key = Deno.env.get('STRIPE_SECRET_KEY')!; // never sent to the browser
  const result = await new Stripe(key).checkout.sessions.create(body);
  return Response.json(result);
});

// src/components/Chat.tsx
const result = await fetch('/functions/v1/checkout', { method: 'POST' }).then((r) => r.json());

How KeyDrift detects it

Matches `sk_live_` and `sk_test_`, then reads the surrounding code. Clerk issues secret keys in exactly this format and nothing in the string distinguishes them, so when only Clerk is referenced nearby the finding is attributed to Clerk, when both are the finding names both, and a `sk_test_` key is reported at medium because no real money can move.

It will happen again

Cursor edits the file you have open. That has not changed because you fixed this one file — the next feature request produces the same shape of code. Continuous monitoring re-scans every deploy and tells you the moment a key comes back.