nosecretsv0.5.2

CASOONOpen Source

Catch secrets before they become commits.

An API key pasted into a config file is easy to commit and hard to take back: once it is in Git history, the only fix is to rotate it. nosecrets checks what you are about to commit, on your own machine, and stops the commit if it finds a password, token or key.

curl -fsSL https://raw.githubusercontent.com/casoon/nosecrets/main/install.sh | sh
npm install -g @casoon/nosecrets
cargo install nosecrets-cli
Free · MITv0.5.2offlinemacOS · Linux · Windows
Terminal: config.py holds the example keys from the AWS documentation. After git add config.py, nosecrets scan --staged reports 'config.py:3:26 [CRITICAL] AWS Secret Access Key (aws-secret-key)' with the masked preview wJal...EKEY and exits with 1; the example key ID ending in EXAMPLE is not reported. With the secret key read from the environment instead, the same scan prints 'No secrets found' and exits with 0.

Who it is for

built-in rules for cloud, code hosts, AI providers, databases and payment
75
extra check for unknown high-entropy tokens
1
network calls while scanning
0
ways to install: curl, npm, cargo
3

Adopt it

Start with the repository you already have

nosecrets scan --tracked checks every file Git tracks once. What you decide to keep is accepted by fingerprint and path, in a file that is part of the repository.

  • Nothing is rewritten and nothing leaves your machine.
  • Each accepted value is one line in .nosecretsignore, visible in review.
  • From then on the hook checks only what a commit adds.
nosecrets
$ nosecrets scan --tracked
legacy/import_users.py:2:17 [CRITICAL] GitHub Personal Access Token (github-pat) nsi_5e31772c2cb9
  preview: ghp_...PeXq
$ nosecrets ignore nsi_5e31772c2cb9 --path legacy/import_users.py
Added ignore entry to .nosecretsignore
$ cat .nosecretsignore
nsi_5e31772c2cb9:legacy/import_users.py
$ nosecrets scan --tracked
No secrets found

Your team

One hook, one file for your own formats

Add the hook to .pre-commit-config.yaml and every contributor is covered. Internal token formats get a rule of a few lines, loaded with --rules.

  • Works with pre-commit, prek, lefthook, husky or a plain Git hook.
  • Rules, exceptions and the scan limit sit in files in the repository.
  • A mistake in a rule or in the configuration is an error, never a silent pass.
.pre-commit-config.yaml
repos:
  - repo: https://github.com/casoon/nosecrets
    rev: v0.5.2
    hooks:
      - id: nosecrets-system
team-rules.toml
[[rule]]
id = "acme-service-token"
name = "Acme service token"
severity = "high"
pattern = '''\b(acme_[A-Za-z0-9]{24})\b'''
keywords = ["acme_"]
capture = 1

How it works

You add nosecrets to the pre-commit hook. On every git commit it reads the files staged for that commit, checks them for known secret formats and suspicious random tokens, and leaves out anything you marked as intentional.

If a secret is left, the commit stops and you see the file, the line and the kind of secret. Everything runs locally: no code is uploaded and no provider is contacted.

