Detect new secrets in GitHub by using secret scanning on commits, pull requests, and repository history, then alerting when credentials, tokens, or keys appear. Supplement that with reviews of dependency files, workflow files, and configuration changes that often introduce secrets indirectly. Any confirmed secret should be rotated and the commit history checked for additional exposure.
What “new secrets” in GitHub usually means in practice
“New secrets” is not just a hardcoded password committed directly to a repository. In GitHub, they can arrive in source files, pull requests, commit history, workflow YAML, dependency manifests, build scripts, or generated artifacts. Detection works best when you treat secret discovery as a repository-wide control problem, not a single scan on the latest branch tip.
For teams running GitHub at scale, the practical question is whether you can see secrets before they become reachable by other users, forks, or automation. That is why the relevant surface includes commits, pull requests, repository history, and the workflow or configuration changes that often introduce a secret indirectly.
GitHub-native detection is strongest when paired with review of where secrets tend to appear accidentally. The most common pattern is not a developer intentionally adding a credential, but a secret being copied into a config file, test fixture, CI variable reference, or action workflow during a change that otherwise looks ordinary.
How detection works across commits, pull requests, and history
Secret scanning is the main detection mechanism because it can inspect new content as it is created, then alert when it matches credential-like patterns or known secret formats. In GitHub, that means you want coverage for commits, pull requests, and retained repository history so a secret is caught even if it was added and removed quickly.
That history matters because the exposure may persist after the visible branch tip has been cleaned up. If a secret was committed and later deleted, the repository history can still contain the sensitive value unless the history is rewritten or the secret is otherwise invalidated. For that reason, detection should not stop at the current state of the default branch.
Workflow files and dependency files deserve separate attention because they are common entry points for credential leakage. A workflow may reference a secret by name, but a misstep in templating, debugging output, or copied environment variables can still expose the underlying value. Dependency manifests can also introduce tokens indirectly through package registries, private sources, or generated lockfile content.
GitHub and GitHub Actions also deserve a broader repository-security view because secrets often interact with automation, not just code. The GitHub and GitHub Actions Security Guide is useful when you need to connect secret detection to workflow permissions, runner exposure, and action hardening.
What to do when a secret is found
Detection only matters if it triggers a fast containment path. Once a secret is confirmed, the first step is rotation or revocation, because the key question is not whether the value was committed intentionally, but whether it can still authenticate or authorize anything useful. If the secret is valid, assume exposure until the issuing system proves otherwise.
After rotation, check whether the secret appeared anywhere else in the repository, forks, mirrors, release assets, or logs. A single finding can indicate a broader secret-sprawl problem, where the same token or credential was reused across files or environments. The Guide to the Secret Sprawl Challenge is a good reference point for understanding why one leak often leads to several more.
For API keys and similar bearer credentials, revocation and replacement should be treated as the default response, not an optional follow-up. The API Key Management Guide covers the lifecycle decisions that matter once a key has left the intended trust boundary.
Risk and Threat Considerations
Secrets in GitHub are high-risk because repository access often exceeds the intended scope of the credential itself. A leaked token can outlive the commit that exposed it, be copied into forks or clones, and be consumed by automation before the leak is noticed.
Failure mechanism: A secret is introduced in code, workflow, or generated content, then becomes reachable through commit history, pull requests, logs, or downstream automation before detection and rotation complete.
Impact: Attackers or insiders may gain unauthorized access to cloud resources, CI/CD systems, registries, APIs, or internal services, and the same secret may continue to be reused elsewhere if the cleanup stops at the first alert.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 and OWASP API Security Top 10 address the attack and risk surface, while CIS Controls v8 and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | GitHub secret detection is fundamentally about finding exposed credentials before misuse. |
| NHI-07 — Long-Lived Secrets | Repository secrets become dangerous when they remain valid after exposure in history or logs. | |
| Recommendation — Scan repositories and workflows for leaked secrets, then rotate or revoke any exposed credential immediately. Replace long-lived secrets with short-lived credentials and revoke anything committed to Git history. | ||
| CIS Controls v8 | CIS-16 — Application Software Security | Secret scanning in repositories is a software-security safeguard that prevents credential exposure in code and config. |
| Recommendation — Integrate secret scanning into development workflows and block releases when exposed credentials are found. | ||
| OWASP API Security Top 10 | API2 — Broken Authentication | Leaked tokens and keys in GitHub can directly break authentication to APIs and services. |
| Recommendation — Review API credential handling in repositories and revoke any token exposed through source control. | ||
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | The issue centers on detecting, rotating, and retiring exposed secrets that authenticate access. |
| Recommendation — Enforce credential lifecycle controls so exposed authenticators are rotated and revoked quickly. | ||
Practitioner Guidance
What to verify: Confirm that secret scanning covers the paths where secrets actually appear in your repos, including pull requests, historical commits, workflow files, and generated configuration. If your process only scans the latest branch state, it will miss real exposure paths.
Decision rule: If the detected value can still authenticate, treat it as a live incident and rotate it first; only after that should you investigate how it got in and whether history still contains copies. If the secret is already invalid, focus on exposure extent and search for additional instances.
Practitioner takeaway: The important judgement is to treat secret detection as an exposure workflow, not a search problem, because the value of the control comes from fast invalidation, history review, and follow-on cleanup.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 20, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org