Why AI Coding Assistants Leak Secrets More Than Twice as Often
AI-assisted commits leak credentials at roughly double the GitHub-wide baseline, and MCP configuration files are now a documented exposure path in their own right

Proactive Security for the AI Era
NodeZero continuously and autonomously pentests infrastructure, identity, cloud, and now web applications, chaining weaknesses across every domain the way real attackers do. Every finding ships with replayable proof showing exploitable business impact, not theoretical risk.
AI coding assistants did not invent credential leakage, hardcoded API keys and tokens have been landing in public commits for as long as there has been version control. What changed is the rate. GitGuardian's 2026 State of Secrets Sprawl report measured AI-assisted commits leaking secrets at roughly double the GitHub-wide baseline rate, with Claude Code-assisted commits peaking at 31 secrets per 1,000 commits during August 2025, about 2.4 times the human baseline for that period. The same report found 24,008 unique secrets exposed specifically in Model Context Protocol (MCP) configuration files, of which 2,117 were confirmed valid credentials at time of discovery.
That is a meaningfully different problem than "developers still hardcode secrets sometimes." AI coding assistants introduce at least three mechanisms that a manual coding workflow does not have: a cloud-hosted model reading your working context (including whatever is open in the editor, pasted into chat, or passed through an MCP server) before it ever reaches a commit; a code-suggestion engine trained to pattern-match on public repositories that are themselves full of leaked credentials, which it can reproduce; and a growing layer of local configuration files, MCP server definitions, .env references, and IDE settings, that sit outside your normal source-controlled review path and often outside your secrets scanner's coverage entirely. This piece is a practitioner-focused walkthrough of why that happens and a concrete procedure for closing it. For the broader question of which assistant to deploy and how to govern it organizationally, see our companion piece on governing AI coding assistants. This article stays narrowly on the credential leakage mechanism.
The problem: three distinct leakage paths, not one
"AI coding assistants leak secrets" is usually shorthand for three separate mechanisms that get lumped together and therefore mitigated inconsistently.
The first is context-window exposure. Every time a developer has a file open, pastes a stack trace, or asks a chat-based assistant to debug a failing integration, whatever is in that context, including any live API key, database connection string, or session token sitting in a nearby line, gets sent to the model provider's inference endpoint. For cloud-hosted assistants that is a third-party service outside your network boundary, and depending on the vendor's data retention and telemetry settings, that context can be logged, cached, or in some documented cases used for further model training. This is a fundamentally different exposure surface than a git commit: there is no diff to review, no CI gate to catch it, and often no local log a security team can audit after the fact.
The second is suggestion-level regeneration. Public research from Hong Kong University demonstrated that GitHub Copilot could be prompted to regenerate real, previously-seen hardcoded credentials it had encountered during training, producing valid secrets it had memorized from public repositories rather than secrets it invented. The researchers' own audit found that roughly 6.4% of nearly 20,000 Copilot-enabled repositories they examined had leaked at least one secret, a incidence rate meaningfully higher than what shows up in repositories without AI code suggestion enabled. The assistant is not intentionally exfiltrating anything, it is doing exactly what it was trained to do: complete a pattern. If the training data contains a plausible-looking API key in a similar code shape, a plausible-looking key is what comes back, and developers under deadline pressure accept AI-suggested boilerplate, including credential-shaped placeholders, without scrutinizing it the way they would a colleague's pull request.
The third, and the one growing fastest, is configuration-file exposure. MCP servers, the connectors that let assistants like Claude Code, Cursor, and Copilot reach external tools and data sources, are configured through local files (commonly mcp.json, .cursor/mcp.json, or similar) that routinely contain API keys and tokens in plaintext so the assistant can authenticate to the connected service. These files are easy to commit by accident, are rarely covered by the same review process as application code, and according to GitGuardian's 2026 report already account for 24,008 unique exposed secrets on public GitHub, with 2,117 of those still valid when discovered. CSA Labs' research on the AI coding assistant attack surface documented related exfiltration techniques building on this same weak point, including malicious environment-variable manipulation and hidden MCP server definitions used to harvest credentials from AI tool workflows. This is a related but distinct problem from the tool-description manipulation covered in our piece on MCP tool poisoning; here the risk is the credential sitting in the config file itself, not the tool's declared behavior.
Prerequisites before you apply the fix
The procedure below assumes a few things are already true. If they are not, do those first, since the controls in the next section only work on top of a working baseline.
Subscribe to unlock Remediation & Mitigation steps
Free subscribers unlock full IOC lists, Sigma detection rules, remediation steps, and every daily briefing.
Briefings like this, every morning before 9am.
Threat intel, active CVEs, and campaign alerts, distilled for practitioners. 50,000+ subscribers. No noise.
The procedure: hardening the assistant, not just the repo
This is a numbered sequence. Steps 1 through 3 close the config-file and context-window exposure paths specifically; steps 4 through 7 extend your existing secrets-scanning posture to cover AI-generated code before it lands.
Subscribe to unlock Remediation & Mitigation steps
Free subscribers unlock full IOC lists, Sigma detection rules, remediation steps, and every daily briefing.
Validation: confirming the fix actually holds
Do not take a config change at face value. Validate each control with a deliberate, harmless test before trusting it in production.
For the MCP config audit, re-run your secrets scanner against the full git history of your MCP and assistant config paths specifically, not just HEAD, and confirm the finding count matches what you expect after remediation, zero, ideally. For the CI gate, commit a deliberately non-functional placeholder credential (a clearly fake string matching your scanner's detection pattern, never a real key) on a throwaway branch and confirm the pipeline blocks the merge. For telemetry and retention settings, check the admin console's audit log after the change, most enterprise tiers of Copilot, Cursor, and Claude Code log configuration changes with a timestamp and actor, and confirm the setting reads as applied org-wide rather than per-user. For the pre-commit hook, have a developer attempt a commit containing a test secret from a machine that has not yet pulled the latest hook configuration, to confirm the CI backstop catches what the missing local hook would have missed.
Failure cases: where this still goes wrong
Even a fully implemented version of the procedure above has real gaps, and security teams should know them going in rather than discovering them during an incident.
Subscribe to unlock Remediation & Mitigation steps
Free subscribers unlock full IOC lists, Sigma detection rules, remediation steps, and every daily briefing.
Troubleshooting common implementation issues
A few problems come up consistently when teams roll this out, and they are worth anticipating rather than discovering mid-rollout.
If your scanner is not flagging MCP config files despite being added to the include list, check whether the scanner's default file-type detection is skipping .json files in dotfile directories (a common default behavior), and confirm you explicitly listed the path rather than relying on extension-based auto-detection. If developers report the pre-commit hook is slow enough that they are routinely bypassing it, that is a signal to scope the hook to changed files only rather than a full repository scan, since a slow hook gets disabled in practice regardless of policy. If an enterprise admin console setting for telemetry or training-data opt-out appears greyed out or unavailable, confirm you are on a tier that actually includes that control, some of these settings are gated to specific enterprise or business tiers and are not present at all on individual or free-tier accounts. If CI is blocking legitimate test fixtures that intentionally contain fake-looking credentials for unit tests, add an explicit allowlist entry for that specific file and pattern rather than lowering the scanner's overall sensitivity, which reopens the gap you just closed.
Security tradeoffs: friction versus coverage
None of this is free. Requiring explicit review on every AI suggestion touching a config-adjacent file slows down exactly the workflow developers adopted AI assistants to speed up, and teams that set the friction too high will see developers route around it, through personal accounts, unmanaged browser-based chat interfaces, or simply disabling the review prompt if the tooling allows it locally. Conversely, teams that only implement the CI-level backstop and skip the pre-commit and IDE-level controls will catch leaked secrets later, after they have already left the context window and potentially been logged by a third-party vendor, which is too late for the context-window exposure path specifically.
The realistic position is to accept that this is a defense-in-depth problem with no single control that closes every path. Config-file hardening and CI enforcement are non-negotiable and low-friction once automated. Vendor-level telemetry and retention settings are policy-dependent and worth applying but not independently verifiable. IDE-level suggestion review is the highest-friction control and should be scoped narrowly, to credential-adjacent files only, rather than applied universally, or adoption will erode. Teams evaluating whether a given assistant's default posture is acceptable for their risk tolerance, rather than just how to configure the one they already picked, should read this alongside our broader piece on governing AI coding assistants and our analysis of AI-generated code risk more generally, since the secrets-leakage mechanism covered here is one piece of a larger AI-assisted development risk surface.
The bottom line
AI coding assistant secrets leakage is not one problem, it is three: context-window exposure to a cloud model, suggestion-level regeneration of credentials memorized from public training data, and configuration-file exposure through MCP server definitions and assistant rules files. GitGuardian's 2026 data puts AI-assisted commit leak rates at roughly double the GitHub-wide baseline and documents 24,008 unique secrets already exposed in MCP config files alone, 2,117 of them still valid. There is no single control that closes all three paths. Audit and harden your MCP and assistant config files first, since that is the newest and least-covered exposure surface, extend your existing secrets scanner and CI gate to treat AI-generated diffs identically to human ones, lock down vendor telemetry and retention settings at the org level, and rotate anything the audit finds rather than just relocating it. Treat this as ongoing hygiene, not a one-time project, since the assistants and their configuration surfaces keep changing faster than most security teams' inventories do.
Frequently asked questions
Do AI coding assistants really leak secrets more often than manual coding?
Yes, according to measured data. GitGuardian's 2026 State of Secrets Sprawl report found AI-assisted commits leaking secrets at roughly double the GitHub-wide baseline rate, with Claude Code-assisted commits peaking at 31 secrets per 1,000 commits in August 2025, about 2.4 times the human baseline for that period.
How do MCP configuration files cause secrets leakage?
MCP servers, the connectors that let AI assistants reach external tools, are configured through local files such as mcp.json that commonly store API keys and tokens in plaintext so the assistant can authenticate. These files fall outside normal code review and are often missed by secrets scanners unless explicitly added to scan paths, which is how GitGuardian found 24,008 unique secrets exposed in MCP config files on public GitHub.
Can GitHub Copilot actually regenerate real credentials from its training data?
Published research from Hong Kong University demonstrated that Copilot could be prompted to regenerate real, previously-seen hardcoded credentials it encountered during training, and found that roughly 6.4% of nearly 20,000 Copilot-enabled repositories examined had leaked at least one secret in this way.
Does disabling AI training data opt-in settings actually stop context window leakage?
It reduces one specific risk, whether your code and prompts are retained or used to improve the model, but it does not eliminate the underlying exposure of secrets visible in the editor context during a live session, since that data still passes through the vendor's inference endpoint regardless of the retention setting.
Will a pre-commit secrets scanning hook alone prevent AI-related secrets leakage?
No. A pre-commit hook can be bypassed with a flag like --no-verify, and it does not cover context-window exposure or config files outside its scan paths. It needs to be paired with a CI-level enforcement gate, explicit scanning of MCP and assistant config directories, and org-level telemetry settings to meaningfully reduce the risk.
What should a security team do first to reduce AI coding assistant secrets leakage?
Start with an inventory of every AI coding assistant in use across the organization, then audit and strip plaintext secrets from every MCP configuration and assistant rules file, since that is currently the newest and least-covered exposure path, before extending existing secrets scanning and CI enforcement to explicitly cover those file types and AI-generated diffs.
Sources & references
Free resources
Critical CVE Reference Card 2025–2026
25 actively exploited vulnerabilities with CVSS scores, exploit status, and patch availability. Print it, pin it, share it with your SOC team.
Ransomware Incident Response Playbook
Step-by-step 24-hour IR checklist covering detection, containment, eradication, and recovery. Built for SOC teams, IR leads, and CISOs.
Get threat intel before your inbox does.
50,000+ security professionals read Decryption Digest for early warnings on zero-days, ransomware, and nation-state campaigns. Free, daily, no spam.
Unsubscribe anytime. We never sell your data.

Founder & Cybersecurity Evangelist, Decryption Digest
Cybersecurity professional with expertise in threat intelligence, vulnerability research, and enterprise security. Covers zero-days, ransomware, and nation-state operations for 50,000+ security professionals every morning.
