Blog

How Coding Agents Leak Secrets

Coding agents leak secrets via saved approvals, context windows and stored traces. What the Claude Code and Cursor incidents show and how to close each gap.

Security6 min readBen @ Grepture

The secrets aren't only in your code anymore

Secret scanning was built for source code: a developer commits an AWS key, a scanner flags the diff, someone rotates it. Coding agents add new places for credentials to end up. Agents remember the commands you approved. They send file contents and command output to a model. And their sessions get stored as traces, sometimes by people you have never heard of.

Claude Code's saved approvals recently put database passwords on public GitHub, and Cursor's stored agent traces handed an attacker credentials. This post covers the three places coding agents leak secrets, what went wrong in each incident, and how to close each gap.

Leak 1: The approvals file

When Claude Code asks to run a command and you pick "don't ask again", it saves that approval as an allow rule in .claude/settings.local.json. The rule stores the command as you approved it. If the command had a password inline, the password is now in a JSON file in your repo:

{
  "permissions": {
    "allow": [
      "Bash(npm run test)",
      "Bash(PGPASSWORD=<the real password> psql -h db.internal -U admin -c \"select 1\")"
    ]
  }
}

The example is made up, but the pattern is common. Apiiro scanned public GitHub and found 104,185 copies of .claude/settings.local.json. 1,122 of them contained at least one secret, 1,379 distinct secrets in total. Counting shared settings.json files, git history and saved transcripts brought it to 2,539 secrets across 1,994 repositories, according to The Hacker News' summary of the research.

Among them:

  • 379 database passwords. More than a third of the secrets open a database directly.
  • 43 SSH logins, 42 GitHub, GitLab and npm tokens, 23 AWS keys.
  • 215 secrets that neither Gitleaks nor TruffleHog flagged (both run without their verification step). Most of them were passwords typed into commands after PGPASSWORD=, sshpass -p or mysql -p, a shape that standard rules don't look for.

The researchers didn't test whether the credentials still worked, so none of this is a confirmed breach. Every affected file was still on its repository's default branch, and half had been there for at least 217 days.

Why .gitignore didn't save them

Claude Code tries to keep this file out of git. According to its docs, the first time it writes settings.local.json in a repository that doesn't already ignore it, it adds **/.claude/settings.local.json to your global git excludes file.

That protects one machine. It doesn't travel with the repository, so a teammate's clone, a CI runner or a fresh laptop has no such rule. It does nothing for a file that was created by hand or committed before the exclude existed. The project's own .gitignore is never touched.

Closing leak 1

Add the file to the project's .gitignore, so the rule ships with the repo:

echo '.claude/settings.local.json' >> .gitignore

Then check whether it is already tracked, now or in history:

git ls-files | grep -E '(^|/)\.claude/settings(\.local)?\.json$'
git log --all --oneline -- '**/.claude/settings.local.json'

# Across your whole GitHub org
gh search code --owner your-org --filename settings.local.json

Look at what your approvals actually contain. This pulls every saved rule and flags the shapes the scanners missed:

jq -r '.permissions.allow[]?' .claude/settings*.json ~/.claude/settings.json 2>/dev/null \
  | grep -nE 'PGPASSWORD=|sshpass +-p|mysql .* -p[^ ]|Bearer [A-Za-z0-9._-]{20,}|://[^/ :]+:[^@ ]+@'

If anything turns up, rotate the credential. Deleting the line or rewriting history doesn't help once it has been pushed. As Fireworks put it in its own incident bulletin, "removing a stored secret alone does not invalidate the underlying credential."

Teach your pre-commit scanner the missing patterns. A Gitleaks rule that extends the defaults:

# .gitleaks.toml
[extend]
useDefault = true

[[rules]]
id = "inline-cli-password"
description = "Password passed inline to a CLI command"
regex = '''(?:PGPASSWORD=|sshpass\s+-p\s*|mysql\b[^"\n]*?\s-p)([^\s"']{6,})'''
secretGroup = 1

Also keep secrets out of commands. Use ~/.pgpass or PGPASSFILE for Postgres, SSH keys instead of sshpass, and environment variables that the command references by name. The saved approval then reads psql -h db.internal -U admin, with nothing in it worth stealing.

Leak 2: The context window

The approvals file is easy to search. Everything the agent reads is harder to keep track of.

