By NHI Mgmt Group Editorial TeamBased on Knostic: “From .env to Leakage: Mishandling of Secrets by Coding Agents” (December 16, 2025)

TL;DR: AI coding assistants can silently ingest .env secrets, API keys, and tokens, then expose them through routine actions or MCP-enabled pathways, according to Knostic’s analysis and examples from customer and public incidents. The operational issue is not just code quality, but uncontrolled secret handling inside probabilistic tools that cannot reliably enforce policy boundaries.


At a glance

What this is: Knostic examines how Claude Code automatically loads .env secrets and uses customer and public incidents to show that AI coding assistants can leak credentials through ordinary actions and MCP-enabled paths.

Why it matters: IAM, PAM, and application security teams need to treat AI coding assistants as secret-bearing non-human actors whose file access, memory access, and outbound tool paths require explicit governance.


Context

AI coding assistants now sit close to source code, local files, environment variables, and outbound integrations, which means their identity and access model matters as much as their code output. The governance gap is simple: teams often scope what the assistant can change, but not what it can ingest, retain, and transmit.

Claude Code’s automatic loading of .env files shows how a tool can quietly cross the line from helper to secret consumer. For IAM and NHI practitioners, the relevant question is not whether the assistant can write code, but whether it can be prevented from inheriting credentials that were never meant to enter its runtime context.

The article ties this to customer and public incidents where coding assistants and MCP-related pathways moved secrets beyond their intended boundary. That pattern is typical of modern AI-assisted development, not an edge case.


Key questions

Q: What breaks when AI coding assistants can read .env secrets by default?

A: Default .env access breaks the assumption that secrets stay outside tool context until a human deliberately uses them. Once the assistant can read local configuration files, credentials can be loaded into memory, copied into outputs, or transmitted through later actions. Security teams should treat silent secret ingestion as a governance failure, not a convenience feature.

Q: Why do coding assistants increase secret exposure risk in development workflows?

A: Coding assistants increase secret exposure risk because they operate inside environments where credentials already exist and can be combined with file, shell, and network capabilities. That creates a larger blast radius than the code task itself. The risk is highest when assistant permissions exceed the minimum needed for the developer's immediate work.

Q: How can security teams tell whether an AI coding assistant is ingesting too much sensitive data?

A: Look for signals that the assistant touches files containing credentials, reads hidden environment files, or interacts with integrations that were never intended to see secret-bearing context. If the assistant can access more than the developer would knowingly paste into a prompt, the boundary is too loose.

Q: Should organisations keep secrets in .env files when using AI coding assistants?

A: Only if those files are tightly excluded from assistant access and there is a clear compensating control. In practice, the safer model is to treat .env as temporary configuration, not as a durable secret store, and to move persistent credentials into managed vaults with explicit retrieval logic.


Technical breakdown

How .env loading turns local files into runtime secrets

Many development tools treat .env files as convenient configuration sources, but that convenience becomes risky when an assistant loads them automatically and silently. In this case, Claude Code read .env, .env.local, and similar files, which can contain proxy credentials, tokens, passwords, and API keys. Once those values are loaded into memory, any downstream action the assistant takes may inherit them, even when the user did not intend to expose them to the tool. The problem is not merely disclosure. It is uncontrolled expansion of the assistant’s trust boundary into files that teams assumed were outside its scope.

Practical implication: Treat local environment files as in-scope for AI assistant governance, not just code review and repository hygiene.

Why MCP becomes an exfiltration path after secret ingestion

Model Context Protocol is a tool and data connection layer, so once an assistant has secrets in memory, MCP can become the route that sends them onward. The risk is amplification: the secret does not need to be stolen from a vault if the assistant already loaded it from a file, mounted filesystem, or runtime context. A malicious or compromised MCP integration can then move credentials, tokens, SSH keys, or other sensitive data outside the user’s intended boundary. That makes MCP governance a question of downstream action control, not just connectivity.

Practical implication: Inventory which MCP servers and extensions can access assistant context, then restrict outbound data flows as if they were credential egress paths.

