In-depth articles on technology shaping what comes next.

AI Agent Secret Leaks: Scanning vs Containment

AI coding agent secret leaks via 'Don't ask again' allowlists: secret scanning vs containment compared, with guardrails that stop committed credentials.

A mechanical switchboard where one lever labeled by position routes glowing cables, some of which spill light out of the panel
Permission allowlists feel like control, but they quietly archive every command you've ever approved — secrets included.

Security researchers just found passwords, API tokens, and cloud credentials sitting in more than a thousand public GitHub files — not in sloppy .env files, but in AI coding agent settings. The culprit is a quiet pattern around AI coding agent secret leaks: developers approve a command like curl -H "Authorization: Bearer sk-...", click "Don't ask again," and the full command — token included — gets written to a local settings file. Commit that file, and the secret is public. I've spent years doing infrastructure security, and this is one of the most avoidable leak classes I've seen. It's also a genuinely new one, because the file that leaks it didn't exist two years ago.

The two defenses teams reach for are secret scanning (detect the leak, then clean up) and containment (make sure the secret never touches the agent or the repo in the first place). Both are necessary. Neither is sufficient alone. This piece compares them head to head — when each one wins, where each fails — and ends with what I'd actually deploy on a team using Claude Code, Cursor, or any agent with a permission allowlist.

One thing to get out of the way first: this isn't an argument against agentic coding tools. I use them daily and wouldn't go back. The permission prompt — the agent asking "may I run this?" — is genuinely one of the better safety mechanisms these tools ship. The problem is purely what happens after you say yes: where that "yes" gets recorded, and what it contains.

How the Allowlist Becomes a Secret Store

To understand the failure mode, you have to look at what "Don't ask again" actually persists. When an agentic CLI asks to run a command, the naive implementation stores the full command string in the permission rule. Not a pattern. Not a hash. The literal string you approved.

So when a developer approves aws s3 cp s3://bucket/backup.sql . --profile prod that's harmless. But when they approve psql postgresql://admin:hunter2@db.internal/myapp or curl -u deploy:APIKEY123 https://.../deploy, the credentials are now sitting in .claude/settings.local.json or the equivalent config. The settings file is designed to stay local — Claude Code even auto-gitignores it when the tool creates the file itself. But if the developer created the file manually, or force-added it, or their global gitignore doesn't cover it, one git add . and a push later it's on GitHub. That's exactly the chain behind the 1,122 files researchers found.

Notice how many links in that chain are individually reasonable. Approving a command with an inline credential is something developers have done interactively for decades with zero consequence — the command runs, the shell history holds it locally, nobody cares. Clicking "Don't ask again" is rational; the prompt fatigue is real, and the whole selling point of these agents is reduced interruption. Even git add . is defensible when the tool told you the file was local. The incident isn't caused by one careless act. It's caused by a system where five harmless acts compose into a public credential. Those are the worst kind of security failures to fix, because no individual sees themselves doing anything wrong.

I've seen this exact mistake in the wild before agents existed. A team lead at a fintech I consulted for had an allowed_commands.sh for a CI helper bot — the same idea, hand-rolled. Someone approved a one-off database migration command with the DSN inline. Six months later the repo was open-sourced, and the DSN was in the git history of a file nobody thought to audit because it "wasn't config." The file was config. It just didn't look like it.

That's the core insight: permission allowlists are configuration files that capture operational secrets as a side effect. Nobody reviews them for secrets because nobody thinks of them as secret-bearing. Your secret management policy covers .env, credentials.yml, maybe Terraform state. It almost certainly doesn't cover .claude/settings.local.json or .cursor/ configs. We wrote about a similar blind spot in auditing API clients as credential vaults — the tools you use daily accumulate secrets in places your policy doesn't name.

And the category is growing. Every agentic tool that launched in the past couple of years has some variant: allowlists, trusted directories, remembered approvals, MCP server configs with inline tokens. Each one is a fresh file path that your existing policies, gitignores, and scanner configs don't mention. The next version of this incident will be the same mistake in a file with a different name.

Secret Scanning vs Containment: The Two Defenses

Here's the comparison I'll run through the rest of the piece:

  • Detection-first (secret scanning): pre-commit hooks, repo scanners like gitleaks and trufflehog, push-protection from GitHub or GitLab, plus periodic history scans. Assume secrets will leak; catch them fast and rotate.
  • Containment-first (keep secrets out): secrets only enter commands via environment variables, password manager CLIs, or short-lived credentials; agents run in sandboxes or ephemeral VMs; local settings files are globally gitignored. Design so there's nothing to leak.

Detection is a cleanup operation. Containment is a design property. They fail in opposite directions: scanning has false negatives and always runs after the fact; containment has an adoption cost and fights developer friction. When each wins depends on which failure mode you can tolerate.

