nosecretsv0.5.2

Custom rules

Extend the 75 built-in rules with repository-specific TOML definitions.

Pass one or more TOML files with --rules:

nosecrets scan --rules .nosecrets-rules.toml --staged
nosecrets scan --rules team.toml --rules project.toml src/

Minimal rule

[[rule]]
id = "internal-token"
name = "Internal service token"
severity = "high"
pattern = '''\b(int_[A-Za-z0-9]{24})\b'''
keywords = ["int_"]
capture = 1

The pattern must contain the configured capture group. Rule IDs must be unique across built-in and custom rules. Unknown keys, an empty id or pattern, and a min_length above max_length are errors.

Optional validation and filters

[rule.validate]
prefix = ["int_"]
charset = "A-Za-z0-9_"
length = 28

[rule.paths]
include = ["src/**", "config/**"]
exclude = ["tests/fixtures/**"]

[rule.allow]
patterns = ["EXAMPLE$"]
values = ["int_000000000000000000000000"]

Fields

Field Type Required Meaning
id string yes Unique ID, shown in findings
name string yes Display name
severity string yes critical, high, medium or low
pattern string yes Regular expression containing the capture group
keywords list of strings no Cheap prefilter terms checked before the regex; without them the rule runs on every file
capture integer no Capture group holding the secret; defaults to 1
generic boolean no true for a catch-all rule; a specific rule of the same severity matching the same text is reported instead
validate.prefix list of strings no Accepted prefixes of the captured value
validate.charset string no Regex character class the whole captured value must match
validate.length integer no Exact captured length
validate.min_length, validate.max_length integer no Captured length range
validate.checksum string no crc32-base62-suffix6: the last six characters of the value must be the base62-encoded CRC-32 of everything between the prefix and them (the layout of GitHub-style tokens). Needs validate.prefix; a value with a wrong checksum is not reported
paths.include list of globs no The rule applies only to these paths
paths.exclude list of globs no The rule skips these paths
allow.patterns list of regexes no Captured values matching one of them are not reported
allow.values list of strings no Exact captured values that are not reported
allow.match_patterns list of regexes no The whole match, not only the captured value, is tested; a match for one of them is not reported. Use it to accept a value by its surroundings, for example a connection URI by its host

Severity

Severity Blocks the commit Exit status
critical, high, medium yes 1
low no, shown only 0

Built-in rules

The built-in rules use the same format and are compiled into the binary. They live in crates/nosecrets-core/rules/, one file per category: cloud.toml, deploy.toml, code.toml, communication.toml, database.toml, payment.toml and generic.toml.

Edit this page on GitHub · Docs for v0.5.2