Leaked API keys: how to find them in your app and what to do next

Keys end up in browser code, mobile apps and Git history more often than founders think. Here is where to look, how to rotate safely and how to stop it happening again.

Assume a key is leaked if it has ever been in your front-end code, your mobile app or a Git commit. Anyone can read a website's JavaScript or unpack a mobile app, and deleting a key from the code does not remove it from history. The fix is the same every time: rotate the key, move it to a server and add a check that stops it coming back.

How common are leaked keys?

  • 28.65 million new secrets were pushed to public GitHub in 2025, up 34% in a year, according to GitGuardian's State of Secrets Sprawl 2026. Secrets for AI services rose 81%, to about 1.28 million.
  • Old keys keep working. GitGuardian found that over 64% of credentials confirmed valid in 2022 still worked when retested in January 2026.
  • 282 of 444 iPhone apps with AI features exposed credentials or backend access in a Wake Forest University study reported by Help Net Security in June 2026. Fifty-four of them exposed plain API keys.

Where do keys usually leak?

  • Browser code. Any variable your front end can read ends up in the JavaScript that visitors download. In Vite apps that means anything starting with VITE_. In Next.js, anything starting with NEXT_PUBLIC_.
  • Mobile apps. Keys compiled into an iOS or Android app can be pulled out of the download.
  • Git history. A committed .env file stays in every earlier commit, even after you delete it.
  • Logs and error messages. Keys printed while debugging end up in tools other people can see.
  • Chats and tickets. Keys pasted into an AI tool, a support ticket or a team chat.

Which keys can be public?

Some keys are designed to be seen: a Stripe publishable key (it starts with pk_), a Supabase anon key protected by row level security, or a maps key restricted to your domain. Others must never leave a server: Stripe secret keys (sk_), the Supabase service role key, database passwords and any AI provider key. If you are unsure, treat it as secret.

Find leaked keys free

SIGSHIP checks your code and Git history for secrets, on your own computer. Free and open source.

Try SIGSHIP

How do you find leaked keys?

  • Search the live site. Open your site's JavaScript files in the browser and search for prefixes such as sk_, service_role and your AI provider's key format.
  • Search your history. Scanners such as gitleaks or trufflehog read every past commit, not just the current code.
  • Check your providers. Usage dashboards show spikes you did not cause.

SIGSHIP checks the code for you: live secrets, a committed .env, server secrets with browser-visible names and AI keys in the browser. npx sigship history finds secrets committed in the past, even if they were removed later. It runs on your computer and uploads nothing.

What should you do when you find one?

  • Create a new key first. Deploy it to your server environment.
  • Then revoke the old key. In that order you avoid downtime.
  • Move the call to a server. If the browser needed the key, put a small server function in between and call that instead.
  • Check usage and bills. Look for activity from before you rotated.
  • Clean the history second. Rewriting Git history is worth doing, but the key may already be copied. Rotation is what protects you.

How do you stop it happening again?

  • Add a pre-commit check. npx sigship init --hook blocks a commit that adds a secret, in well under a second.
  • Keep .env in .gitignore from the first commit.
  • Set spending limits with every AI and cloud provider.
  • Give each environment its own keys, so a leaked test key never touches production.

For the full launch list, including payments and database rules, read our 8 checks before you launch.

Questions

What happens if my API key is leaked?

Anyone holding it can use the service as you, which can mean charges on your account, access to your data or both. Rotate it immediately and check usage.

Does deleting a key from GitHub fix a leak?

No. The key remains in earlier commits and may already have been copied. Rotate the key. Cleaning the history is a secondary step.

Is it safe to put an OpenAI or Anthropic key in a front-end app?

No. Call AI providers from a server function, keep the key there and add a per-user rate limit.

How do I check my Git history for secrets?

Use a secret scanner that reads every commit, such as gitleaks, trufflehog or npx sigship history.

Which keys are safe to expose in the browser?

Keys designed to be public, such as a Stripe publishable key or a Supabase anon key protected by row level security. Secret keys, service role keys and AI keys are not.

Have an idea? See what it would take to build it.

The Idea Lab turns a two-sentence idea into a build plan: why it could work, what to get right first, the first version worth building and its price. Two minutes, from our published rates.

Open the Idea Lab

Next: What does a senior developer really cost in 2026?

Tell us what you're building.

Thirty minutes with a senior engineer. You leave with a plan and a price, whether or not you work with us.

Book a callGet your price