By NHI Mgmt Group Editorial TeamBased on Semgrep: “Secrets Story: The Prefixed Secrets That Tried%20to%2BGetAway” (November 20, 2025)

TL;DR: Common secret-scanning design choices such as word boundaries and keywords can miss valid live secrets in public GitHub repositories, including tokens from GitHub, OpenAI, Anthropic, Gemini and others, according to Semgrep. The result is a familiar governance problem: tuning for fewer false positives can silently widen the false-negative window.


At a glance

What this is: This is an analysis of why secret scanners miss live secrets in public repos, with Semgrep showing that boundary rules and keyword filters can create false negatives.

Why it matters: IAM and NHI teams need to treat detection tuning as an exposure control problem, because missed secrets extend the lifespan of credentials that should already be revoked or rotated.


Context

Secret scanning is only useful if it finds the credential formats that actually appear in code, logs, notebooks, and diffs. When rules rely too heavily on word boundaries or keyword context, they can miss real secrets that are still valid and still callable.

For NHI governance, the issue is not whether scanners can reduce noise. It is whether the detection model is precise enough to catch exposed API keys, tokens, and other machine credentials before they become active attack paths. That balance sits at the center of secret lifecycle control.

Semgrep's research argues that overly restrictive detection logic creates a false sense of coverage. The operational problem is familiar across identity programmes: a control tuned for elegance can fail at the exact moment it is needed most.


Key questions

Q: What breaks when secret scanners rely on word boundaries and keyword filters?

A: They miss valid live secrets that appear inside comments, notebooks, escaped output, or mislabelled code. The scanner is optimised for low noise, but that same optimisation can exclude real tokens that are still active and publicly exposed. Security teams should test detection against messy, real-world leakage patterns, not just clean sample tokens.

Q: Why do false-positive reduction rules create secret exposure risk?

A: Because every extra filter narrows the set of strings that qualify as a secret. If the rule assumes a token must be isolated, correctly labelled, and formatted in one expected way, then valid credentials that deviate from that path will be ignored. The result is a quiet miss, not a noisy alert, and that miss can persist until revocation.

Q: What should security teams measure to know secrets scanning is working?

A: Measure coverage, context quality, and time to remediation. If findings lack ownership, rotation age, or access scope, the scanner is generating alerts without enough information to drive action. Effective scanning makes secrets easier to find and easier to prioritise.

Q: How should security teams respond when valid API keys are discovered in public repositories or datasets?

A: Security teams should treat exposed API keys as active access, not as harmless configuration residue. The right response is immediate verification, revocation, and replacement, followed by a search for secondary abuse such as token minting, repository writes, or workflow execution. Detection without rapid revocation leaves a live starting point for follow-on compromise and credential chaining across systems.


Technical breakdown

How boundary rules create false negatives in secret detection

Secret scanners often use regex boundaries to decide whether a string is isolated enough to treat as a credential. That works when a token appears cleanly on its own, but it fails when secrets sit inside comments, shell output, notebooks, escaped text, or other surrounding characters that break the boundary condition. In practice, the scanner is not just matching a token format. It is also making a judgement about context, and that judgement can be too strict. For machine credentials, the cost of strict context rules is missed detection of live secrets that are already public.

Practical implication: Treat boundary logic as a precision trade-off, not a safe default, and test it against real leakage patterns from your own repositories.

Why keyword gating misses valid API keys and tokens

Keyword filters are meant to reduce false positives by requiring nearby service names or labels, but they can become brittle when developers omit the expected keyword, place it in another field, or label the credential incorrectly. A scanner looking for a DeepSeek keyword near a token, for example, can miss the same token if the code uses an OpenAI client or a different naming convention. This is a governance problem as much as a parsing problem: detection logic assumes consistent human labelling in environments where naming is often messy, stale, or wrong.

Practical implication: Validate secret rules against mislabelled and context-shifted examples, not just idealised token samples.

Why broad token patterns can still under-detect service-specific secrets

Generalised regex can look attractive because it covers multiple token families with one rule, but that convenience can obscure service-specific formats. A single broad pattern may need boundaries to control noise, yet those same boundaries can suppress valid matches when token lengths, suffixes, or unique markers differ by provider. The result is a detector that is simultaneously too broad and too narrow: broad enough to need heavy filtering, narrow enough to miss live credentials. For NHI teams, this shows that token format governance has to stay aligned with actual service formats over time.

Practical implication: Maintain service-specific detection logic and review token formats whenever providers change their secret structure.


Threat narrative

Attacker objective: Use publicly exposed but still-valid secrets to access third-party services or adjacent repositories before defenders detect and revoke them.

  1. Entry occurs when a valid secret is committed or leaked into a public GitHub repository, often inside code, comments, notebooks, or terminal output.
  2. Credential access follows because the exposed token remains valid and can still authenticate against the third-party service if it is not detected and revoked.
  3. Impact is created when the undetected credential enables repository access, API use, or other downstream actions before the leak is discovered.
  • Hugging Face Spaces breach 2024: Unauthorised access to Hugging Face Spaces may have exposed secrets users stored for AI apps; tokens were revoked and org tokens removed.
  • PyPI admin GitHub token leak 2024: A PyPI admin's GitHub token with admin rights over Python and PyPI repos sat in public Docker images for 15 months before JFrog found it.

Read and download The State of NHI & AI Agent Breach Report 2026, covering 200+ breaches impacting Non-Human Identities including AI Agents.


NHI Mgmt Group analysis

