How it works
What nosecrets reads on each commit, how it decides what is a secret, and how exceptions are applied.
Scope
nosecrets checks what is about to be committed. It runs offline, does not verify findings against provider APIs and does not scan Git history; those jobs belong to other tools.
Exact staged contents
nosecrets scan --staged reads the blobs selected for the next commit from the Git index, not
the files in the working tree. A secret that was staged cannot be hidden by editing or deleting
the working-tree copy afterwards: the scan sees what the commit would contain.
nosecrets scan --tracked reads every tracked blob from the same index. Run it once when adding
nosecrets to an existing repository to get a complete baseline; it includes committed and staged
tracked files, excludes untracked files and does not look at history.
Layered detection
Every file passes the same pipeline (scan_content in crates/nosecrets-core/src/detector.rs):
Focus
Source: crates/nosecrets-core/src/detector.rs (scan_content), crates/nosecrets-core/src/entropy.rs, crates/nosecrets-core/src/filter.rs
Show chart data
| Step | Kind | Lane | Leads to |
|---|---|---|---|
| Path filter | start | Every file | Skip binary files |
| Skip binary files | step | Every file | Keyword prefilter, High-entropy strings |
| Keyword prefilter | step | Known formats | Rule pattern |
| High-entropy strings | step | Unknown tokens | Skip rule matches |
| Rule pattern | step | Known formats | Validation |
| Skip rule matches | step | Unknown tokens | Inline markers, fingerprints |
| Validation | step | Known formats | Allowlists |
| Allowlists | step | Known formats | Inline markers, fingerprints |
| Inline markers, fingerprints | step | Result | Finding |
| Finding | end | Result |
Focus
Source: crates/nosecrets-core/src/detector.rs (scan_content), crates/nosecrets-core/src/entropy.rs, crates/nosecrets-core/src/filter.rs
Show chart data
| Step | Kind | Lane | Leads to |
|---|---|---|---|
| Path filter | start | Every file | Skip binary files |
| Skip binary files | step | Every file | Keyword prefilter, High-entropy strings |
| Keyword prefilter | step | Known formats | Rule pattern |
| High-entropy strings | step | Unknown tokens | Skip rule matches |
| Rule pattern | step | Known formats | Validation |
| Skip rule matches | step | Unknown tokens | Inline markers, fingerprints |
| Validation | step | Known formats | Allowlists |
| Allowlists | step | Known formats | Inline markers, fingerprints |
| Inline markers, fingerprints | step | Result | Finding |
| Finding | end | Result |
- Known formats. 75 built-in rules in
crates/nosecrets-core/rules/cover cloud providers, deploy platforms, code hosts, AI providers, developer tools, messaging, databases, payment and generic patterns. An Aho-Corasick keyword prefilter selects the rules worth running, the rule’s regular expression finds candidates, and structural validation (charset, length, prefix) drops values that cannot be the real format. - Encoded secrets. Runs of 24 or more base64 characters (standard or URL-safe alphabet) are
decoded one level deep. If the result is valid UTF-8 and mostly printable text, the same rules run
over it; the entropy detector does not. The finding sits at the encoded token, carries the rule ID
of the inner rule and the fingerprint of the decoded secret, and is marked
(base64)in text output and"encoding": "base64"in JSON. Turn it off with[decode] base64 = false. - Unknown tokens. The entropy detector looks for long, high-entropy strings near names such as
secret,token,key,authorpassword. Placeholders likeexampleorchangemeare never flagged, and spans already reported by a rule are not reported twice. Entropy findings use the rule IDhigh-entropy-stringwith severitymedium. - Known examples. Rules can carry their own allowlist. The AWS access key rule, for instance,
skips IDs ending in
EXAMPLEorSAMPLE, so the documentation keyAKIAIOSFODNN7EXAMPLEpasses while a secret key next to it is still reported (the start page shows this run).
Reviewable exceptions
What remains after detection is checked against the exceptions you recorded, from broad to narrow:
- path ignores in
.nosecrets.toml([ignore].paths, plus built-in defaults such as.git,node_modules,target,dist), - allowed patterns and values (
[allow]), - inline markers on the line itself (
@nosecrets-ignore,@nsi), - stable
nsi_…fingerprints in.nosecretsignore, optionally limited to a path glob.
All of them live in files you commit, so every exception is visible in review. See Configuration for the syntax.
Fingerprints
Every finding carries a fingerprint: nsi_ followed by the first twelve hex digits of the
SHA-256 hash of the secret. It depends on the secret alone, so it stays the same when the line
moves, and it does not reveal the secret. .nosecretsignore takes one fingerprint per line,
optionally limited to a path glob:
nsi_a1b2c3d4e5f6
nsi_b2c3d4e5f6a7:src/config.py
nosecrets ignore <FINGERPRINT> and scan --interactive write these lines for you.
From command to exit code
- The CLI loads
.nosecrets.toml, the built-in rules, any--rulesfiles and.nosecretsignore. A mistake in one of them stops the run. - It collects the input: changed index blobs (
--staged), all index blobs (--tracked) or files below the given paths. Ignored paths and files abovescan.max_file_sizeare dropped before their content is read; Git contents come from one batchedgit cat-fileprocess. - Files are scanned in parallel through the pipeline above.
- Findings are de-duplicated, sorted by path, line and column, and printed as text or JSON.
Exit codes
0: no blocking findings (onlylowor none).1: blocking findings (critical,highormedium). The pre-commit hook stops the commit.2: the scan could not run, for example because of an invalid configuration.