Sub topic 13
Excluding paths to reduce noise
This chapter assumes you can read basic YAML and know how to list secret scanning alerts. Both were covered earlier in the tutorial. It explains how to tell secret scanning to skip certain paths, when that is a good idea, and what it costs.
Why exclusions exist
Secret scanning looks for strings that match known token formats. It cannot tell whether a matching string is a live credential or a sample. Some repositories produce many alerts for strings that are not real secrets:
- Documentation that shows what a token looks like.
- Test fixtures with captured API responses.
- Recorded HTTP cassettes from integration tests.
- Vendored sample data.
Every one of these alerts takes time to open and close. If a team sees dozens of false alerts, it starts to ignore the list, and a real leak can get lost among them. A narrow exclusion keeps the alert list short enough to be worth reading.
An exclusion removes coverage. A file that is excluded is a file where a real secret will not be reported. Use exclusions as a last step, after you have tried to make the noise go away at its source.
The configuration file
Exclusions live in a file named .github/secret_scanning.yml in the repository. The file has one key, paths-ignore, which holds a list of glob patterns.
# .github/secret_scanning.yml
paths-ignore:
- "docs/**/*.md"
- "test/fixtures/**"With this file, secret scanning skips every Markdown file anywhere under docs/ and everything under test/fixtures/.
Glob rules
Patterns follow glob syntax. These are the rules you will use most:
| Pattern | Matches | Does not match |
|---|---|---|
| `*.md` | Markdown files in the repository root | `docs/guide.md` |
| `docs/*.md` | Markdown files directly in `docs/` | `docs/api/guide.md` |
| `docs/**/*.md` | Markdown files at any depth under `docs/` | `README.md` |
| `test/fixtures/**` | Everything under `test/fixtures/` | `test/unit/a.py` |
| `**/*.sample` | Files ending in `.sample` at any depth | `a.sample.bak` |
The single asterisk * stands for any characters except the path separator /. The double asterisk ** crosses directory boundaries. Most mistakes come from using * where ** is needed, which leaves deeper files still scanned.
YAML quoting
A pattern that starts with * is read by YAML as an alias, so it must be in quotes. Quote every pattern, as the example does. An unquoted - **/*.sample will break the file.
Limits to know
GitHub documents two limits for this file. Check the current documentation before relying on the exact numbers.
- Only the first 1,000 entries in
paths-ignoreare used. Entries past that are ignored. - If the file is larger than 1 MB, secret scanning ignores the whole file, so every path is scanned again.
Both limits fail quietly. If you generate this file by script, check its size and entry count in a test.
Deciding whether to exclude
Do not reach for an exclusion first. The better order is:
- Ask whether the value can be made obviously fake.
- Ask whether the alerts belong in one place that can be closed with a reason.
- Only then exclude the path.
The first question matters most. A path full of "test" data is sometimes not fake at all. A developer may have pasted a real key into a fixture to make a test pass. Check before you exclude, because once the path is excluded no one will be told.
Prefer fake values that do not match
Many test needs can be met with a value that does not look like a provider token. A string such as test-key-not-a-real-secret does not match any provider pattern, so no alert appears and no exclusion is needed. Where a test must exercise parsing of a real token format, keep that file small and put it in a clearly named directory, so the exclusion can be narrow.
Prefer narrow patterns
Compare these two exclusions:
# Too broad: hides real leaks in any test file
paths-ignore:
- "**/test/**"
# Narrow: only the directory known to hold dummy data
paths-ignore:
- "test/fixtures/dummy-tokens/**"The broad version also hides a real key that someone commits in services/billing/test/integration.env. The narrow version only covers the directory you reviewed.
Finding which paths are noisy
You can use data instead of guessing. The alerts API has a locations endpoint that returns where each alert was found. This script counts open alerts by file path:
for n in $(gh api --paginate 'repos/OWNER/REPO/secret-scanning/alerts?state=open' --jq '.[].number'); do
gh api "repos/OWNER/REPO/secret-scanning/alerts/$n/locations" \
--jq '.[] | select(.type == "commit") | .details.path'
done | sort | uniq -c | sort -rn | head -20Replace OWNER/REPO with your repository. The output is a ranked list of paths with the number of alerts each has. A path near the top that holds only documentation or fixtures is a candidate for exclusion. A path that holds application code is not.
For each candidate, open a few alerts and confirm the values are not live. The validity status shown in the alert can help here, but it does not cover every secret type, so "unknown" does not mean "safe".
What exclusions do not do
They do not close existing alerts
Adding a path to paths-ignore stops new detections for that path. Do not assume it removes alerts that are already open. Review the open list afterward and close leftover alerts for the excluded paths yourself. Choose the resolution that is accurate:
| Resolution | Use it when |
|---|---|
| `false_positive` | The string matched a pattern but is not a credential |
| `used_in_tests` | The credential is real in format but only used in tests |
| `wont_fix` | You accept the risk and will not act |
| `revoked` | The credential was actually revoked at its provider |
Never use revoked to clear noise. That reason says the credential was cancelled, and later readers will trust it.
gh api --method PATCH repos/OWNER/REPO/secret-scanning/alerts/42 \
-f state=resolved \
-f resolution=used_in_testsThey do not undo a leak
A path exclusion is about detection, not safety. If a real secret sits in an excluded file, it is still exposed to anyone with read access. Excluding the path only means that you will not be told. The rule from earlier chapters still holds: revoke and rotate first, then clean up.
They do not apply to other repositories
The file is per repository. Organizations with many repositories that share a layout need to commit the file to each one. A template repository or a scripted pull request can keep them consistent.
Check how push protection treats excluded paths
The file is documented as controlling which files secret scanning checks. Confirm in the current GitHub documentation, and by testing in a scratch repository, whether pushes that touch an excluded path are still blocked. Do not rely on an assumption either way when you write guidance for your team.
Keeping the file healthy
An exclusion file tends to grow and never shrink. Treat it like code:
- Put it under
CODEOWNERSso the security team reviews every change. A pull request that adds**is worth a second look. - Add a comment above each entry saying why it is there.
- Review the file every few months, and remove entries for directories that no longer exist.
- Watch for entries that were added to silence one alert but cover far more than that.
# .github/secret_scanning.yml
paths-ignore:
# Sample tokens in API reference pages; all values are fabricated.
- "docs/api/**/*.md"
# Recorded responses scrubbed by tools/scrub_cassettes.py before commit.
- "test/cassettes/**"Comments like these let a reviewer judge whether the reason still holds.
Summary of the trade-off
Each path you exclude trades some coverage for a quieter alert list. The trade is good when the path holds only fabricated values and the pattern is narrow. It is bad when the path is broad, mixed, or excluded to avoid a real fix. When in doubt, close the individual alert with an accurate reason and leave the path scanned.
Exercise
Your repository has 60 open alerts. Most are under test/fixtures/ and are sample tokens, but a few are in test/integration/ where developers sometimes paste real keys for local runs. A teammate proposes adding **/test/** to paths-ignore. What would you do instead, and how would you handle the alerts that are already open?
Show answer
Reject the broad pattern, because it hides test/integration/ where real keys may appear. Add only test/fixtures/** after checking a sample of those alerts to confirm the values are fabricated. Review the alerts under test/integration/ individually, and revoke and rotate any that are live. After the exclusion is in place, close the remaining open alerts under test/fixtures/ with used_in_tests or false_positive, not revoked, because adding a path does not close existing alerts and revoked would wrongly claim the credentials were cancelled.