False-negative tuning is an identity governance decision, not just a detection preference. When secret scanners are tuned to suppress noise, they also decide which exposed machine credentials remain invisible long enough to matter. That shifts the problem from alert quality to credential lifecycle exposure, because a missed token is still an active identity surface. Practitioners should treat scanner rules as part of the NHI control plane, not a cosmetic filter.

Boundary logic assumes clean credential placement, but real leaks are messy. Secrets appear inside comments, notebooks, shell output, escaped strings, and copy-pasted fragments that do not respect ideal regex assumptions. The assumption that a valid token will sit cleanly between word boundaries is often false in public repos. The implication is that detection coverage must be tested against how developers actually leak secrets, not how rule authors hope they will.

Keyword dependence creates a labelling problem that governance teams do not control. A scanner that expects the correct provider name near a token is relying on human consistency at the exact point where human behaviour is least reliable. Misnamed variables, reused SDKs, and mixed service labels make keyword gating brittle. For NHI governance, this is a reminder that discovery logic must tolerate operational sloppiness, or it will miss the credentials most likely to be exposed.

Secret scanning should be measured by missed-live-secret rate, not by false-positive comfort. A control that feels quieter can still be materially weaker if it systematically excludes real tokens from detection. Semgrep's findings reinforce a larger programme lesson: visibility controls must be validated against live credential patterns, not only against synthetic test corpora. Practitioners should re-baseline scanner efficacy around what the tool fails to find, not only what it flags.

Secret format drift is a governance drift problem. The moment a provider changes token structure, introduces unique suffixes, or reuses common prefixes, scanner rules can become stale even when the underlying platform is unchanged. That means inventory, validation, and update cadence for secret patterns need the same operational discipline as rotation and revocation. Teams should manage detection logic as a living control with owner, review cycle, and test evidence.

What this signals

Secret scanning is only as strong as the assumptions behind its parsers. When detection depends on the ideal placement of a token, it will miss the messy reality of source control, notebooks, and copied output. That makes false-negative testing a core part of NHI governance, not a tuning exercise at the edge of the programme.

Credential discovery should be governed as a living control. Token formats change, providers add unique identifiers, and developers leak secrets in unexpected ways. Teams that treat scanner rules as static will accumulate blind spots, so the detection library needs recurring review, version awareness, and evidence-based validation.


For practitioners

  • Review secret scanning rules for boundary overreach Test whether word boundaries, suffix checks, or surrounding-character assumptions are suppressing real secrets in comments, notebooks, diffs, and terminal output.
  • Tune keyword gates against mislabelled secrets Check whether your detector misses valid tokens when the provider name is absent, wrong, or located elsewhere in the file rather than adjacent to the secret.
  • Write service-specific token patterns Use precise regex for each token family instead of one broad pattern that forces heavy filtering and misses provider-specific format details.
  • Add post-commit validation and revocation checks Assume some secrets will bypass push protection and confirm that exposed tokens can be validated and revoked after commit or publication.
  • Monitor public repositories for your own token formats Search public code and artifacts for the exact formats your services issue, especially where partner scanning or push protection is not guaranteed.

Key takeaways

  • Secret scanning can fail in exactly the cases that matter most, especially when rules assume secrets will appear in clean, predictable text patterns.
  • The research shows that over-tuned boundary checks and keyword dependencies can let live credentials remain public without triggering detection.
  • Practical governance requires validating detection logic against real leakage patterns, then pairing discovery with rapid revocation and format-specific rule maintenance.

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 and MITRE ATT&CK address the attack and risk surface, while NIST SP 800-53 Rev 5 sets the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-02 — Secret LeakageThe article centers on exposed live secrets and missed detection in repositories.
NHI-07 — Long-Lived SecretsMissed public tokens stay usable until revoked, extending exposure windows.
Recommendation — Scan repositories continuously for leaked NHI secrets and treat missed detections as control failures. Reduce secret lifetime and automate revocation for any token exposed in public code.
NIST SP 800-53 Rev 5IA-5 — Authenticator ManagementIA-5 governs credential lifecycle, including rotation and revocation after exposure.
Recommendation — Apply IA-5 to enforce secret rotation, revocation, and validation after public exposure.
MITRE ATT&CKTA0006 — Credential AccessThe primary threat is acquisition and reuse of exposed credentials.
Recommendation — Map exposed-secret findings to Credential Access and prioritize validation of active tokens.

Key terms

  • False negative: A missed detection where a real threat is not recognised as malicious or important. In AI SOC environments, false negatives often arise when the system under-collects context, stops at the first plausible answer, or over-optimises for speed.
  • Word Boundary: A word boundary is a position in text where a match starts or ends cleanly without blending into nearby characters. In log searches, it helps stop partial matches inside longer strings, such as embedded addresses in URLs or query values. It is useful when precision matters more than recall.
  • Keyword Gating: Keyword gating is a detection technique that requires surrounding terms, such as a provider name, to be present before a token is treated as a secret. It reduces noise, but it also creates brittle assumptions about how developers label credentials and where secrets appear in files.
  • Secret Format Drift: Secret format drift is the change in a provider's token structure, length, prefix, or suffix over time. When scanners are not updated to follow those changes, detection logic becomes stale and begins missing valid credentials even though the service is still in active use.

Deepen your knowledge

NHI governance, agentic AI identity, and machine identity lifecycle are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are building or maturing an identity security programme, it is worth exploring.
NHIMG Editorial Note
Published by the NHIMG editorial team on August 2, 2026.
Updated on October 12, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org