How nosecrets worksYou run git commit. The pre-commit hook starts nosecrets, which reads the files staged for this commit from the Git index and checks them against 75 built-in rules and an entropy check, leaving out the exceptions you recorded. If a secret is left, the commit is stopped with exit code 1; otherwise it goes on with exit code 0.How nosecrets worksgit commit → Staged files: pre-commit hookStaged files → 75 rules + entropy75 rules + entropy → Secret left?Secret left? → Commit stopped: yesSecret left? → Commit goes on: nopre-commit hookyesnogit commitgit commitStaged files – from the Git indexStaged filesfrom the Git index75 rules + entropy – minus your exceptions75 rules + entropyminus your exceptionsSecret left?Secret left?Commit stopped – exit code 1Commit stoppedexit code 1Commit goes on – exit code 0Commit goes onexit code 0
How nosecrets worksYou run git commit. The pre-commit hook starts nosecrets, which reads the files staged for this commit from the Git index and checks them against 75 built-in rules and an entropy check, leaving out the exceptions you recorded. If a secret is left, the commit is stopped with exit code 1; otherwise it goes on with exit code 0.How nosecrets worksgit commit → Staged files: pre-commit hookStaged files → 75 rules + entropy75 rules + entropy → Secret left?Secret left? → Commit stopped: yesSecret left? → Commit goes on: nopre-commit hookyesnogit commitgit commitStaged files – from the Git indexStaged filesfrom the Git index75 rules + entropy – minus your exceptions75 rules + entropyminus your exceptionsSecret left?Secret left?Commit stopped – exit code 1Commit stoppedexit code 1Commit goes on – exit code 0Commit goes onexit code 0
How nosecrets worksYou run git commit. The pre-commit hook starts nosecrets, which reads the files staged for this commit from the Git index and checks them against 75 built-in rules and an entropy check, leaving out the exceptions you recorded. If a secret is left, the commit is stopped with exit code 1; otherwise it goes on with exit code 0.How nosecrets worksgit commit → Staged files: pre-commit hookStaged files → 75 rules + entropy75 rules + entropy → Secret left?Secret left? → Commit stopped: yesSecret left? → Commit goes on: nopre-commit hookyesnogit commitgit commitStaged files – from the Git indexStaged filesfrom the Git index75 rules + entropy – minus your exceptions75 rules + entropyminus your exceptionsSecret left?Secret left?Commit stopped – exit code 1Commit stoppedexit code 1Commit goes on – exit code 0Commit goes onexit code 0
How nosecrets worksYou run git commit. The pre-commit hook starts nosecrets, which reads the files staged for this commit from the Git index and checks them against 75 built-in rules and an entropy check, leaving out the exceptions you recorded. If a secret is left, the commit is stopped with exit code 1; otherwise it goes on with exit code 0.How nosecrets worksgit commit → Staged files: pre-commit hookStaged files → 75 rules + entropy75 rules + entropy → Secret left?Secret left? → Commit stopped: yesSecret left? → Commit goes on: nopre-commit hookyesnogit commitgit commitStaged files – from the Git indexStaged filesfrom the Git index75 rules + entropy – minus your exceptions75 rules + entropyminus your exceptionsSecret left?Secret left?Commit stopped – exit code 1Commit stoppedexit code 1Commit goes on – exit code 0Commit goes onexit code 0

Quickstart

Check the repository once, then let the hook check every commit.

  1. Install nosecrets with one of the lines above.
  2. Run nosecrets scan --tracked once and review what it finds.
  3. Add nosecrets scan --staged to your pre-commit hook.
Two commands
nosecrets scan --tracked   # once, for what is already there
nosecrets scan --staged    # on every commit, in the hook

New in v0.5.2

Changelog →

Frequently asked questions

Does nosecrets scan my Git history?

No. It is built for the pre-commit moment: scan --staged checks exactly what the next commit would contain, so nothing ever reaches history that needs cleaning up afterwards.

Does it call out to any service while scanning?

No. nosecrets is offline only — no API calls, no account, no dashboard. Everything runs locally on your own machine.

How do I adopt nosecrets in an existing repository?

Run nosecrets scan --tracked once to see what the current Git index already holds, then add nosecrets scan --staged to your pre-commit hook so every future commit is checked.

What if it flags a documented example key or test value?

Allow it on purpose: list the pattern or value under [allow] in .nosecrets.toml, add an inline @nosecrets-ignore comment, or record its fingerprint in .nosecretsignore. Every exception stays visible in the repository and in code review.

Will the high-entropy check flood me with false positives?

By default it only flags long, random-looking tokens found near secret-related names such as secret, token or password (require_context = true), which keeps unrelated random strings out of the report.