What the incidents say about probabilistic policy boundaries

The article’s examples show a recurring pattern: the assistant can appear to respect workflow intent while still drifting into secret exposure through automatic ingestion, cloud upload, or branch commits. That is why probabilistic systems are a poor place to rely on policy boundaries alone. The boundary is not stable enough to be enforced by prompt intent, and it can fail even when the user believes the environment is isolated. The practical issue is not one bad command. It is a control model that assumes the assistant will remain aligned to the user’s mental model of what is sensitive.

Practical implication: Assume assistant context can include secrets unless the environment is explicitly isolated, denied, and monitored at the file and integration layers.


Threat narrative

Attacker objective: The objective is to obtain and move sensitive credentials or other data out of the developer environment through trusted AI-assisted pathways.

  1. Entry occurs when the coding assistant silently loads secrets from .env files or other local sources into its runtime context.
  2. Credential access follows because those values, including API keys, tokens, proxy credentials, and passwords, are now available to the assistant without explicit user intent.
  3. Escalation happens when the assistant writes, uploads, or transmits those secrets through routine actions or MCP-connected integrations outside the intended boundary.
  4. Impact is secret exposure, credential leakage, and downstream misuse of sensitive data in repositories, cloud services, or third-party tools.
  • Sentry MCP Agentjacking 2026: Researchers showed a fake Sentry error, posted with a public DSN, could make AI coding agents run attacker code with developers' credentials.
  • postmark-mcp malicious MCP server 2025: A fake Postmark MCP server on npm quietly BCC'd every email AI agents sent through it to an attacker, using victims' own Postmark tokens.

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

Secret ingestion is the control failure, not just secret storage: The governing mistake is assuming an AI coding assistant only needs guardrails around outputs, when the real risk begins at context ingestion. .env files were designed to hold secrets away from source control and away from tools that should not see them. Once an assistant loads them silently, the control boundary has already failed, and the practitioner must rethink what counts as in-scope runtime context.

Runtime secret boundary collapse: The article exposes a specific failure mode where credential ownership, file location, and tool context no longer align. That means the old assumption that secrets are safe if they remain off GitHub is incomplete for AI-assisted development. The implication is that NHI governance now has to cover local files, assistant memory, and tool connections as one access surface.

Tool permission is not secret permission: Granting an assistant permission to read a directory or execute a command is not the same as authorising it to inherit every credential embedded in that context. This is especially important where assistants can act through MCP or other integrations. Practitioners should read this as a governance gap between action scope and data scope.

MCP changes the exposure model for coding assistants: Once secret-bearing context exists, MCP becomes a transport layer for unintended disclosure rather than a neutral integration layer. That makes the relevant governance question whether the assistant can combine local context with outbound tools, not merely whether each tool is individually approved. The right response is to treat assistant integrations as data-exfiltration-capable pathways, not just developer conveniences.

Named concept: secret ingestion blast radius: The article’s core contribution is showing that the blast radius starts before exfiltration, at the point where an assistant automatically absorbs secrets from files developers assumed were excluded. That shifts the problem from leak detection to boundary design. Practitioners need to govern what the assistant can ingest, not only what it can emit.

From our research library:

  • Claude Code-assisted commits leaked secrets at a rate of 3.2%, more than double the human-only baseline of 1.5%, with peaks reaching 31 secrets per 1,000 commits in August 2025, according to the State of Secrets Sprawl 2026.
  • 24,008 unique secrets were exposed in MCP configuration files in 2025 alone, the protocol's first year of widespread adoption, according to the State of Secrets Sprawl 2026.
  • Read next: AI Coding Agents Security Guide

What this signals

Secret ingestion is becoming the real AI coding control problem: The governance issue is not limited to whether an assistant can generate insecure code. It is whether the tool can silently absorb sensitive material from files, memory, and mounted context before any human sees the exposure path. That is a secret ingestion blast radius problem, not just a code-quality problem.

