How AI Coding Tools Leak Credentials: Causes and Protections

    A common risk with AI coding assistants: authorization decisions meant to reduce repeated prompts get stored in local config files, sometimes alongside the original commands that may contain plaintext credentials. This article explains how that happens, how secrets end up in Git history, and what developers and teams can do to prevent and respond to leaks.

    A related leak incident has been publicly reported, but the statistics cited in the original material lack verifiable sources, so this article skips specific numbers and focuses on the risk mechanism and mitigations.

    Where the Risk Comes From

    AI coding tools typically ask for confirmation before running a shell command. When a user chooses “Yes, and don’t ask again,” the tool writes an allow rule to a local project config file — in the reported case, settings.local.json. The problem: the file may store not just the authorization decision but the command text itself. If a developer has ever typed a database connection string, API key, or service password directly into a command line, that plaintext gets persisted.

    The more often approvals are granted, the more sensitive content accumulates. A one-off operation may leave only a small trace, but over time the file becomes a centralized, unencrypted, access-uncontrolled credential store.

    How Credentials Reach the Repository

    Local config files are supposed to be excluded via .gitignore. In practice, several scenarios bypass this protection:

    1. Running git init and committing files before adding ignore rules. .gitignore does not affect files already tracked by Git.
    2. The project is cloned to a new machine or distributed as a template, and the new environment lacks the same ignore rules.
    3. The tool automatically commits config changes in some scenarios, and the user never reviews them item by item.

    Users had reportedly flagged similar issues before, but the reports went unaddressed for a long time — a reminder that feedback channels and response processes matter too.

    Three Root Causes

    First, blurred trust boundaries. Authorization state and sensitive data live in the same file with no separation. A better design keeps authorization rules and credentials apart, and detects and redacts sensitive content before writing.

    Second, ignore rules are unreliable. They depend on every machine and every team member configuring things correctly. The longer a repository lives and the more collaborators it has, the higher the chance of a miss.

    Third, history is persistent. Even after the file is deleted from the working tree, its contents remain recoverable from past commits by anyone who clones the repo. Deleting a file does not undo a leak.

    What Developers Should Do

    1. Never put passwords or tokens directly in commands. Use environment variables or a secrets management service, and reference only variable names in commands.

    2. Scan before committing. The following Git hook runs gitleaks against staged changes at commit time:

    1. #!/bin/sh
    2. # Save as .git/hooks/pre-commit, then run: chmod +x .git/hooks/pre-commit
    3. # gitleaks must be installed first (v8.19+ supports the "gitleaks git" subcommand)
    4. if ! command -v gitleaks >/dev/null 2>&1; then
    5. echo "gitleaks not found; commit blocked." >&2
    6. exit 1
    7. fi
    8. gitleaks git --pre-commit --staged --redact

    When gitleaks detects a suspected credential, it exits with a non-zero status, blocking the commit. Since developers can bypass local hooks with git commit --no-verify, a scan should also run in CI.

    3. Treat any credential that lands in a config file as compromised. Whether or not the file was pushed, revoke the old credential and issue a new one in the provider’s console.

    4. If the file is already tracked, stop tracking it, then add the ignore rule:

    1. git rm --cached <path-to-config-file>
    2. echo "<path-to-config-file>" >> .gitignore

    What Teams Should Do

    Teams need to turn individual habits into verifiable processes. Four baseline measures:

    Measure Requirement Owner Frequency
    Pre-commit scanning Local hooks plus CI re-scanning Engineering productivity team Every commit
    Credential rotation Rotate database passwords and cloud tokens regularly; rotate immediately after any suspected leak Security team Quarterly, and on incident
    Git history cleanup On discovery of leaked data in history, rotate credentials first, then evaluate rewriting history with git filter-repo or BFG Security team and repo admins Event-driven
    Access auditing Retain logs of repo pushes and credential usage, traceable to machine and time Security team Monthly spot checks

    History cleanup is expensive: rewriting history changes every commit hash, collaborators must re-clone, and force pushes can disrupt work in progress. Rotate credentials first so historical secrets become invalid; whether to rewrite history should be a team decision.

    How Tools Should Change

    Vendors should follow secure-by-default principles. Reasonable improvements include:

    1. Storing authorization rules separately from credentials, and never persisting raw command text.
    2. Detecting credentials before writing, replacing them with environment variable placeholders, and storing real values in the system keychain or encrypted storage.
    3. Requiring explicit user approval for any automatic commit, with a diff preview beforehand.
    4. Keeping audit records of when operations occurred and which rules triggered them.

    Auto-extracting secrets and centralizing them expands the attack surface in itself. Tools should handle secrets only with explicit user consent and under the principle of least privilege.

    Conclusion

    Incidents like this show how convenience features — local persistence plus automatic commits — change the risk profile. Developers can start with three steps: check which local config files Git is tracking, add commit-time scanning, and rotate credentials immediately upon discovery. Teams should embed these actions into their processes and verify them regularly.