What Is Secrets Scanning, and How Does It Find Leaked Credentials? (Explained Clearly)
Learn how secrets scanning finds leaked credentials in code and Git history, how push protection helps block leaks, and why revoking exposed keys matters.
👉 Master your Security+ skills with Pluralsight here: Pluralsight
You’ll learn how secrets scanning detects exposed API keys, passwords, and private keys in code and Git history. Find out how push protection helps prevent leaks and why revoking or rotating a credential matters more than just deleting it from the code.
Chapters: 0:00 Intro 0:14 What does secrets scanning actually find? 0:59 Why can a deleted secret still show up in a scan? 1:36 How do secret scanners spot and block leaks? 2:35 What should you do when a scanner finds a secret? 3:37 Outro
Affiliate notice: Some links may earn a commission. Thanks for your support.
Key Takeaways
Secrets scanning finds exposed credentials such as API keys, passwords, access tokens, and private keys in source code, Git history, and other locations the tool covers.
A clean scan doesn’t prove there are no leaks. Scanners use patterns, context, and randomness to flag likely secrets, but they can miss unsupported formats or locations outside their scope.
Push protection can stop leaks before they reach a shared repository. It can block supported credentials in outgoing commits, while historical scans can find secrets deleted from current files.
Revoke or rotate exposed credentials at the source. Deleting a secret or rewriting Git history doesn’t invalidate it or erase copies in forks and clones. Review audit logs for unexpected use.
Use a secrets manager, least-privilege permissions, and short-lived credentials to keep secrets out of code and limit the damage if one leaks.
👉 Put your cybersecurity knowledge into practice with Pluralsight through guided labs, feedback, and practice exams.
Secrets scanning automatically checks source code, Git history, and other supported locations for exposed credentials, such as API keys, passwords, access tokens, and private keys. It can catch a mistake before it reaches a shared repository or uncover an old leak after the code has changed. The distinction matters: deleting a credential from code does not stop it from working. Revoking it does.
What does secrets scanning find?
In cybersecurity, a secret is a sensitive value that software or people use to authenticate, access a service, or sign data. Common examples include database passwords, API keys, access tokens, private keys, and connection strings that contain credentials.
A is the credential itself written directly into source code, a configuration file, or another project artifact. By contrast, tells the application where to fetch a password without putting the password in the file. A vault, also called a secrets manager, supplies credentials to authorized applications.
FAQ
Quick answers to the questions people usually ask about this topic.
Should you scan private repositories for secrets?
Yes. A private repository restricts who can see the code, but it doesn’t control who can use a credential copied from it. When enabling secrets scanning on an existing private repository, include Git history so you can catch credentials that no longer appear in the current files.
Does adding .env to .gitignore remove secrets from Git?
No. .gitignore helps keep an untracked .env file out of future commits, but it doesn’t stop Git from tracking a file it already tracks or remove past commits. If the file was committed, stop tracking it and revoke or rotate any credentials that may have been exposed. Commit a .env.example file with placeholders if teammates need a configuration template.
How should you handle a secrets scanning alert for a test fixture?
Confirm with the fixture owner that the value is deliberately fake and was never issued by a real service. If it’s harmless, use a clearly fake placeholder where the test allows it, or document a narrow exception for that fixture. Don’t suppress alerts for an entire directory to silence one finding.
How do you choose a secrets scanning tool for your repository?
Check whether it recognizes credentials from the services you use, supports custom detection rules if you have internal token formats, and covers the locations you care about. Look for both historical scanning and push protection if you need to find old leaks and block new ones. Also check who receives alerts and whether the tool masks credential values.
Can you close a secrets scanning alert if the credential is already revoked?
A confirmed revocation addresses the risk of future use, but it doesn’t tell you whether the credential was used before then. Verify its status with the issuing service, review available audit logs for the exposure window, and document what you found before closing the alert.
How can I practice responding to security alerts after learning about secrets scanning?
If you’re ready to apply the concepts, try guided cybersecurity labs on Pluralsight. The platform offers hands-on practice and feedback, plus assessments and practice exams to help you identify gaps and focus your certification prep.
Some links may earn a commission. Thanks for your support.
Watch in the video playerOpen the dedicated player for this video.
hardcoded secret
password = read_from_vault("orders-db")
The impact of a leak depends on what the credential can do. A read-only database password could expose records, while a deployment token with write access could let someone change production systems. The potential extent of the damage is called the blast radius. Permissions, the resources the credential can access, and how long it remains valid all affect that radius.
Why can a deleted secret still show up in Git history?
A Git repository stores project files and their version history. A commit records a change, and a push sends commits to a remote repository. If one commit adds a password and the next removes it, the latest version looks clean, but the earlier commit still contains the password. A scanner that checks Git history can find it there.
If the repository was public, someone may already have copied the credential. Making the repository private or rewriting its history does not erase independent copies in forks or clones. A private repository limits who can see the files, but it is not a vault. If a credential was exposed, changing the repository does not change whether the issuing service still accepts it.
How does secrets scanning detect leaked credentials?
A scanner first checks a defined scope, such as files staged for a commit, commits in a proposed change, or available repository history. It then looks for signals that a value might be a secret.
Detection method
What it looks for
What it cannot establish
Pattern matching
A known structure, such as a provider-specific token format or a private-key header
Whether the value is real or active
Context clues
A nearby label like password or token, or a relevant file path
Whether the value is a credential or just a test placeholder
Entropy analysis
A string that looks unusually random
Whether the string is a secret rather than, for example, a checksum
Validity checking
Whether a detected credential is active or inactive, when the platform or issuer supports the check
Whether anyone used it or whether it was active when first exposed
A scanner can flag a harmless test value, producing a false positive. It can also miss a real credential, producing a false negative, if the format is unsupported or the relevant file or commit is outside the scan’s scope. A genuine token that has since been revoked is not a false positive: it may still be evidence of an earlier exposure.
Where does push protection fit?
The point at which scanning runs determines whether it can prevent a leak or only alert you after the fact.
Scan point
What it helps catch
Before a commit
A local pre-commit check can flag a staged .env file containing a password before it enters Git history.
During a push
Push protection can block a supported credential before the outgoing commits reach the remote repository.
During code review or CI/CD
An automated check can flag a secret before a change is merged, even though the commit may already be on the remote.
Across Git history
A historical scan can find credentials in older commits, even when the current files are clean.
Push protection can catch a token in an earlier outgoing commit even if a later commit in the same push deletes it, provided the tool covers that token type and those commits. But blocking a push does not revoke the credential or establish that it was never shared elsewhere. Check what the tool actually scans: Git coverage does not automatically extend to build logs, container images, or issue comments.
What should you do when a scanner finds a secret?
Triage the alert without sharing the value. Identify the credential type, owner, issuing service, and where it appeared. Estimate when it was first exposed. Keep the raw value out of tickets, chat messages, and logs.
Revoke or rotate it at the source. If the credential may still be active and was exposed, don’t wait for proof of misuse. Revocation invalidates it at the issuing service. If an application still depends on it and immediate revocation would cause an outage, coordinate a rotation: put the replacement into use, then promptly revoke the old value.
For example, suppose a team finds a production database password in an old commit. The current application already fetches its password from a vault, but the exposed password was never retired. The team checks which services still depend on the old password, replaces and invalidates it, then reviews database access logs. Moving to the vault fixed how the application gets its password. Invalidation addressed the risk from the old one.
If you encounter a suspected secret in someone else’s repository, report its location privately through the project’s disclosure process. Public visibility is not permission to test or use the credential.
How secrets scanning fits into repository security
Secrets scanning and secrets management solve different problems. Scanning finds credentials that ended up where they shouldn’t. Secrets management controls how authorized applications obtain them. Least-privilege permissions limit what a leaked credential can do, and short lifetimes limit how long it can be used. Moving a password into a .env file is not enough if that file is still committed or the password gets printed in a build log.
Scanning for secrets is also different from static application security testing (SAST), which looks for insecure code patterns, and software composition analysis (SCA), which examines dependencies for issues such as known vulnerabilities. A clean result from one check does not replace the others.
Practice responding to security alerts
Understanding what an alert means is one thing; deciding what to do next takes practice. Pluralsight offers guided cybersecurity labs and feedback, plus assessments and practice exams to help you spot gaps and focus your certification prep.
Review audit logs for unexpected activity. Check what the credential could access and review relevant provider or service logs from the earliest known exposure through containment. The scanner tells you where the value appeared; audit records can help determine whether it was used.
Clean up copies you control and prevent a repeat. Remove the value from active files and affected outputs. Consider whether rewriting history is worth the disruption, knowing it cannot erase independent copies. Have the application retrieve credentials from a secrets manager or use short-lived credentials where supported.
Affiliate link — I may earn a commission at no additional cost to you.
Jay's Recommendation
Turn understanding into hands-on confidence
You've built the foundations. Pluralsight adds opportunities to practice in guided security labs, get feedback, and check your knowledge with assessments and practice exams, so your next step is more than another video.
🛠Put concepts to workBuild practical skills with guided security labs and feedback.
🎯Find your weak spotsUse assessments to focus on what needs more work.
📝Check your understandingUse practice exams to guide your certification preparation.
🧭Give study sessions directionOrganize further learning with curated paths and progress tracking.