Demo, all content is generated
Question

My service role key was in a public repo for 3 weeks, what do I do first?

Open · 642 views · asked by anouk · edited

Just found out my repo was public (thought v0 made it private). .env.local is not in there, but the AI hardcoded the Supabase service role key in lib/admin.ts. Three weeks. The app has about 200 users with names, emails and their journal entries.

I'm panicking a bit. Do I make the repo private first? Delete the file? Rewrite history?

What I’ve tried

Made the repo private 10 minutes ago. Haven't changed anything else yet because I don't want to break the app.

Comment
Rotate first, everything else after. Answer coming. lena_ops · edited

3 answers

lena_ops · edited

Order matters. Making the repo private doesn't help much; forks and scrapers already have it. Do this now:

  1. Rotate the key. In Supabase → Project Settings → API Keys. If your project uses the newer secret keys (sb_secret_...), create a new one and delete the old one. If it's the legacy JWT service_role key, you have to rotate the JWT secret; that also changes the anon key and logs everyone out, which is acceptable here.
  2. Update the app to use the new key from an env var (server-only), redeploy.
  3. Check for damage: Supabase logs (API/Postgres) for unusual queries from unknown IPs, row counts, deleted data.
  4. Then clean history (git filter-repo) mostly for hygiene.

The app will break for a few minutes between 1 and 2. That's fine.

Comment
Rotated, redeployed. App is back up. anouk · edited
Can't tell from the logs if anyone used it, the log retention on free is short. What now? anouk · edited
Found one weird request from an IP in the logs, a select on profiles. Writing it all down. anouk · edited
chidi_eze · edited

About not knowing: if you can't rule out access, many jurisdictions (GDPR in the EU for example) expect you to assess whether it's a reportable breach, and journal entries are sensitive. Not legal advice, but write down the timeline now (when public, when found, when rotated) while you remember it. You'll need it whatever you decide.

Comment
I'm in the Netherlands so yes GDPR. Writing it down. anouk · edited
ximena_c · edited

Also GitHub has secret scanning alerts; check the repo's Security tab. If a scanner partner notified GitHub, it may show there when it was detected.

Comment