There's also an asymmetry in how they degrade over time. Scanning degrades gracefully — a missed secret is bad, but the ones it does catch still get caught, and rulesets improve. Containment degrades by exception. Every time a developer works around the friction — "just this once, I'll paste the token directly" — the property weakens, and there's no log of the weakening. You find out the containment failed the same way you find out a lock was left open: when someone checks. This is why the two belong together rather than as rivals, but also why I weight them differently. The section below explains why scanning, despite being the industry's default answer, is the weaker of the two for this particular leak class.

Secret Scanning: Strengths and Hard Limits

Secret scanning wins when the leak has already happened or is about to — which, given human nature, is a lot of the time. GitHub's push protection blocks known token formats at push time. gitleaks in a pre-commit hook catches a surprising amount before it leaves the laptop. If you do nothing else from this article, do this:

# .pre-commit-config.yaml
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.4
hooks:
- id: gitleaks

Ten minutes of setup, and the specific leak class from this story — a token in a committed settings file — mostly disappears, because gitleaks doesn't care that the file is a JSON settings file. It scans content, not filenames. Add a regex for your internal token prefixes if you have them.

There's one more scanning layer worth having that teams forget: scanning your own local machine, periodically, for uncommitted secrets. The repo-level hooks only fire at commit or push time. A settings file that sits on disk for three months before someone runs git add . is a three-month window where the secret is one command away from public. A scheduled job — even a weekly cron that runs gitleaks over your home directory's dotfiles — closes that window to days. It's ugly, but it works.

But scanning has three hard limits that the Claude Code story exposes nicely. First, entropy-based detectors miss low-entropy secrets. A password like Winter2024! in a psql connection string won't trip an entropy check, and if it isn't a known provider format, no rule matches it. The researchers found plenty of plain passwords, not just AWS-style keys. Second, scanning is post-hoc at the push layer. Push protection stops the push, which is great — but if it doesn't fire, the secret is in history, and history is forever. Rotating after a leak means hunting down every place the credential was used, and I've never seen that cleanup take less than a day. Third, scanning creates a false sense of completeness. Teams see the green checkmark and stop thinking about how secrets flow. As we've argued before in our piece on AI security scanners, a scanner is a safety net, not a substitute for not falling.

On that second point, it's worth being precise about what "cleanup" actually involves when a credential does hit a public repo, because teams chronically underestimate it. Rotation is the easy part — revoke the token, issue a new one, update the secrets store. The hard part is the archaeology: every deploy pipeline, cron job, developer laptop, and third-party integration that used the old credential has to be found and updated, and missing one means an outage at the worst possible time. Then there's the mirror problem: if the repo is public, you have to assume the secret was scraped within minutes. Credential-harvesting bots watch the GitHub event stream continuously. By the time your scanner alerts, the secret has likely been cloned, indexed, and possibly tried against your production endpoints. Detection bought you awareness. It did not buy you safety.

That said, I want to be fair to scanning, because it gets dismissed too easily in these debates. For large organizations with hundreds of repos and thousands of developers, scanning is the only layer that scales without behavior change. You cannot train your way out of a leak at that scale, but you can push-protect your way out of most of it. If you're a platform team deciding where to spend your first week of effort, the answer is scanning — it's cheap, centralized, and catches the high-entropy provider tokens that cause the most damage. Just don't mistake it for the whole solution.

A fishing net with large holes being pulled from dark water, most glowing fish escaping through the gaps while a few are caught
Scanning catches the secrets it recognizes — low-entropy passwords and novel formats slip through.

Containment: Env Vars, Sandboxes, and Short-Lived Credentials

Containment wins everywhere the secret would otherwise be written down — which is precisely where this incident lives. If the credential never appears as a literal string in a command, the allowlist has nothing dangerous to store. The approved command becomes curl -H "Authorization: Bearer $DEPLOY_TOKEN" ..., and the settings file contains a harmless variable name. Two rules cover most of it:

  • Secrets enter commands only through environment variables or indirection ($TOKEN, $(op read ...), a config file the agent reads at runtime) — never as literal values.
  • Agent-local config directories (.claude/, .cursor/, .aider*) go in your machine-wide global gitignore (~/.config/git/ignore), not just per-repo, so no project can ever commit them.
# Global gitignore covers every repo on this machine
git config --global core.excludesFile ~/.config/git/ignore
cat >> ~/.config/git/ignore <<'EOF'
.claude/
.cursor/
.aider*
.env*
EOF

Why global rather than per-repo? Two reasons. First, per-repo gitignores only exist if someone remembers to add them to every new repository, and new repositories are created precisely when nobody is thinking about security hygiene. Second, a global gitignore is machine policy, not project policy — it can't be accidentally removed in a pull request that "cleans up the gitignore," which I have genuinely watched happen. The per-repo version protects a repo. The global version protects a developer, and the developer is the unit that's leak-prone here.

