Cursor wrote my Supabase call into a client component
Cursor edits the file you have open; if that file ships to the browser, so does the key it referenced. Scan the deployed bundle free.
The request named a file, not an architecture — that sentence carries the whole story. Ask Cursor to “call Supabase here” and it writes exactly that, competently, into whatever module is open.
When the open file was a client component, competence produced a leak. Here is the anatomy and the three-step response.
What actually happened
A query returned empty; you opened the component and asked the agent to make it work with the service credential from .env.
- The agent read the env reference style already present and mirrored it.
- It added the import plus createClient call in the client module — valid TypeScript, wrong boundary.
- Review passed: the diff showed a variable, not a secret.
- The next build substituted the literal; review never sees substitution.
Every step above is individually reasonable and none of them prints a warning. The value crosses into the bundle during substitution, not execution, so nothing in your runtime ever sees the moment it happened.
What someone can do with it
The agent had no way to know the module bundles for the browser:
- Unconstrained database access per service_role scope.
- Silent persistence — the pattern now looks native to the repo.
Rotate first
Rotate before you touch any code. The key has been served to every visitor since the deploy that introduced it, cached by CDNs along the way, and very likely harvested by crawlers that scan served JavaScript for exactly these shapes. Rotate the Supabase key, then relocate the call server-side before re-enabling traffic. Removing the string from source does not un-publish it; only revocation closes the door.
A rotated key left in old deploys is still discoverable in CDN caches and archived copies. Rotation plus redeploy closes both halves; either alone leaves the door ajar.
Move the call somewhere the browser cannot read
The structural fix is always the same shape: the call moves to a context that holds the key without serving it, and the browser asks your server instead.
"use client";
const db = createClient(url, process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY);
// app/api/orders/route.ts
import 'server-only';
export async function GET() {
const db = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY);
return Response.json(await db.from('orders').select());
}
Check whether yours is exposed
You can check manually right now: open the site, view source or open DevTools, and search the built JavaScript for eyJ. A hit means the string shipped; decode or prefix-check it before deciding how bad the news is.
Manual searching proves one page on one day. KeyDrift fetches the deployment the way a browser would, follows chunks named only in route manifests, reads streamed hydration payloads, and classifies what it finds — secret, or public-by-design — so an anon key never shows up dressed as an emergency.
Keep it from coming back
One more thing worth knowing before you close the tab: fixing this once does not end the story. Agents imitate whatever pattern is already in the repo, templates carry their own defaults, and the next feature request can reintroduce the same shape of code. Continuous monitoring re-scans every deploy and alerts only on change — new, regressed, resolved — so the comeback attempt is a notification instead of a quarter-end surprise.
Re-prompting as prevention
Boundary rules belong in instructions files (.cursorrules and equivalents): never import server credentials in files under components/, prefer route handlers for data access. Instructions reduce frequency; they do not guarantee absence — which is why the deploy-side check stays part of the loop.
Why this keeps happening industry-wide
Zoom out and the pattern is bigger than one repo. AI-assisted output has outgrown review capacity everywhere at once, which means thousands of teams are making the same reasonable-looking tradeoffs in the same week. Cursor users are not uniquely exposed — they are typically exposed. The failure mode documented above is the modal outcome of velocity without verification, not evidence of carelessness.
How KeyDrift reports this exact finding
Report anatomy matters during incidents, so it is worth reading once calmly: masked string (never the live value — it ceases to exist outside the detection engine), salted fingerprint (trackable within your workspace, useless to strangers), chunk path (your starting point for a "git log -S" hunt), disposition (secret versus public-by-design), confidence (matches below 0.5 never reach the page at all).
Manual check, step by step
The full manual drill, for readers who want zero dependence on any tool: open the deployed site in a private window; launch DevTools → Sources; use Search-all-files (Ctrl/Cmd+Shift+F) for eyJ; then repeat for the other marker families — eyJ, sk_live_, sk-proj-, AKIA, postgres, BEGIN PRIVATE KEY. Decode anything JWT-shaped before reacting, and classify public-by-design formats as expected guests rather than intruders.
Close the loop with monitoring
If you take one operational step from this page, make it this: put the URL under continuous monitoring (free tier covers one project daily). The first scan tells you whether you have a problem today; the schedule tells you whether the problem comes back next month after someone re-adds the convenient line.
Common questions
Do .cursorrules files prevent this?
They help consistently-stated conventions spread. They are guidance, not enforcement; keep the post-build verification.
Why did review pass?
Because in source, only a variable name crossed the diff. Substitution happens later, alone.
Run a free scan at keydrift.dev/scan — paste a URL or the bundle source itself, no account. Findings arrive masked, with the exact chunk they live in.
Related
KeyDrift is an independent product and is not affiliated with, endorsed by, or sponsored by Cursor. The name is referenced descriptively.