Why Approval Memory in AI Coding Tools Becomes a Secret Leak Source
A security research team's large-scale scan of public code hosting platforms found that a widely used AI coding assistant persists previously approved shell commands into a project-local settings file (such as `.claude/settings.local.json`) after a developer chooses an authorization option like "approve and don't ask again." Those commands often contain database connection strings, access tokens, third-party API credentials, and even plaintext passwords. This article breaks down the incident, why generic secret scanners miss these leaks, the correct incident response order, and how to decouple approvals from credentials at the root.
1. Incident Overview: How a “Convenience Checkbox” Turned into a Credential Vault
A security research team recently scanned public code hosting platforms at scale and found that a widely used AI coding assistant persists previously approved shell commands into a local settings file under the project directory (typically .claude/settings.local.json) once a developer selects an authorization option such as “approve and don’t ask again.” The problem: those persisted commands often contain database connection strings, access tokens, third-party API credentials, and even plaintext passwords.
From an engineering standpoint, this is not “malicious collection” but an efficiency design: since the user already approved a command, the tool records the command text as a whitelist entry so it can skip the confirmation prompt next time. But keeping “commands” as long-lived “configuration” effectively freezes every manually approved payload into a committable text file, mixing the approval record with the credential payload.
The initial quantitative picture is compelling:
- About 104,185 publicly searchable local settings files;
- About 1,122 of them contain at least one secret, totaling roughly 1,379 distinct secrets;
- Expanding the scope to Git commit history, shared settings files, agent run logs, and forks brings the total to about 2,539 secrets across roughly 1,994 repositories;
- Database passwords that connect directly to production databases account for more than one third of the leaked types (about 379 database passwords), with the rest including SSH keys, cloud provider keys, object storage and container registry credentials;
- About half of the repositories had the leak sitting on the default branch for more than 217 days;
- Two commonly used credential scanners in the industry identified only 564 and 643 respectively, with about 215 files missed by both;
- Comparing the product documentation of 16 similar AI coding tools, only this class of tool writes full approved commands into a project file by default.
Three numbers deserve emphasis: “default behavior”, “long-lived on the default branch”, and “massive blind spots in generic scanners”. They correspond to three independent risk surfaces: design flaws, exposure duration, and detection gaps.
2. Cloud Narrative vs. Local Incident: Security Boundaries Are Redrawn
One recent industry discussion focused on “secrets are encrypted in cloud sessions and the model side never sees plaintext.” That is a vertical, link-narrowing security narrative: credentials enter a controlled environment from the client, the model only touches redacted references, and plaintext never lands in the model context.
This incident is a horizontal, post-write spreading reverse failure: the credentials were not seen by the model, but written by the tool itself into files in the developer’s workspace, then spreading along the most ordinary paths—commit, push, sync, fork, CI cache, log collection.
The key difference lies in the shape of the trust boundary:
| Dimension | Cloud Session Security Narrative | Local Config Leak Incident |
|---|---|---|
| Boundary location | Inside the request path | Developer machine filesystem |
| Attack surface | Transport and model context | Version repository and collaboration network |
| Visibility | Platform can audit and redact | Depends on developer awareness and repo config |
| Cleanup cost | Handled centrally on the platform | Requires rewriting history repo by repo |
| Spread speed | Controlled | One push spreads it across the network |
The conclusion: no amount of cloud-side redaction can stop the incident layer where “plaintext has already landed in the project directory and been committed.” Security design for AI coding tools must treat “where approval state is persisted” as a first-class concern—whether it is written to a global config under the user’s home directory or to a visible file inside the project determines an order-of-magnitude difference in risk.
3. Why the “Convenience Checkbox” Is the Most Dangerous Kind of Default
From the classic conflict between human-computer interaction and security, this design hits three traps at once:
- On by default, and inside the project by default. Defaults represent what most users actually do; writing to a project file by default means most users’ credentials are naturally in a “committable” state.
- Weakened authorization semantics. What the user clicks is “stop asking me,” subjectively meaning “reduce interruptions,” but objectively granting permission to “archive this command text long-term.” The form of expression of the authorization does not match the actual consequence—a classic informed-consent failure.
- Naming causes misjudgment. The file name contains
local, which easily leads developers to believe “this is machine-private and won’t enter the repository.” In fact, many teams’ wildcard ignore rules (for example, only ignoring*.local) do not cover compound suffixes like.local.json, so the file is still pulled into a commit bygit add ..
A more subtle point: the tool writes this file path into the machine-global version control exclude list, but not into the repository’s own ignore file. This means the protection “follows the machine” rather than “follows the project”—switch machines, switch collaborators, or rebuild the CI environment, and the protection disappears instantly, while the file is already in history.
4. Breaking Down the Spread Path: How One Commit Becomes Thousands of Leaked Secrets
Abstracting the incident as a data flow makes it clearer why cleanup is so difficult:
[Developer selects "don't ask again"]↓[Full command (with plaintext password) written to .claude/settings.local.json]↓[git add . / IDE one-click commit / scripted batch commit]↓[Push to remote default branch]↓[Clone, fork, CI pull, image build, log collection]↓[Permanent retention in commit history → searchable by search engines and scanning platforms]
Each stage has an amplifying effect:
- Commits are counterintuitive: the local config file’s extension does not match intuition and is almost never noticed during code review;
- History is irreversible: even if the file is deleted later, the objects in historical commits still exist unless history is rewritten and force-pushed;
- Derivative spread: every fork, every CI cache, and every developer’s local clone is a copy, and the leak surface grows linearly or even exponentially with the number of collaborators;
- Time accumulation: remaining on the default branch for more than 200 days shows this kind of leak is rarely discovered proactively, with exposure windows measured in quarters.
5. Why Generic Scanners Miss These Leaks
Two widely used credential scanning approaches hit only 564 and 643 respectively, with 215 files missed by both. The reasons come down to three points:
Rules target “known credential formats.” Most detectors rely on regex and entropy heuristics, which are sensitive to high-entropy strings with fixed prefixes and suffixes like cloud access keys, but weak at recognizing passwords embedded in shell commands, for example:
mysql -h db.internal -u root -p'S3cr3t-Pass!' apppsql "postgres://appuser:Pa55w0rd@10.0.3.12:5432/prod"curl -H "Authorization: Bearer eyJhbGciOi..." https://api.example.internal/v1/export
These strings are wrapped in quotes, parameter names, and escape characters, which dilutes the entropy distribution, so rules easily classify them as ordinary command text.
Scan scope does not include all paths and history by default. Most tools scan only the workspace or the most recent few commits by default, with insufficient coverage of non-source config files, dot-prefixed hidden files, and deep subdirectories; depth parameters and history depth parameters need to be explicitly increased.
Side effects of allowlists and noise suppression. To reduce false positives, tools commonly introduce path ignores, sample file exclusions, and test fake-data filtering, and files like
.local.jsoneasily fall into the “looks like a config sample” ignore range.
Therefore, “the scanner reported nothing” can never be used as a conclusion that “there is no leak.” The real criterion is active verification indexed by “the credential itself,” not passive confirmation indexed by “scanner output.”
6. The Correct Incident Response Order: Rotate First, Then Clean Up
The most important point in the incident’s recommendations is order. Many teams’ emergency reaction is “delete the file + add an ignore rule + commit,” which does the easy things first and postpones the most critical thing. The correct order is as follows.
Step 1: Confirm and freeze (minutes)
- Immediately search the internal code hosting platform in full for the local settings file; the search scope must include the default branch, all feature branches, release tags, and historical commits;
- Freeze external sync and image publishing pipelines for the affected repositories to prevent further expansion of the leak surface;
Example search commands:
# Target files in the current workspace and historygit log --all --oneline -- '*.local.json' '.claude/*'git rev-list --all --objects | grep -iE 'settings\.local\.json'# Search for suspected credential patterns across all historygit grep -nE '(password|passwd|token|secret|api[_-]?key)[[
]]*=' $(git rev-list --all) -- 2>/dev/null | head -n 200
Step 2: Credential rotation (hours, highest priority)
- For each type of potentially exposed credential, perform revocation + reissuance, rather than only modifying the local config file;
- Suggested order: database passwords → cloud access keys → SSH keys and deployment keys → third-party API tokens → container registry and artifact repository credentials;
- After rotation, verify that the old credentials are indeed invalid, avoiding the false security of “changed but not effective”;
- For legacy systems that cannot be rotated immediately, at least apply network-layer restrictions (source CIDR allowlists, least-privilege accounts, temporary disabling of high-privilege logins).
This step cannot be delayed because “investigation is still ongoing.” In practice, the cost of rotation is far lower than the cost of handling an exploited leak, and rotation does not depend on whether cleanup is complete.
Step 3: Cleanup and history governance (days)
- Remove the file from the current branch and add repository-level ignore rules:
git rm --cached .claude/settings.local.jsoncat .gitignore <<'EOF'# Ignore local authorization files from AI coding tools.claude/*.local.json*.local.yaml*.local.ymlEOFgit commit -m "chore: remove local agent settings from VCS"
- If the repository can be governed collaboratively, use history rewriting tools to clean sensitive objects from history, force-push, and notify all collaborators to re-clone;
- If the repository is shared by many people or has a large number of forks, evaluate the “coordination cost of rewriting history,” and if necessary adopt the pragmatic strategy of “treat it as leaked, only rotate and monitor.”
Step 4: Detection hardening (weeks)
- Add a two-layer detection of pre-commit hooks + server-side credential scanning in the CI pipeline, with scan scope covering full history and all file types;
- Customize rules to cover the “credentials embedded in commands” scenario, such as separate rules for connection strings, long parameter strings, non-empty values after
-p, and-H "Authorization: ..."patterns; - Perform a one-time full retrospective scan of historical leaks, output a credential inventory, and close the loop item by item;
- Build alerts: notify security on-call in real time when a specific sensitive file name appears in a repository, or when commit content hits a high-priority rule.
7. Root-Cause Governance: Fully Decouple “Authorization” from “Credentials”
Incident response solves “this leak”; root-cause governance solves “it never happens again.” There are four core ideas.
1. The authorization allowlist records only “patterns,” not “instances”
When a user approves a command, they should be guided to authorize a parameterized pattern, not the full text of a specific command:
{"permissions": {"allow": ["Bash(npm run:*)","Bash(git status)","Bash(pytest:*)"],"deny": ["Bash(mysql:*)","Bash(psql:*)","Bash(ssh:*)","Bash(curl * -H *Authorization*)"]}}
The benefits are twofold: it keeps credentials out of the config file, and it makes the authorization granularity fit the real intent (“allow running tests” rather than “allow running this one command with a password”).
2. Clearly distinguish “machine-level config” from “project-level config”
- Machine-level: global preferences, cross-project authorizations, personal credential references, stored in the user’s home directory and naturally never entering the repository;
- Project-level: team-shared permission policies and configs that require review must enter the repository and be included in code review;
- At either level, sensitive values must not be inlined and can only exist as references (such as an environment variable name or an alias for an entry in a key management service).
3. Externalize credentials: environment variables, key management services, and short-lived tokens
# Bad example: credentials inlined in the command are recorded verbatim by the toolmysql -uroot -p'Prod-Pass-123' appdb# Good example: credentials injected at runtime, the command text itself contains no secretMYSQL_PWD="$(cat /run/secrets/db_password)" mysql -uroot appdb# Good example: use short-lived tokens + automatic rotation to reduce long-lived riskexport CLOUD_TOKEN="$(cloud-cli token issue --ttl 15m)"
A more thorough engineering approach is to let the tool never touch real credentials: a controlled credential proxy or local sidecar injects them, and the tool only calls quoted placeholders.
4. Organization-level policies and engineering constraints
- Enable push protection on the hosting platform to reject pushes directly when a suspected credential is detected;
- Enable default branch history protection and mandatory review to prevent config file changes from being silently merged;
- Build a credential inventory: record the ownership, permission scope, rotation cycle, and revocation process of each credential type, shifting rotation from “incident-driven” to “cycle-driven”;
- Conduct admission evaluation for AI coding tools: whether they write to project files by default, whether they support authorization patterns, whether command persistence can be disabled, and whether they are compatible with enterprise key proxies.
8. Enterprise Implementation: From “Scan—Respond—Insight” to “Eliminate—Accept—Transform”
When building a protection system in the cloud, organizations typically go through four stages of increasing maturity:
- Scan: rely on generic scanners to find problems, characterized by limited coverage and both false positives and false negatives;
- Respond: manually rotate and clean up after discovery, characterized by being passive, lagging, and prone to missing history;
- Insight: aggregate scan results into a unified logging, monitoring, and alerting system, forming an organization-level leak posture view and identifying high-risk repositories and teams;
- Eliminate and accept: through credential externalization, short-lived tokens, push protection, and authorization patterns, make “credentials appearing in config files” technically impossible.
The integration points with general cloud capabilities are mainly:
- Key management services centrally host sensitive values, supporting versioning, access auditing, and automatic rotation;
- Identity and access management enforces least privilege and separation of duties, preventing a single high-privilege account from being amplified by a credential leak into a full-domain compromise;
- Code hosting and pipelines insert credential detection and admission checks at commit, merge, build, and deploy nodes;
- Logging services and monitoring alerts build baseline alerts for behaviors like “use of old credentials from abnormal sources” and “high-privilege calls outside working hours,” which are key signals for discovering that “a leak has been exploited”;
- Object storage and artifact repositories verify source and signature at the distribution stage to prevent secondary outflow of artifacts carrying sensitive information.
Notably, the value of cloud protection is not to replace developer-side governance but to turn uncontrollable “human diligence” into controllable “platform enforcement.” When credential issuance, injection, rotation, and revocation are all consolidated on the platform side, even if a command text remains in a config file, it no longer equals a substantive leak.
9. Action Checklists for Different Roles
Individual developers
- Check whether the project has a local authorization config file, and if so, confirm whether it has been committed;
- If it has been committed and contains real credentials, rotate through the internal process first, then handle the file and ignore rules;
- Prefer “allow by pattern” for daily authorizations, and avoid selecting “don’t ask again” for commands with parameters;
- Confirm the new file list with
git statusbefore committing, and stay alert to dot-prefixed hidden files.
Teams and technical leads
- Include an “AI coding tool admission checklist” in engineering standards, specifying the default write location and what can be disabled;
- Preconfigure ignore rules and pre-commit detection in repository templates so security defaults do not depend on individual habits;
- Regularly conduct credential exposure drills to test the actual time cost of the “discover—rotate—verify” chain.
Security and platform teams
- Expand detection scope from “source code” to “all file types + full history + derivative repositories”;
- Build dedicated detection rules and baseline false-positive evaluation for “credentials embedded in commands”;
- Establish a credential inventory and rotation cycle system, replacing incident-driven temporary remediation with cycle-driven rotation;
- Apply push protection and mandatory review to high-risk repositories, forming a platform-level safety net.
10. Conclusion: The Boundary Between Convenience and Security Should Be Defined by Defaults
This incident is not technically complex, but the pattern it reveals is very typical: when a security-relevant “convenience item” is enabled by default and persisted to a project-visible file, a leak is only a matter of time. When a developer clicks “don’t ask again,” they mean “reduce interruptions,” but the tool translates it into “archive this command, along with the password inside it, into your code repository.”
Three conclusions are worth taking away:
- Rotation before cleanup. Files can be deleted, but history is hard to erase; once a credential leaves the controlled scope, it should be treated as leaked by default.
- No scanner alert does not mean no risk. Default rules target known credential formats and have systematic blind spots for command-embedded passwords, so active verification indexed by credentials is required.
- The key to governance is decoupling. Let “authorization” record only patterns, let “credentials” exist only in key management infrastructure, and let “defaults” stand on the side of security—that is the sustainable approach.
For teams that rely heavily on AI coding tools, one simple thing to do today: search your enterprise code hosting platform in full for that settings file with local in its name.
