Join our Newsletter — 33% off our NHI Course
Home› FAQ› Foundations & NHI Taxonomy› Why does rarity work better than randomness for…
Foundations & NHI Taxonomy

Why does rarity work better than randomness for candidate secrets?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated October 12, 2026 Domain: Foundations & NHI Taxonomy

Because many secrets are not maximally random, but they are unusual in ordinary source code and documentation. Rarity captures how far a string sits from natural-language distribution, which is closer to the real triage problem after regex has already found a candidate. That makes rarity a more discriminating signal than entropy alone.

Why rarity outperforms randomness for candidate secrets

Rarity works better because the first job in secret triage is not proving a string is mathematically random, it is deciding whether a string looks out of place in ordinary code, config, and documentation. A secret candidate can be low-entropy yet still be highly suspicious, while many benign values are random-looking by design.

How rarity matches the actual triage problem

In practice, most candidate secrets are found by pattern matching first, then ranked for follow-up. That means the useful question is not “is this string random enough?” but “does this string resemble something a human would expect to see in source text?” Rarity scores that distance from natural-language and common-token distributions, which is often the stronger separator between real secrets and harmless noise.

That distinction matters because source code, comments, documentation, test fixtures, and configuration files contain many values that are structured but not secret. A rare token is more likely to stand out in those contexts, especially when paired with surrounding clues like key names, path names, or credential-like prefixes.

Rarity also handles the messy reality that secrets are not one uniform type. API keys, bearer tokens, client secrets, session material, and cloud credentials can each have different formats. A detector that relies only on randomness can miss values that are semi-structured or partially human-shaped, while rarity can still flag them when they are unusual in the local corpus.

Why entropy alone creates false comfort

Entropy is useful, but it is only a proxy for unpredictability. It can overrate values that look random without being secrets, and underrate values that are operationally sensitive but not perfectly random. In other words, entropy tells you something about internal structure, not whether a value belongs in the file it was found in.

That is why a practical secret scanner should treat entropy as one feature, not the decision rule. The better test is whether the candidate is rare relative to its surrounding text, repository, or documentation set, then whether the local context reinforces that suspicion. This is also why teams often combine rarity with regex patterns and allowlists rather than trusting entropy thresholds alone.

For workflow context, the same logic appears in broader secrets guidance such as Secrets Management Guide, which treats discovery, rotation, and reduction of exposed material as a lifecycle problem, not just a detection problem. It also aligns with the practical handling of exposed application keys in the API Key Management Guide.

What rare signals usually improve precision

Rarity works best when it is anchored to concrete signals rather than used alone. Useful signals include uncommon character combinations, values that are unusual for the file type, tokens that appear only once across a repository, and candidate strings that are rare in relation to adjacent words such as “secret”, “token”, “key”, “auth”, or “vault”.

High-value candidates often also appear in places where secrets should not live: source code, sample configs, logs, markdown docs, CI variables, container images, and issue trackers. In those environments, a rarity-based score helps separate an accidental paste from ordinary boilerplate. When the context indicates actual credential material, follow-up should move quickly to validation and rotation, not prolonged scoring.

NHIMG’s Guide to the Secret Sprawl Challenge and Secrets Management Guide are useful reference points because they frame secrets exposure as a discovery and lifecycle issue. For scanners, that means the best signal is the one that finds a likely secret where it does not belong, not the one that merely proves the string could have high entropy.

Risk and Threat Considerations

Relying on randomness alone can leave exposed credentials in place, especially when the secret is short-lived, partially structured, or embedded in an unusual-but-not-fully-random format. Attackers do not need a perfectly random secret to cause damage, they only need one that is accepted by the target system and present in a reachable location.

Failure mechanism: Entropy-only filters miss low-entropy or semi-structured secrets, while also producing false positives on benign random-looking strings, which weakens triage and delays remediation.

Impact: Missed secrets remain exploitable, and noisy detections train teams to ignore alerts, reducing both response speed and trust in scanning results.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 addresses the attack and risk surface, while NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-02 — Secret LeakageCandidate secret triage centers on exposed secret material.
Recommendation — Prioritise detection and rotation workflows for leaked secret material.
NIST SP 800-53 Rev 5IA-5 — Authenticator ManagementCandidate secrets are authenticators that need lifecycle control and rotation.
SI-4 — System MonitoringSecret scanning depends on monitoring for exposed credentials in code and repos.
Recommendation — Manage authenticators so exposed secrets are rotated, revoked, or replaced promptly. Monitor code and repositories for exposed credential patterns and triage findings quickly.
CIS Controls v8CIS-16 — Application Software SecuritySecrets in code and documentation are an application-security exposure.
Recommendation — Scan application assets for embedded secrets and remediate exposed values before release.

Practitioner Guidance

What to prioritise: Use rarity as the ranking signal after regex or pattern matching has already identified a candidate, then reserve entropy for secondary confirmation. That ordering keeps the scanner aligned with the real operational task, which is deciding what deserves human review first.

What to verify: Check whether a candidate is rare in the local repository, file type, or documentation set, not just rare in an abstract sense. A string that is unusual in one codebase may be ordinary in another, so local context should shape the threshold.

Common mistake: Treating high entropy as proof of secrecy leads to noisy results and missed exposures. The better rule is that a candidate should look out of place before it is treated as sensitive.

Practitioner takeaway: Secret detection works best when it asks “does this belong here?” before asking “how random is it?”, because context-aware rarity is usually closer to the real remediation decision.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 12, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org