Skip to main content
All posts

Which API keys are safe to put in a website?

Which keys are built to be public, a one-minute DevTools search for the rest, why to rotate first, and the VITE_ and NEXT_PUBLIC_ trap.

6 min readAPI keysSupabaseFirebaseEnvironment variables

Put only keys the provider built to be public in a browser: Supabase anon and publishable keys, and Firebase web config keys. Database rules decide what those keys can do. Secret keys, such as a Supabase service_role or secret key or a Gemini API key, must never reach a browser. If one did, rotate it first, then clean up.

Which keys are meant to be public?

A key is meant to be public when the provider says so in its docs and something else, usually database rules, controls what the key can do.

KeyWhat the docs sayWhere it can live
Supabase anon key (legacy, starts eyJ)Low privilege, maps to the anon and authenticated roles [1]Browser or app, with Row Level Security on
Supabase publishable key (sb_publishable_...)The newer replacement; "Safe to expose online" [1]Browser or app, with Row Level Security on
Firebase web API key"OK to include in code or checked-in config files"; it identifies the project, and access is enforced by Security Rules and App Check [3]Browser or app, with Rules written properly

Which keys must never reach a browser?

Supabase puts it bluntly: "Never use a secret key in the browser or expose it to customers." [2]

KeyWhat the docs sayWhere it can live
Supabase secret key (sb_secret_...)Elevated privilege; "A secret key bypasses every Row Level Security policy you have" [1]Server only
Supabase service_role key (legacy, starts eyJ)Same elevated role as the secret key [1]Server only
Gemini Developer API keyShould "never be included in your code or configuration files" and must not be on a publicly accessible key [3]Server only
Any key your provider calls secret, private, or "server"Read the provider's docs for that keyServer only

For a provider not listed here, such as a payment, email or AI service, open its docs and look for the words "publishable" and "secret". If a key can spend money or read private data, treat it as secret.

Watch out: two Supabase keys look the same

A legacy anon key and a legacy service_role key both begin with eyJ, so the first characters won't tell you which is which. Open Supabase, Settings, API Keys, and compare the key in your site with the entries there. Supabase says the newer secret and publishable keys are short strings, not JWTs. So if your site shows an eyJ value, it is a legacy key, and you need to find out which one. [1]

How can I search my site for a leaked key in one minute?

You do not need to read code.

  1. Open your live site in Chrome. Press F12 (Windows) or Cmd+Option+I (Mac).
  2. Open the Sources tab, then press Ctrl+Shift+F (Windows) or Cmd+Option+F (Mac) to search all loaded files.
  3. Search for service_role, then sb_secret_, then secret, then private key, then password.
  4. Search for eyJ. Each hit is a Supabase legacy key or another token. Check each one against Settings, API Keys.
  5. Any hit you recognize as a provider's secret key is a finding. Don't paste it into a chat tool or an online decoder.

A search finds only what is loaded on that page, so click through the main pages and repeat. A clean search does not prove there is no secret anywhere in the app.

What do I do first if a secret key was in the page?

Rotate before you clean up. Assume a key in a public bundle or a public repo has been copied. Deleting it from the code does not make the copy stop working. GitGuardian's 2026 report says 64% of credentials that were valid in 2022 were still valid in January 2026. [5]

  1. Create a new key in the provider's dashboard. In Supabase, new secret keys are made under Settings, API Keys, and Supabase says legacy keys "stay valid until you disable them". [1]
  2. Put the new key in server-side settings only (environment variables on your host, edge function secrets), then deploy.
  3. Disable the old key. This is the step that ends the exposure.
  4. Check the provider's logs and billing for use you do not recognize. For a database key, review what the key could read and treat that data as read.
  5. Then remove the key from code and from Git history, and add a scan or hook so it does not come back.

Keep the two cases apart. In the Moltbook case, the key in the page was a public sb_publishable_ key and the database had no Row Level Security. That is a rules problem, not a leaked secret key. [4]

For scale, GitGuardian counted 28,649,024 new secrets in public GitHub commits in 2025, 1,275,105 of them AI-service secrets. It also said commits co-authored by Claude Code leak secrets at about twice the baseline. That covers public GitHub only, and GitGuardian, which sells secrets-detection tools, points out that the developer controls every commit. [5]

For developers: why VITE_, NEXT_PUBLIC_ and EXPO_PUBLIC_ matter

These prefixes mean "put this in the browser bundle".

