How AI Coding Assistants Turn Auto-Approval Into Secret Leakage
This article examines how the "Yes, and don't ask again" option in AI coding assistants can quietly turn a convenience feature into a secret leakage source. When an approved shell command contains plaintext credentials, the tool may persist the full command text into local settings files, which are then committed to repositories and pushed to public hosting platforms. Based on a recent security scan of public code hosting platforms, the article outlines the leakage scale, explains why traditional secret scanners often miss these files, clarifies common misconceptions about Git ignore rules and history, and provides a practical remediation workflow: rotate exposed credentials, clean version history, fix ignore policies, approve command patterns instead of literal commands, and embed secret scanning into the development process. It also discusses the broader trust-boundary implications of AI-assisted development.
Event Overview: How a Convenience Option Triggers a Chain Reaction
Recently, a security research organization performed a systematic scan of public code hosting platforms and surfaced a widely overlooked risk: when a mainstream AI coding assistant processes command-line approval, selecting the convenient “Yes, and don’t ask again” option causes the tool to record the entire approved shell command into a local settings file inside the project (typically in a form such as .<tool-name>/settings.local.json).
The problem is not the act of recording itself, but the content being recorded. When an approved command contains plaintext database passwords, access tokens, or keys, this sensitive information becomes fixed inside the configuration file. Once developers commit the file and push it to a public repository, the convenience mechanism originally designed to “remember your preferences” turns into a trigger for leakage.
It is worth noting that this is a different layer from privacy narratives such as “cloud session encryption” or “plaintext not visible to the model”: the latter concerns whether data is exposed during transmission and inference, whereas this incident occurred at the local file persistence and version-control stage—a reverse accident in the design of “convenience features and credential management.”
Root Cause: A Structural Conflict Between Convenience and Security
Understanding this incident requires first unpacking the design logic behind “auto-approval without confirmation.”
Before executing shell commands, AI coding assistants typically request authorization from users to prevent the tool from running risky operations on its own. The essence of the “don’t ask again” option is a form of trust persistence based on command patterns: the tool persists the fact that “the user has approved executing a certain type of command” as a rule on disk, and automatically permits matching commands the next time they appear.
The focal point of the conflict is the granularity of trust:
- Ideal case: trust should be bound to the “structural pattern of commands,” for example, “allow running
npm runscripts.” - Actual case: many tools choose to record the complete literal text of the command, including all arguments and values.
# A user executes a command with plaintext credentials in the terminalmysql -h db.prod.internal -u admin -p'S3cr3t_P@ssw0rd' mydb# After selecting "don't ask again", the configuration file is written with content similar to the following{"permissions": {"allow": ["Bash(mysql -h db.prod.internal -u admin -p'S3cr3t_P@ssw0rd' mydb)"]}}
Once persisted in this way, the password changes from “one-time input” to “persistent storage” and enters the version-control chain along with the configuration file. This is the technical core of the problem: treating the original text of credential-bearing commands as persistable trust credentials.
Leakage Scale: A Bleak Reality Revealed by Data
The scan data published by this organization provides a quantitative picture of this risk:
- Baseline scope: among approximately 104,000 public local settings files (
settings.local.json), about 1,122 files contain at least 1 key, totaling about 1,379 distinct keys. - Expanded scope (including git history, shared
settings.json, agent run logs, repository forks, and other sources): leaked keys rose to about 2,539, involving about 1,994 repositories. - Leakage composition: more than one-third are passwords that can directly connect to databases (about 379 database passwords), with the remainder including SSH keys, cloud provider access keys, and others.
- Exposure duration: about half of the repositories’ leaked content had been exposed on their default branch for at least about 217 days.
These numbers send a clear signal: the leakage is not sporadic isolated cases, but a systematic problem at scale and over long periods. The high proportion of database passwords is especially concerning—it means attackers may reach the data layer directly, rather than stopping at the code or configuration level.
Scan Blind Spots: Why Traditional Tools Miss These Cases
Many teams have introduced secret-scanning tools (such as various open-source secret detection tools) as a protective measure. However, this incident exposed a critical weakness: detection tailored to generic key formats struggles to cover the AI tool’s unique persistence approach.
Statistics show that two common secret scanning tools flagged only about 564 and 643 of these cases respectively, and another approximately 215 configuration files were missed by both.
The causes of under-reporting can be understood from three angles:
- Limitations of pattern matching: most scanning tools use regex or entropy to identify strings that “look like keys.” If the credential in a command uses a custom format, is URL-encoded, or is embedded in command-line arguments in a non-standard way, generic rules may fail to match.
- Incomplete detection locations: default scans usually target only current files in the workspace and commit history, and may not cover derived sources such as agent run logs or forked branches—precisely the part that caused the expanded scope to surge.
- Blind spots for file types:
.jsonlocal settings files are not on the traditional “sensitive file” list, and scanners often treat them as ordinary configuration and lower their priority.
Misconceptions About Local Config Protection: Ignored Rules Do Not Follow the Project
Many AI coding assistants adopt a seemingly reasonable protection measure when handling local settings files: they write the file into the local machine’s global git excludes, so it will not be accidentally committed locally.
However, this design has a commonly misunderstood boundary:
- Global
git excludesonly applies to the current developer’s machine; it does not enter the repository’s own.gitignore. - This means the file’s “ignored” state does not follow the project’s distribution. When another collaborator clones the repository, or when operating on the same machine with a different global configuration, the protection fails.
- More critically: for files that have already been committed, merely deleting them does not erase the history.
# Wrong assumption: thinking deleting the file resolves everythingrm .tool/settings.local.jsongit commit -m "remove local settings"# —— But the sensitive content still exists in some commit in the history
Why Deleting Files Won’t Save You: Git History Is “Memory”
Git is essentially a content-addressed distributed version control system. Once a file is committed, its content is fixed into a commit object and can be fully reconstructed through history. Deleting the working-directory file, or even deleting the file from the current branch, merely adds a new “deletion” operation; the plaintext in the old commit still exists.
Anyone with access to the repository history (including copies forked out, caches, mirror sites, and search engine snapshots) can reconstruct it as follows:
# Traverse history to view every past version of the filegit log -p --all -- .tool/settings.local.json# Or view the content directly in a historical versiongit show <commit-hash>:.tool/settings.local.json
Therefore, “deleting a file” and “eliminating leakage” are two entirely different problems. The former is an operational cleanup, while the latter requires handling both the credentials themselves and the history records simultaneously.
Systematic Protection: From Emergency Response to Long-Term Governance
In the face of this type of risk, it is recommended to build a protection loop in the order of “first stop the bleeding, then clean up, then solidify.”
Step 1: Rotate Keys Immediately (Stop the Bleeding)
Since the file may already be public, you should assume all credentials appearing in commands have been leaked. The first action is to revoke and reissue these keys, passwords, and tokens, because once exposed, the exposure duration cannot be undone; the only way to stop the loss is to invalidate the old credentials.
- Database passwords → change immediately and check access logs for abnormal connections- Cloud access keys → disable old keys, issue new keys and narrow permission scope- SSH private keys → revoke corresponding public key authorization and regenerate the key pair
Step 2: Clean Version History (Eliminate)
After the keys are invalidated, then process the history records. If clearing is truly necessary, use tools that rewrite history (such as git filter-repo or similar solutions), force-push, and notify collaborators to re-clone.
# Remove a specified file from all history (illustrative)git filter-repo --path .tool/settings.local.json --invert-paths# Force-push and notify the team to re-clone (high risk, requires coordination)git push --force --all
Please note that history rewriting is a high-risk operation that changes commit SHAs and must be coordinated with the team before execution.
Step 3: Fix the Ignore Policy (Solidify)
Add the local settings file to the repository-level .gitignore so that protection is distributed with the project:
# .gitignore —— commit this file to make protection effective for everyone.tool/settings.local.json
At the same time, if the tool has already tracked this file from version control, it needs to be untracked:
git rm --cached .tool/settings.local.jsongit commit -m "chore: stop tracking local settings"
Step 4: Pattern-Based Approval (Address the Root)
This is the key step to fundamentally eliminate risk. Do not approve “specific commands containing credentials”; instead, approve “structured command patterns,” binding trust to intent rather than literal content:
// Recommended: authorize by command prefix/pattern without involving any credentials{"permissions": {"allow": ["Bash(npm run:*)","Bash(git status)","Bash(pytest:*)"],"deny": ["Bash(mysql:*)","Bash(* -p *)"]}}
When a command truly needs to carry credentials, you should instead rely on environment variables or a dedicated secret management/credential vault, keeping sensitive values outside command text and version control:
# The command only references variable names, with no plaintext appearingmysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME"
Step 5: Embed Scanning into the Development Workflow (Prevent Recurrence)
- Enforce secret scanning in pre-commit hooks and CI pipelines to block credential-bearing commits from entering the main branch.
- Add dedicated detection rules for AI tool persistence files (local settings files, agent logs) to fill the blind spots of generic scanners.
- Perform a full retrospective scan of historical repositories, rather than scanning only new commits.
Deeper Reflections: Trust Boundaries in the Age of AI Programming
The lessons from this incident go beyond a single tool or a single accident. As AI coding assistants become deeply involved in the development workflow, the design of “trust granularity” is becoming a new proposition in security engineering.
Traditional security focuses on “who can access what,” while AI coding assistants partially delegate decision-making power to a one-click selection in natural language interaction. When convenience features like “remember my choice” default to an implementation that “records the complete original text,” they inadvertently shift the responsibility of credential management from dedicated secret systems to ordinary configuration files—often without the developer’s knowledge.
A common observation in the industry is that among mainstream coding agent products, the behavior of persisting complete approved commands to project files by default is not unique, but it is far from a common practice. This reminds us that when selecting and configuring such tools, we should proactively examine their approval persistence granularity, storage location, and ignore policies, rather than accepting the vendor’s convenience settings by default.
For developers and enterprises, three principles can be distilled:
- Convenience features must be secure by default: any mechanism that “persists user choices” should default to desensitizing sensitive content or storing it by pattern.
- Credentials must never enter version control: whether in the form of commands, configuration, or logs, credentials should be passed through a dedicated secret management channel.
- Assume leakage has occurred: for credentials exposed in public environments, the only reliable assumption is “leaked,” and remediation should prioritize rotation.
Conclusion
A checked “don’t ask again” option may seem to only save the trouble of repeated confirmation, but it can actually bury thousands of searchable keys in project configuration files. This incident clearly demonstrates that the implementation details of convenience are often the weak points of security boundaries. For developers, understanding three questions— “how approval mechanisms persist,” “why local files are not protected with the project,” and “why deleting does not equal erasing”—is the key to shifting from passive remediation to proactive protection. Hand keys back to a dedicated secret management system, bind approval to command patterns rather than literal content, and make secret scanning a routine checkpoint in the development workflow—only then can we hold the line against leakage while enjoying the efficiency benefits of AI programming.