The env-var rule deserves the same scrutiny, because it has a subtle failure mode: shell profiles. If the developer "solves" the env-var requirement by exporting DEPLOY_TOKEN=sk-... in their .bashrc, you've moved the secret from one unreviewed dotfile to another. The rule has to terminate at a real secrets backend — 1Password CLI, direnv reading from an encrypted store, a cloud secrets manager with aws ssm or op inject at session start. The agent gets the variable; the disk never gets the value. It's one extra indirection, and it's the difference between containment and cosmetics.

The stronger version of containment is what I'd call real sandboxing: run the agent in an ephemeral VM or container per task, on an isolated network, with a proxy in front of external APIs. One practitioner setup I admire puts an API proxy between the agent and a god-mode SaaS key: reads flow through, writes require a tap on a phone. That's defense in depth done right — even a fully compromised agent with --dangerously-skip-permissions can only touch what the proxy allows. We covered the broader trade-off in containment vs monitoring for AI agents; this story is a point for containment.

Short-lived credentials are the other half of the strong version, and they're underrated because they shrink the blast radius even when every other layer fails. A static AWS access key leaked to GitHub is valid until someone notices. An OIDC-issued credential with a one-hour TTL that's leaked to GitHub is a log entry. If your cloud provider supports workload identity federation — and all the major ones do — the agent's credentials should expire faster than your incident response process can even convene a meeting.

The honest cost of containment is friction. Password manager CLIs mean fingerprint prompts mid-task. Ephemeral VMs mean setup time and cold-start latency on every run. Scoped proxies mean someone has to build and maintain the proxy. For a solo developer on a side project, full sandboxing is overkill and the global-gitignore-plus-env-vars version is the right call. For a team whose agents touch production credentials, the friction is the price of not being the next breach disclosure.

The Middle Layer: Fixing the Allowlist Itself

There's a third option that tool vendors own, not you: don't store the literal command. A permission rule that persists curl -H "Authorization: Bearer *" as a pattern — with argument values redacted — is just as usable for matching and carries no secret. Claude Code's team has said they're looking at preventing exactly this class, and their recommended direction is an auto permission mode that doesn't require maintaining allow/deny lists at all. That's the correct instinct. Every manually maintained allowlist is a future incident with a timestamp you can't see yet.

Pattern-matching isn't a free lunch, to be clear. A glob like curl * matches the benign deploy command and the malicious exfiltration command equally well, so aggressive redaction trades leak risk for approval-breadth risk. The right design is probably structural rather than textual: persist which binary and which flags were approved, never the argument values. That keeps the matching precise (yes to curl with headers, no to curl piping to a new domain) without storing anything a credential could hide in. Vendors will get there; the incentive is now a thousand-plus public files of evidence.

Until vendors ship that, you can approximate it with hygiene: periodically run a scanner over your local settings files themselves. A one-liner like gitleaks detect --no-git --source ~/.claude .claude audits the exact files this story is about, before they're anywhere near a repo. Add it to your dotfiles setup script and it costs nothing.

My Recommendation: Containment by Default, Scanning as the Net

If forced to pick one, pick containment. A leak that never happens beats a leak detected quickly, every time. Scanning is what you rely on when containment fails — and it will fail, because someone will paste a connection string into a chat at 1 a.m. — but it should be the exception handler, not the policy.

Concretely, for a team rolling out agentic coding tools this quarter, in order of effort:

  1. Global gitignore for agent config directories on every developer machine — five minutes, kills the committed-settings leak entirely.
  2. Rule: secrets only via env vars or a password manager CLI, never inline in commands. Put it in onboarding, not a wiki nobody reads.
  3. gitleaks as a pre-commit hook plus push protection on the forge — the safety net for everything above.
  4. Short-lived, scoped credentials for anything the agent touches (OIDC-issued cloud creds instead of static keys), so a leak expires in hours.
  5. For agents with production access: ephemeral sandbox plus an API proxy that scopes what the agent's credentials can do.

Note the ordering. The two cheapest items are containment, and they eliminate the entire incident class rather than shrinking its probability. The scanning items come third, not first — not because they're unimportant, but because they're the net under the trapeze, and you rig the net after you've checked the ropes. Items four and five are where you stop defending against accidents and start defending against compromise, which is where agentic tools are heading whether we plan for it or not.

A fortress wall with a small gate, behind which sits a second inner wall and a locked vault at the center
Layered containment: even if the outer wall fails, the vault holds nothing static worth stealing.

The first two items alone would have prevented essentially every file in the researchers' dataset. That's the frustrating part of this incident: it isn't a sophisticated attack. It's a new file type carrying an old mistake, and the fix is the same hygiene we've been preaching since the first committed .env — applied to a directory nobody's policy mentions yet.

Update the policy. The agents aren't going anywhere, and neither is the "Don't ask again" button.