Subscribe to the Non-Human & AI Identity Journal

How should security teams stop AI coding tools from creating secrets sprawl?

Security teams should make approved secret retrieval the easiest path and block plaintext credential storage in files, chat messages, and scripts. Builders need service account-based access, secret references, and runtime retrieval patterns that keep credentials out of source control and local notes. The goal is to prevent one shortcut from becoming durable exposure.

Why This Matters for Security Teams

AI coding tools do not just accelerate delivery, they also compress the time available for safe handling of credentials. When a developer asks an assistant to scaffold a script, fix a pipeline, or draft a test harness, the model may surface secrets in prompts, copy them into files, or encourage the reuse of long-lived credentials. That turns convenience into durable exposure, especially when the output is committed, shared, or pasted into tickets.

This is why secrets sprawl is no longer only a source-control problem. NHIMG has shown how quickly AI-related leaks are expanding, with The State of Secrets Sprawl 2026 documenting 28.65 million new hardcoded secrets in public GitHub commits in 2025 alone. The practical lesson is that retrieval patterns matter as much as storage policy. Security teams need to make approved secret access easy enough that developers do not invent their own shortcuts, while blocking plaintext exposure in code, chat, and local notes. Current guidance from the OWASP Non-Human Identity Top 10 reinforces that secret lifecycle controls must account for automated actors, not just human users.

In practice, many security teams discover secret sprawl only after an AI-generated commit or shared prompt has already copied the credential into multiple places.

How It Works in Practice

The most effective pattern is to move AI coding tools away from direct secret handling and toward runtime retrieval. That means the tool, the build job, or the agented workflow authenticates as a workload, receives a short-lived identity token, and requests a secret only when the task actually needs it. The secret is then injected into memory or a runtime session, not written to source files, shell history, or chat transcripts. This is consistent with the direction of the Guide to the Secret Sprawl Challenge and aligns with the broader industry shift toward ephemeral access.

Operationally, teams should combine a few controls:

  • Use service account or workload identity rather than personal developer credentials for AI-assisted automation.
  • Issue secrets through a broker or vault at request time, with short TTLs and automatic revocation.
  • Scan prompts, generated code, and CI logs for plaintext secrets before merge or execution.
  • Block commit paths that contain keys, tokens, certificates, or obvious secret references.
  • Prefer secret references, environment injection, or runtime bindings over literal values in files.

Static IAM fails here because the access pattern is not stable. An AI coding tool may need a database token for one task, an artifact signing token for the next, and no secret at all for the third. Runtime authorization and policy-as-code are a better fit than pre-approved standing permissions, particularly when paired with the CI/CD pipeline exploitation case study, which shows how quickly pipeline trust can be abused once credentials are exposed. For implementation detail, NIST’s Zero Trust Architecture guidance supports continuous verification rather than one-time trust, and SPIFFE-style workload identity is often used to prove what the automated workload is before issuing access. These controls tend to break down when teams let coding assistants run inside broad, persistent developer sessions because the tool inherits too much ambient privilege.

Common Variations and Edge Cases

Tighter secret controls often increase friction for developers, so organisations have to balance safer workflows against speed and usability. That tradeoff is real, especially in fast-moving engineering teams where an AI assistant is expected to move from prototype to pull request in minutes. Best practice is evolving, and there is no universal standard for how much context an AI coding tool should be allowed to retain between tasks.

One common edge case is local development. If a team blocks every visible secret but leaves a cached token on a laptop, the tool may still leak through shell history, editor plugins, or crash reports. Another is CI/CD, where the assistant may generate secure-looking code that still hardcodes test credentials or copies production values into fixtures. The Ultimate Guide to NHIs – Static vs Dynamic Secrets is useful here because static secrets create far more remediation debt than short-lived ones.

Teams should also treat prompt logging, issue trackers, and collaboration tools as part of the secrets attack surface. NHIMG research on the State of Secrets Sprawl 2026 shows that a significant share of incidents now originate outside code repositories, which is exactly where AI-assisted work often spills into chat. In environments with regulated production access, shared admin shells, or legacy deployment scripts, the guidance breaks down because the tool cannot separate safe retrieval from unsafe reuse without deeper platform changes.

Standards & Framework Alignment

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

OWASP Agentic AI Top 10 and OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST AI RMF set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
OWASP Agentic AI Top 10 A2 AI coding tools can expose secrets through generated output and prompt handling.
OWASP Non-Human Identity Top 10 NHI-03 Secret rotation and lifecycle control are central to stopping secrets sprawl.
NIST AI RMF GOVERN Governance is needed to assign accountability for AI-assisted secret exposure.

Replace long-lived credentials with short-lived secrets and automate rotation plus revocation.