In practical terms, teams need to govern AI coding assistants like runtime actors with data access, not like passive IDE features. If the assistant can read hidden configuration, call connected tools, and preserve context across actions, then file-level exclusions and prompt policy alone are not enough.

The broader signal for programme owners is that assistant governance now spans secrets management, developer environment hardening, and integration control. The controls that matter most are the ones that limit what the assistant can ingest and where it can transmit it, because once the secret is in memory, containment becomes reactive.


For practitioners

  • Move secrets out of active project trees Place .env files and similar secret-bearing artifacts outside directories that coding assistants can scan by default, especially in repositories where the assistant has file-read capability.
  • Add explicit deny rules for secret files Block reads of .env*, token files, and similar patterns in assistant configuration so the tool cannot silently ingest credentials from the working directory.
  • Isolate assistants from sensitive repositories Run coding assistants in containers or tightly scoped environments so local files, mounted paths, and project context do not expand into broad secret access.
  • Disable background execution features where secrets exist Turn off auto-run and similar features in repositories that contain credentials, because background actions can turn one secret read into many unintended outbound steps.
  • Shift from local files to managed secret stores Remove secrets from .env files where possible and use vault-backed retrieval patterns so credentials are not sitting in assistant-readable project context.

Key takeaways

  • AI coding assistants can leak secrets because they ingest hidden configuration files as runtime context, not just because they generate unsafe code.
  • The article’s incidents show that the exposure can reach cloud uploads, source control commits, and MCP-connected pathways.
  • The most relevant control shift is to govern assistant file access and outbound tool paths before secret ingestion happens.

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, OWASP Agentic AI Top 10 and MITRE ATT&CK address the attack and risk surface, while NIST CSF 2.0 sets the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-02 — Secret LeakageThe article centres on hidden credentials being loaded and exposed by an AI coding assistant.
NHI-10 — Human Use of NHIDevelopers are using the assistant as an intermediary that handles secrets on their behalf.
Recommendation — Audit assistant-readable paths for secret leakage and remove credentials from .env files and similar local sources. Restrict human-directed secret handling through assistants and define which credentials may never enter tool context.
OWASP Agentic AI Top 10ASI02 — Tool MisuseThe assistant uses connected tools and commands in ways that can move secrets outside intended boundaries.
Recommendation — Constrain tool access so assistants cannot use approved actions to transmit sensitive data unexpectedly.
MITRE ATT&CKTA0006;TA0010 — Credential Access; ExfiltrationThe article describes credentials being absorbed and then moved through assistant actions.
Recommendation — Map assistant-driven secret exposure to credential access and exfiltration tactics in detection and response planning.
NIST CSF 2.0PR.AA-05 — Access Permissions, Entitlements and AuthorizationsThe issue is overbroad access to local files and connected tools that reveal secrets.
Recommendation — Apply PR.AA-05 to limit assistant access to only the files and integrations required for the task.

Key terms

  • Secret Ingestion: Secret ingestion is the automatic or unintended loading of credentials into an AI or software tool’s runtime context. For coding assistants, this includes reading .env files, hidden config, or mounted paths that contain tokens, keys, or passwords that were never meant to be visible to the assistant.
  • Secret Leakage Blast Radius: Secret leakage blast radius is the amount of damage possible once sensitive credentials enter an assistant’s memory or tool context. It is shaped by what the assistant can read, retain, and transmit, which is why file access and outbound integrations matter as much as the original secret source.
  • MCP Exfiltration Path: An MCP exfiltration path is a route by which an AI assistant can send data to connected tools or services through Model Context Protocol integrations. In practice, it becomes dangerous when the assistant already holds secrets and the integration allows those secrets to leave the intended boundary.
  • Runtime secret elimination boundary: The point in a system where a secret stops being a visible object and becomes an enforced request attribute. In mature NHI designs, that boundary should sit before user space so the workload cannot read, log, or reuse the credential outside policy.

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 responsible for identity security strategy or NHI governance in your organisation, it is worth exploring.
NHIMG Editorial Note
Published by the NHIMG editorial team on July 9, 2026.
Updated on October 11, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org