Sub topic 1
Why Committed Secrets Are a Problem
Prerequisites
Assume you know how to commit and push with Git. You should also know that an API key, token, or password grants access to a service. GitHub repository settings and terminal commands will be used.
Why Committed Secrets Are a Problem
A committed secret is a credential stored in Git history. Even if you delete it in a later commit, the original value can remain in older commits, branches, forks, pull requests, caches, or clones.
Anyone who obtains the value may impersonate your application. They could read data, spend money, change infrastructure, or access customer systems. Treat every exposed credential as compromised until its provider confirms otherwise.
How Secret Scanning Works
Secret scanning searches repository content and history for strings that match known credential patterns. A detected match creates an alert for investigation. Push protection performs a related check earlier: it examines a proposed push and blocks it when it detects a likely secret.
What GitHub Recognizes: Provider Patterns and Secret Types
GitHub includes patterns for credentials issued by many service providers. A pattern can identify a provider prefix, expected length, and character format. Secret types describe what the detected credential represents, such as a cloud access key or an OAuth token.
Detection is not proof that a value works. It is a signal for triage. GitHub may also check whether supported credentials are active. You can add custom patterns for internal tokens that GitHub does not recognize.
The Partner Program: How Providers Learn About Leaked Tokens
In GitHub’s secret scanning partner program, participating providers receive information about exposed tokens. A provider can then revoke or rotate the credential. This response can reduce the time between exposure and invalidation, but you must still investigate the alert and confirm the credential’s status.
Turning On Secret Scanning and Push Protection
Enable both features in the repository’s security settings when your plan supports them. Organization policies can help apply the same baseline across repositories. The REST API can automate configuration:
gh api --method PATCH repos/OWNER/REPO \
-f 'security_and_analysis[secret_scanning][status]=enabled' \
-f 'security_and_analysis[secret_scanning_push_protection][status]=enabled'A blocked push should normally be fixed by removing the secret and using a safe runtime input, such as an environment variable. Bypass only when the value is demonstrably harmless and your organization permits that reason.
Exercise
Why does deleting a secret in a new commit not fully remediate it?
Show answer
Earlier commits may still contain the value, so the credential must be revoked or rotated and the history handled separately.