Every file a coding agent opens and every command it runs becomes context for the next model call. Common examples:

  • cat .env while debugging a config issue
  • env or printenv to check why a variable isn't set
  • docker inspect, kubectl get secret -o yaml, cat ~/.aws/credentials
  • Stack traces and connection errors that print the full database URL

All of it travels to the model provider in the request body. It is then stored by whatever sits on that path: the provider (subject to its retention policy), your observability stack, and any vendor you have shared traces with.

Claude Code supports deny rules that keep its file tools away from sensitive paths:

{
  "permissions": {
    "deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)", "Read(~/.aws/**)"]
  }
}

These rules only cover the agent's file tool. A shell command that prints the same file goes around them, and there are many ways to print a file. Every path ends in the same outbound request to the model, so that request is where a secret can be caught reliably.

Leak 3: The traces

According to Cursor's incident update, Cursor shared data with Fireworks AI through a read-only storage bucket. It held "limited coding agent traces, mostly from 2025, from sessions not in Privacy Mode." Cursor says the key to that bucket was exposed by Fireworks, which disclosed unauthorized use of its internal credentials. Cursor also writes: "A small number of those traces contained credentials that had not been redacted."

Those credentials gave the attacker access to some of Cursor's SaaS tools. A stolen credential from the same data was then used to serve trojanized builds of the Claude Code extension (versions 2.1.312 and 2.1.313) from Cursor's marketplace cache for about eleven hours. Cursor puts the upper bound at 5,000 users who requested those cached versions. Microsoft's analysis shows the builds added an attacker SSH key named svc-telemetry, enabled SSH, opened a reverse tunnel and set up persistence. If you use Cursor, check authorized_keys for that name and follow Cursor's remediation steps. Cursor warns that uninstalling the extension may not be enough.

Cursor says fewer than 0.01% of customers had API credentials exposed. That small share of traces was still enough to compromise a widely used extension.

Whoever stores your agent traces stores your secrets, unless they were removed before the trace was written. That applies to your vendor's training and evaluation pipelines, your own observability platform, the eval datasets you build from production logs, and every subprocessor any of those share data with.

For every place your agent traffic ends up, ask:

  • Are secrets redacted before the trace is written, or only hidden in the UI?
  • Who else receives the traces, and under what access controls?
  • How long are they kept?
  • Can you turn off storing request and response bodies entirely?

One control per layer

The three leaks happen in different places, so each needs its own control:

LayerWhat leaksControl
RepositorySaved approvals, committed settings and transcriptsProject .gitignore, pre-commit scanning with inline-password rules, org-wide search
AgentFiles and command output read into contextdeny rules for sensitive paths, no secrets in commands, secrets in files the agent doesn't need
NetworkEvery request to the model providerScan and redact or block outbound requests at a gateway
StorageTraces held by you and your vendorsRedact before storage, minimize retention, opt out of sharing, disable body storage where you can

How Grepture helps

Grepture is an AI gateway, so it sits at the network layer. It sees every request described in leak 2, and a secret it removes there can't show up later in a provider's logs or a vendor's traces.

You route Claude Code or Cursor through Grepture by pointing the base URL at the proxy. Claude Code needs three environment variables, covered in the setup docs. From then on, every request the agent sends is scanned before it reaches the provider, including tool results from earlier turns, which is where .env contents and printenv output end up.

Secret detection ships as pattern packs: AI provider keys, cloud and infrastructure credentials (AWS, GitHub, GitLab, npm, PyPI, Vault and more), SaaS service keys (Stripe, Slack, Twilio and others), and private keys, JWTs and database connection strings. For each rule you choose what happens: replace the secret with a placeholder like [DATABASE_URL], block the request outright, or log it at critical severity. A credential in a prompt usually means something upstream is misconfigured, so our guide to preventing data leaks in LLM calls argues for blocking rather than masking. Custom regex rules (Pro plan) cover patterns like PGPASSWORD= that standard scanners miss.

For the storage layer, zero-data mode (Business plan) processes every request without persisting request or response bodies, keeping only operational metadata like model, tokens, cost and latency.

A gateway never sees a file you commit to git, so leak 1 has to be fixed in the repository with the .gitignore, scanning and rotation steps above. For the broader picture of agent data flows, see why AI agents leak data.

Redact PII before it reaches the model.

Grepture is an open-source, EU-hosted AI gateway. Names, emails and secrets are replaced on the way out and restored in the response. Free for 1,000 requests a month.

Start free