Sovra Recon·Glossary · Secret Leak

Secret Leaks: API Keys and Tokens Exposed in Code

By Solan Barlet, co-founder of Sovra Recon
Updated October 29, 2026

In short

A secret leak occurs when an API key, access token, password, or private key ends up where a third party can read it: source code, Git history, public repository, exposed configuration file, mobile app, or JavaScript sent to the browser. These secrets often grant direct access to a database, cloud service, or payment account, without any vulnerability to exploit. The only secure course of action is to revoke and replace the secret, not just remove it from the code.

Where Secrets Leak

  • Git history: Removing a secret from a new commit does not erase it from previous commits.
  • Public repositories, or private repositories accidentally made public, and developers’ forks.
  • Code sent to the browser: a key placed in an exposed client-side environment variable ends up in the site’s JavaScript, where anyone can read it.
  • Files left behind on the web server: .env files, backups, and accessible .git directories.
  • Container images, CI/CD pipeline logs, and decompiled mobile apps.
  • Collaboration tools: tickets, messaging systems, and shared documents.

What an attacker does with it

Public code repositories are automatically scanned by attackers looking for known key formats. A cloud provider key can be used to read data, create resources at the victim’s expense, or establish a persistent presence; a payment or messaging API token enables direct fraud.

Prevent and Respond

  • Immediately revoke and replace any exposed secret, then check the logs to see if it was used.
  • Store secrets in a dedicated manager (secret vault) rather than in the code.
  • Enable secret detection on repositories and block commits that contain them.
  • Grant each key the minimum necessary permissions and a limited lifespan.
  • Never place a secret in client-side code, regardless of the framework.

Frequently asked questions

Is deleting the file from the repository enough?

No. The secret remains in the history and in copies that have already been made, and if it was ever made public, it could have been collected very quickly. It must be considered compromised and replaced.

Sources

Find out where an attacker would get in.

Our AI agents actually attack your scope, fully automated, and hand you the proof of every vulnerability.