An AI coding tool will sometimes add the prefix to make an error go away. A prefix on a secret is the leak. Names to review in .env, hosting settings and code:

bash
grep -rEn "(VITE|NEXT_PUBLIC|EXPO_PUBLIC)_[A-Z0-9_]*(SECRET|SERVICE_ROLE|PRIVATE|PASSWORD|TOKEN)" .env* src app 2>/dev/null

And what actually shipped:

bash
grep -rEl "service_role|sb_secret_" dist build .next/static 2>/dev/null

For a secret key, use a server-only variable (no prefix). Call the provider from a server route, edge function or serverless function, and send the browser only the result. Next.js freezes NEXT_PUBLIC_ values at build time, so changing one needs a rebuild. [7]

For Supabase, the browser should hold only the publishable (or legacy anon) key, plus Row Level Security. See the Supabase anon key page. For Firebase, see rules that check only that someone is signed in.

ShipSafe scans a GitHub repo for keys in the wrong place and other issues, in plain English with the file and the line. Plans and what they include are on the pricing page. https://ship-safe.co

Sources

  1. Supabase docs, API keys: https://supabase.com/docs/guides/api/api-keys (checked 2026-11-20)
  2. Supabase docs, Row Level Security: https://supabase.com/docs/guides/database/postgres/row-level-security (checked 2026-11-20)
  3. Firebase docs, "Learn about using and managing API keys for Firebase": https://firebase.google.com/docs/projects/api-keys (checked 2026-11-20)
  4. Wiz, "Exposed Moltbook database reveals millions of API keys" (a public sb_publishable_ key plus missing Row Level Security): https://www.wiz.io/blog/exposed-moltbook-database-reveals-millions-of-api-keys (published about 2026-02-02; checked 2026-11-20)
  5. GitGuardian, "The State of Secrets Sprawl 2026" (covers 2025 data; public GitHub only; page has no publication date, reported about 2026-03-17): https://www.gitguardian.com/state-of-secrets-sprawl-report-2026 (checked 2026-11-20)
  6. Vite docs, Env Variables and Modes: https://vite.dev/guide/env-and-mode (checked 2026-11-20)
  7. Next.js docs, Environment Variables (page last updated 2026-08-25): https://nextjs.org/docs/app/guides/environment-variables (checked 2026-11-20)
  8. Expo docs, Environment variables: https://docs.expo.dev/guides/environment-variables/ (checked 2026-11-20)

Questions and answers

Is a Firebase API key a secret?
No. Firebase's docs say API keys for Firebase services only identify your project and app, and are OK to include in code or checked-in config files. Firebase Security Rules control access to Realtime Database, Firestore and Storage, and App Check covers supported APIs. So your rules are the real control. Other Google keys, such as a Gemini Developer API key, are different and must stay on a server.
Can I hide an API key in my .env file?
A .env file keeps a key out of Git, not out of the browser. If the variable name carries a prefix such as VITE_, NEXT_PUBLIC_ or EXPO_PUBLIC_, the build tool copies the value into the code sent to visitors. Name secrets without that prefix, read them only in server code, and give the browser the provider's public key or the server's response.
I pushed an API key to GitHub. What should I do first?
Rotate it before anything else. Create a new key, put it in server-side settings, deploy, and disable the old key. Deleting the commit does not help, because the old key may already have been copied. [GitGuardian reported](https://www.gitguardian.com/state-of-secrets-sprawl-report-2026) that 64% of credentials valid in 2022 were still valid in January 2026. Then check the provider's logs for use you do not recognize.
How do I tell whether the key in my website is the dangerous kind?
Compare it with your provider's dashboard. For Supabase, a legacy anon key and a legacy service_role key both start with eyJ, so open Settings, API Keys and match the value. Keys starting with sb_secret_ are secret keys, and sb_publishable_ keys are public. If the provider calls a key secret, private or server, it never belongs in a website.
Is it fine to call the Gemini or OpenAI API straight from my frontend?
For Gemini, no. Firebase's docs say a Gemini Developer API key must not be in your code or configuration files, and must not be allowed on a publicly accessible key. The same reasoning applies to any key that can spend money or read private data. Put a small server function in between, and let the browser call that function instead of the provider.

You just read what AI builders ship. Now check yours.

Paste your GitHub URL. 2 minutes. You get the findings in plain English, and the report says what it could not check. Free, no card.

Scan My App Free