Secrets Committed to Source Control
Passwords, API keys, tokens or private keys are stored in a source code repository or its history, where anyone with read access to the repository can use them.
| Severity | High |
| CVSS 3.1 | 8.1 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N Open in the calculator |
| CVSS 4.0 | 8.6 CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-540: Inclusion of Sensitive Information in Source Code |
| OWASP Top 10 | A01:2025 Broken Access Control |
| MITRE ATT&CK | T1552.001 Credentials In Files, T1213.003 Code Repositories, T1078 Valid Accounts |
| Category | Information Disclosure |
Description
Credentials have been committed to a source code repository: for example database passwords in configuration files, cloud access keys, API tokens, private keys, or .env files holding the application's secrets. Anyone who can read the repository, including every developer, contractor and integrated service with access to it, can therefore read the secrets, whether or not their role needs them. An attacker who obtains read access, through a compromised developer account, a leaked access token, an insider, a third party with access or the repository being made public, gains every secret in it at once.
Depending on what the secrets unlock, they may give direct access to production databases, cloud accounts, payment or messaging services and other internal systems, often with the broad privileges that service accounts tend to hold, and without passing the controls that protect user sign-in, such as multi-factor authentication. The exposure is greatest for long-lived credentials to production systems, and lower where the secrets are for test environments or have already been revoked.
Removing a secret in a later commit does not remove it from the repository. It stays in the commit history, in other branches and tags, in forks and clones, and in copies held by build systems, until the history is rewritten everywhere. Secrets in a repository that is, or has ever been, public must be assumed to have been collected, as public repositories are scanned continuously for credentials.
The weakness is identified by scanning the full history of each repository with tools such as gitleaks or TruffleHog, or with the hosting platform's secret scanning, and by reviewing configuration files, deployment scripts and infrastructure templates. Each secret found is then checked to see whether it is still valid. This finding concerns the repository itself; secrets embedded in code delivered to browsers or devices, and repositories exposed through a web server, are separate issues.
Remediation
Treat every committed secret as compromised, and move secrets out of source code:
- Revoke or rotate each exposed secret at its source first, then review the target system's logs for use of the old credential. Deleting the file or rewriting history does not make an exposed secret safe.
- Store secrets in a dedicated secrets manager, such as HashiCorp Vault, AWS Secrets Manager, Azure Key Vault or Google Cloud Secret Manager, or in the CI/CD platform's protected secret store, and have the application or pipeline retrieve them at run time. Prefer workload identities and short-lived credentials where the platform supports them.
- Keep local configuration files such as
.envout of the repository with.gitignore, and commit only templates with dummy values. - Enable secret scanning on the hosting platform, with push protection where it is available, and add a pre-commit hook such as gitleaks so that new secrets are blocked before they are pushed.
- Where history must be cleaned, for example before a repository is made public, rewrite it with a tool such as git filter-repo and have every clone and fork replaced. This is in addition to rotation, not instead of it.
Confirm the fix by rescanning the full history of every repository and checking that each secret found earlier has been revoked and no longer works.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.