Sub topic 11
Validity checks: prioritizing active secrets
This chapter assumes you can read a secret scanning alert, know the difference between detection and push protection, and can run gh api commands. It covers what a validity check is, what the three statuses mean, and how to use them to order your triage work without trusting them too much.
Why validity matters
A repository with a long history can produce dozens or hundreds of secret scanning alerts. Many of them point to credentials that were revoked years ago, to test tokens, or to keys from a sandbox. A few point to live production credentials. If every alert looks the same, a team tends to work through them in the order the alerts appear, and the live credential can sit unrevoked for days.
A validity check answers one question: does the provider still accept this credential? GitHub asks the provider (or runs a provider-specific check) and records the result on the alert. You can then sort and filter by it.
What GitHub records
For supported provider patterns, each alert carries a validity value.
| Status | Meaning | What to do |
|---|---|---|
| `active` | The provider accepted the credential at the time of the check. | Treat as an incident. Revoke and rotate first. |
| `inactive` | The provider rejected the credential. It was probably revoked, expired, or deleted. | Verify it, then close the alert. Lower priority. |
| `unknown` | GitHub could not tell. | Treat as unverified. Check it yourself. |
A fourth case is easy to miss. If a pattern has no validity check, or the feature is off, the alert shows no status or unknown. Not every provider pattern is supported, and patterns that are not tied to one provider, such as generic passwords and your own custom patterns, are not checked against any provider.
The check is a snapshot. A credential that was inactive cannot normally become active again. An active one can become inactive after you revoke it, and GitHub re-checks active secrets periodically, so the status can lag behind what you did at the provider.
Turning validity checks on
Validity checks are a setting separate from secret scanning itself. In the UI, it is the option to automatically verify whether a secret is valid, found in the repository's code security settings. The feature is available for repositories that have the paid secret scanning product, so it may not appear on every repository.
You can set it through the REST API. As with other settings, you need admin access to the repository.
gh api --method PATCH repos/OWNER/REPO \
-f 'security_and_analysis[secret_scanning][status]=enabled' \
-f 'security_and_analysis[secret_scanning_validity_checks][status]=enabled'If the repository is not eligible, the API returns an error or the setting does not change. Read the response before assuming it worked. You can confirm by fetching the repository and looking at security_and_analysis:
gh api repos/OWNER/REPO --jq '.security_and_analysis'Organization owners can also enable the setting for many repositories at once through the organization's code security configuration, which is better than repo-by-repo changes for a large estate.
How the check fits the alert lifecycle
The order of work follows from that flow. Active alerts get immediate attention. Unknown alerts need a human to decide. Inactive alerts are cleanup.
Using validity in triage
The alert list API accepts a validity filter, so you can ask only for what needs urgent action.
gh api --paginate \
'repos/OWNER/REPO/secret-scanning/alerts?state=open&validity=active' \
--jq '.[] | {number, secret_type_display_name, validity, push_protection_bypassed, html_url}'To see how the backlog is distributed, count alerts by status. A missing value is printed as null.
gh api --paginate \
'repos/OWNER/REPO/secret-scanning/alerts?state=open' \
--jq '.[].validity' | sort | uniq -cA sensible order of work:
activealerts wherepush_protection_bypassedistrue. Someone chose to push this credential, and it still works.- Remaining
activealerts, newest first. unknownalerts for providers you actually use.inactivealerts, closed in bulk after a spot check.
Teams often add a second signal when ordering. For example, an active credential in a public repository is more urgent than one in a private repository, because anyone can read it and automated scrapers do.
Reading an `active` result correctly
active means the provider accepted the credential when GitHub checked. It does not tell you how much damage the credential can do. A token scoped to read one public resource and a token with administrator rights on a cloud account both show active. After you revoke it, look at the provider's audit logs to see what the credential could reach and whether it was used.
Revoking is the fix. Removing the file from the repository does not make an active credential safe, because the secret remains in Git history, forks, clones, and any cache that saw the push.
Reading an `inactive` result correctly
inactive is good news, but do not close the alert without thinking. There are several reasons the provider may reject a credential:
- You or the provider revoked it. This is the outcome you want.
- It expired through normal lifetime rules.
- It was never valid, for example a placeholder that matches the pattern.
- The check failed in a way that looked like a rejection, such as a network restriction at the provider.
The first three are fine to close. For the last, spot-check a sample with the provider before closing a large group. Pick the resolution reason that matches what happened, as covered in the triage chapter. For a credential you confirmed is revoked, use revoked:
gh api --method PATCH repos/OWNER/REPO/secret-scanning/alerts/42 \
-f state=resolved \
-f resolution=revokedIf it was a dummy value in a test file, use used_in_tests or false_positive instead. An accurate resolution keeps your reporting honest.
Treating `unknown` correctly
unknown is the largest category in most real repositories, and it is the one teams get wrong. It does not mean "probably fine". It means GitHub has no information. Common reasons:
- The pattern has no validity check.
- The provider's service was unreachable or rate limited the check.
- The credential type needs more context than GitHub has, such as a token that is only valid together with an account identifier.
- Validity checks were turned on after the alert was created, and the check has not yet run.
For unknown alerts from providers you use, test or revoke the credential through the provider's own console or API. If you cannot tell whether it works, rotate it. Rotation costs a little time. A live leaked credential costs far more.
Gotchas
- Checking is not blocking. Validity checks happen after detection. They do not affect push protection, and a push containing an inactive secret is still blocked in the same way.
- The status is a point in time. An alert listed as
activean hour ago may already be revoked. Check again before you act on a stale export. - Sending a secret to a provider is the point. GitHub contacts the provider with the credential to learn whether it works. If your compliance rules restrict that, review the feature before enabling it organization-wide.
- Custom patterns are not validated. Alerts from a custom pattern, such as
acme_[A-Za-z0-9]{32}, never get anactiveorinactiveresult from a provider, because there is no provider to ask. You must build your own check, for example a script that tests the token against your internal service. - Do not auto-close on
inactivealone. Automation that closes every inactive alert is fine only if you accept the failure case where the check wrongly rejected a live secret.
Summary of the working model
Validity checks add a provider-confirmed status to supported alerts. Use active to decide what to revoke first, treat unknown as unverified, and close inactive alerts after a spot check with an honest resolution reason. Combine the status with other signals such as repository visibility and whether push protection was bypassed.
Exercise
Your repository has 120 open alerts. A gh api count shows 4 active, 30 inactive, and 86 unknown. Half of the unknown alerts come from a custom pattern for an internal token. In what order do you work, and what do you do about the custom-pattern alerts?
Show answer
Start with the 4 active alerts: revoke and rotate each credential at its provider, check the provider logs for misuse, then resolve the alerts as revoked. Next, look at the unknown alerts from providers you use and verify or rotate them, since unknown means unverified. The custom-pattern alerts will never get an active or inactive result because there is no provider to check them, so test each token against your internal service yourself (or revoke it) and then resolve it. Finally, spot-check a sample of the 30 inactive alerts at the provider and close them with an accurate resolution.
Exercise
A colleague writes a script that closes every alert whose validity is not active, using the resolution revoked. Name two problems with this.
Show answer
First, unknown does not mean revoked. It means GitHub could not tell, so the credential may still work, and closing it as revoked hides a live leak. Second, even inactive can be wrong or have a different cause, such as a placeholder value that was never valid, so the resolution revoked makes the reporting inaccurate. The script should close only confirmed-revoked alerts, use a resolution that matches the real cause, and leave unknown alerts for manual review.