Secrets Sprawl: Stop Leaked API Keys in Code
Secrets sprawl is the spread of API keys and tokens across code, chat tools, and build systems, where they stay valid after they leak. GitGuardian counted 28.65 million new secrets in public GitHub commits in 2025. A vault, push-time scanning, and short-lived credentials cut that exposure, since a key that never sits in code cannot leak from it.
By Abdullah Shafique, AI Engineer
Why are leaked secrets still so common?
Leaked secrets are still common because software ships faster than credential hygiene keeps up. GitGuardian's State of Secrets Sprawl 2026 report, covering 2025, found 28,649,024 new secrets in public GitHub commits in 2025, a 34% rise on the year before and the largest single-year jump the report has recorded. Since 2021, leaked secrets have grown 152%, while the public developer population grew 98%, so secrets are leaking about 1.6 times faster than the developer population is growing.
Artificial intelligence tooling added a new layer to the same pattern. The same report counted 1,275,105 secrets for AI services exposed in 2025, up 81% on 2024. Twelve of the fifteen fastest-growing leaked secret types were AI services. Commits co-authored by Claude Code leaked secrets at roughly twice the baseline rate across public GitHub, at about 3.2% against a 1.5% baseline. Speed alone does not explain every leak, since the report notes that less experienced developers may ignore warnings or prompt tools to include sensitive information. The practical point for a buyer is that AI-assisted coding raises the volume of code that needs a credential check, and checks that only cover familiar token formats will miss the newer AI service keys.
Where do secrets leak beyond code?
Secrets leak beyond code more often than many teams assume. GitGuardian's 2026 report found that about 28% of incidents originate in collaboration and productivity tools, outside code repositories, where credentials can reach broader audiences, automations, and AI agents. Only 4% appear in both code and those tools. The report also found that collaboration tool incidents are more severe, with more than half classed as critical.
Internal repositories hold a larger reservoir than public ones. The report found that internal repositories are six times more likely than public ones to contain hardcoded secrets: 32.2% of internal repositories contain at least one secret, against 5.6% of public repositories. Configuration files add another path. GitGuardian found 24,008 unique secrets exposed in Model Context Protocol configuration files, with Google API keys at 19.2% and PostgreSQL database connection strings at 14% of the valid unique secrets found there. A team that scans only its main code branch will miss chat exports, ticket attachments, and configuration files.
Why do old leaked keys stay dangerous?
Old leaked keys stay dangerous because rotation keeps getting deferred. GitGuardian tracked valid secrets detected in 2022 and found that 64% were still active and exploitable four years later, in 2026. The report points to rotation risk as the cause: teams avoid rotating secrets because they fear breaking production, so they leave the key in place. Long-lived secrets dominate the policy picture, accounting for 60% of policy breaches in the report, with internally leaked secrets at 17% and duplicated secrets at 16%.
GitHub's own data tells a similar story about slow cleanup. In an October 2026 post, GitHub reported that the mean time to manually revoke a secret hovers around 40 days, and roughly one in five took more than 90 days. GitHub also reported that a new secret appears in publicly visible code about once every two seconds, and that push protection stops about 30% of newly detected secrets before they enter repository history, with the remaining 70% found after the credential is already exposed. Eric Fourrier, chief executive officer at GitGuardian, put the laptop side of the risk in plain terms: "AI agents need local credentials to connect across systems, turning developer laptops into a massive attack surface." That sentence comes from GitGuardian's March 2026 release of the same report, linked below. When a key stays valid for months, the window for abuse is measured in months as well.
Which secrets controls work best?
The controls that work best remove secrets from code, block them at push time, and shorten their life. A vault on its own helps, since developers stop copying keys into files, yet a vault without scanning still leaves old keys in history. Scanning on its own helps, since it finds leaks, yet scanning without automated rotation still leaves a valid key in place for weeks. The combination matters, and the table below compares four common setups.
| Setup | What it does | Main limitation | Best fit |
|---|---|---|---|
| Hardcoded keys in code | Lets any developer paste a key where it is needed | Keys enter history, forks, and exports | No team; retire this pattern first |
| Vault with manual rotation | Stores keys in one place and issues them on request | Rotation still depends on a person remembering to act | Small teams starting a secrets program |
| Vault plus push-time scanning | Blocks recognised keys before they enter history and finds older leaks | Generic passwords and custom tokens can slip past pattern checks | Teams shipping code daily through GitHub |
| Vault plus scanning plus short-lived credentials | Issues credentials that expire, scans code and chat tools, and rotates on leak | Needs identity work and platform support up front | Teams running SaaS, cloud, and AI workloads at scale |
Short-lived credentials change the economics of a leak. A key that expires in hours limits what an attacker can do with it, even when detection lags. GitHub's October 2026 post describes a newer classifier that assesses candidate secrets in context and could more than double the number of secrets prevented at push time. That kind of prevention helps with generic secrets, which lack a recognisable token format and made up a large share of the problem in earlier GitGuardian reports. Prevention still needs a response plan, since about 70% of newly detected secrets reach history before they are found, according to GitHub's figures.
How should a team respond to a leaked secret?
A team should respond to a leaked secret by revoking it first and investigating second. Revocation stops the exposure, while an investigation that runs before revocation leaves the key usable throughout. After revocation, the team should issue a replacement through the vault, check logs for use of the old key, and search forks, exports, and chat tools for copies. Deleting a commit does not remove a key from every copy, so the search has to cover every place the string may have travelled.
Ownership makes that response repeatable. Every secret needs a named team, a purpose, and an expiry or review date, so rotation does not depend on the person who created it remembering to act. Our guide to non-human identity security covers the same ownership idea for service accounts and automation tokens, which are the identities most leaked keys belong to. Our guide to privileged access management covers time-bound admin access, which pairs with short-lived credentials to limit what a stolen key can reach. Together, those controls turn a leak from a standing credential problem into a bounded incident with a known owner and a known expiry.
Frequently asked questions
What is secrets sprawl?
Secrets sprawl is the spread of API keys, tokens, passwords, and certificates across code, chat tools, configuration files, and build systems, without a single inventory, owner, or expiry date for each one.
How many secrets leaked on public GitHub in 2025?
GitGuardian counted 28,649,024 new secrets in public GitHub commits in 2025, a 34% rise on 2024, in its State of Secrets Sprawl 2026 report.
How many AI-service secrets leaked in 2025?
GitGuardian counted 1,275,105 secrets for AI services exposed in 2025, up 81% on 2024, with twelve of the fifteen fastest-growing leaked secret types tied to AI services.
How long do leaked secrets stay valid?
GitGuardian found that 64% of valid secrets detected in 2022 were still active in 2026, and GitHub reported a mean manual revocation time of around 40 days in October 2026.
What stops secrets sprawl most reliably?
A vault, push-time scanning, and short-lived credentials together stop the most leaks, since the vault removes keys from code, scanning blocks and finds the rest, and short expiry limits the damage from any key that still slips through.
Which leaked key in your own stack would cause the most damage if it stayed valid for 40 days, and what would it take to shorten its life to hours? Share your approach in the comments, including which control broke first when you tried it. Use the share buttons below if this checklist helps your team plan its next step.

Comments
Post a Comment