Nexus Void AI Research

api key leak, secret manager, google cloud, secrets management, llmjacking, anthropic, gemini, incident response

API Key Leaked From Secret Manager? 9 Escape Paths (2026)

API key leaked from a secret manager? The vault guards it at rest; it escapes once your app reads it. 9 leak paths, how to check each, and what to do next.

If your API key leaked even though it was in a secret manager, the vault was probably not the weak point. Google Secret Manager protects the key at rest. Once your app reads it, copies live in memory, env vars, logs, builds and tools. Attackers take one of those copies, or use an identity that can read the secret.

Last updated 1 December 2026.

A founder told us this week that about $700 of Anthropic and Gemini credits were burned while both keys sat in Google Secret Manager. They asked what to do besides making new keys. For the generic runbook, see what to do when an API key leaks. This post covers how keys escape a vault and how to prove which path it was.

Why did my API key leak if it was stored in Secret Manager?

Because a secret manager controls one copy of the key, and your app makes more. Secret Manager encrypts the stored value and gates who can call AccessSecretVersion. After that, the plaintext key can land in a bundle, a log, an image layer, a CI variable or a laptop, and none of those copies are in the vault.

The OWASP Secrets Management Cheat Sheet says it plainly: environment variables "are generally accessible to all processes and may be included in logs or system dumps." The second route skips copies: anyone holding an identity allowed to read the secret can fetch it directly. Google's threat intelligence team saw one 2026 actor exfiltrate "third-party API keys" from cloud secret managers (GTIG, 3 November 2026).

In the same report, Mandiant saw fraudulent charges above $100,000 in a single day and one actor making more than 500,000 LLM API calls in under eight hours. Researchers at Sysdig named this LLMjacking in May 2024 (The Hacker News); see our LLMjacking explainer.

What are the 9 ways an API key escapes a secret manager?

In our analysis, nine paths cover how a stored key gets out: git copies, frontend env vars, logs, Docker layers, CI, over-broad IAM, stolen credentials or laptops, key reuse, and tools or AI agents that read .env. Each has a quick check you can run today.

1. A copy still lives in git history or a committed .env file

Keys often reach Secret Manager after being committed, and deleting the file leaves them in history. Check with git log -p -S 'sk-ant-' --all (or AIza for Google keys), or run gitleaks across the full history. Rotate, then rewrite history; see how to remove secrets from git history. Anthropic says GitHub reports Claude keys found in public repos and Anthropic deactivates them automatically (Anthropic support). That program covers public repositories.

2. A frontend env var bundled the key into JavaScript

Next.js inlines any NEXT_PUBLIC_ variable "into any JavaScript sent to the browser" at build time (Next.js docs). Vite says VITE_ variables "should not contain sensitive information such as API keys" (Vite docs). If CI pulled the key into one of those names, every visitor has it. Check with grep -r 'AIza' .next/static dist/. Call the LLM from a server route only; our Next.js security guide shows how.

3. Logs, error trackers and request dumps captured it

Logging process.env, error trackers that record request headers, and HTTP clients that dump failed requests all write the key in plaintext. Search logs and error trackers for the key prefix and x-api-key or x-goog-api-key headers. OWASP says plaintext secrets must never be logged. Redact at the logger.

4. Docker image layers and build args kept a copy

Docker's docs say build arguments and environment variables are "inappropriate for passing secrets to your build" because "they persist in the final image" (Docker docs). Check with docker history --no-trunc <image> and docker inspect. Use build secret mounts and fetch keys at runtime.

5. CI/CD logs or over-broad CI secrets exposed it

GitHub says log redaction "is not guaranteed" and can miss JSON-wrapped or Base64-encoded secrets (GitHub Actions hardening guide). Scope matters too: a long-lived CI credential that can read every secret is a skeleton key. OWASP recommends short-lived OIDC federation. Search old workflow logs for the key prefix, and see how to secure a GitHub Actions pipeline.

6. Over-broad IAM on the secret

The role that reads secret payloads is Secret Manager Secret Accessor (roles/secretmanager.secretAccessor). Granted at project level, it reads every secret in the project (Google Cloud docs). Google's advice is to "always apply permissions at the lowest level in the resource hierarchy." Check with gcloud projects get-iam-policy and gcloud secrets get-iam-policy, and look for Owner and Editor grants too. Move access to the individual secret, one service account per workload.

7. A service account key, developer machine or developer token was stolen

For someone holding a credential that can read the secret, the vault works as designed. Google says "anyone who possesses a service account key can use it" and recommends avoiding keys "whenever possible" (Google Cloud IAM best practices). GTIG calls stolen cloud identity tokens the dominant way in. Check for downloaded service account keys, old gcloud sessions and broad GitHub PATs.

8. The same key is reused across services and environments

One key shared by production, staging and three developers means any leak spends production money, and you cannot tell which copy leaked. Anthropic recommends separate keys for development, testing and production, and one key per person (Anthropic support). Compare usage per key in the provider console.

9. Third-party tools and AI coding agents read .env

Editor extensions, MCP servers and AI coding agents can read local .env files and send them on. Claude Code, for example, documents deny rules such as Read(./.env) to stop it reading env files (Claude Code settings). Audit which agents and MCP servers run on developer machines; our MCP security guide explains what they can reach.

How do I check which leak path it was?

Start from evidence: the provider's usage per key and the first anomalous timestamp, compared with deploys and Secret Manager access logs. The table maps each path to a check and a fix; the first four are the cheapest to rule out.

Leak path

How to check

Fix

Git history / committed .env

git log -p -S on the key prefix, or gitleaks on full history

Rotate, rewrite history, add a pre-commit scan

Frontend env var

grep built JS (.next/static, dist) for the key prefix

Server-side calls only; no NEXT_PUBLIC_/VITE_ secrets

Logs and error trackers

Search logs for the prefix and auth headers

Redact at the logger; purge old entries

Docker layers / build args

docker history --no-trunc, docker inspect

Build secret mounts; fetch at runtime

CI/CD logs and secrets

Search old run logs; list which jobs can read the secret

OIDC, scoped secrets, delete leaked logs

Over-broad IAM

get-iam-policy for Secret Accessor, Owner, Editor

Grant per secret, per service account

Stolen SA key or dev token

List service account keys and old sessions; check audit logs

Delete SA keys; use Workload Identity Federation

Key reused everywhere

Compare usage per key across services

One key per service and environment

Tools and AI agents

List extensions, MCP servers and agents with file access

Deny .env reads; keep prod keys off laptops

Most of the first five paths are visible in code. ARGUS scans every repo for secrets (built on gitleaks) and marks each one live, rotated or test, and its third-party discovery flags every place your code calls OpenAI, Anthropic or another LLM provider. Our guide to finding hardcoded secrets covers the manual way.

What should I do beyond rotating the key?

Rotation stops the bleeding, but a fresh key stored the same way leaks the same way. Beyond rotating: widen the rotation, read the access logs, date the leak, ask for a credit, and add limits so the next leak costs less. Our read on the order:

  1. Rotate everything stored alongside it. If an identity was stolen, every secret it could read is exposed.

  2. Audit Secret Manager access. AccessSecretVersion is recorded as a Data Access audit log (Google Cloud docs), but Data Access logs "are disabled by default" for most services (Cloud Logging docs). If they were off, there is no record of past reads. Turn them on now.

  3. Date the leak from provider usage. Anthropic points to its Usage and Logs pages (Anthropic support); Google Cloud billing reports show Gemini spend per project. The first spike narrows the search.

  4. Request a billing credit. Google says compromise cases are reviewed "on an individual basis" through Cloud Customer Care (Cloud Billing docs). Anthropic's compromised-key article says to contact support if suspicious activity continues (Anthropic support). Neither promises a refund; send timestamps, fixes and usage evidence up front.

  5. Split keys per service. Revoke one without an outage, and see which copy leaked next time.

  6. Set spend limits. Anthropic's spend limits "act as a safeguard against unexpected usage due to leaked keys." On Google Cloud, an alerts-only budget "doesn't automatically cap" spending (Cloud Billing docs); use spend cap budgets where supported.

  7. Restrict Google API keys. Google's docs say "Unrestricted API keys are insecure" (Google Cloud docs). Limit each key to the Gemini API and to your server's IPs.

In February 2026, researchers at Truffle Security found 2,863 live Google API keys in public web pages that could call Gemini once the Generative Language API was enabled, keys never meant for it (The Hacker News). Google's Gemini API key docs now say dormant unrestricted keys have been blocked since 7 May 2026 (Google AI Studio docs). Our Gemini API key security guide goes deeper.

How do I stop an API key leaking from a secret manager again?

Keep the key on the server, read it at runtime with a narrowly scoped identity, and never let it pass through a build, a log or a laptop. Then scan for the copies you miss. Five habits close most of the nine paths.

  • Grant Secret Accessor per secret to one service account per workload, never project-wide.

  • Fetch secrets at runtime; keep them out of NEXT_PUBLIC_, VITE_, Docker ARG/ENV and CI variables.

  • Replace service account keys with attached service accounts or Workload Identity Federation.

  • Route LLM calls through one AI gateway that holds the key and enforces quotas.

  • Scan every commit and pull request for secrets, and keep Data Access audit logs on for Secret Manager.

More in how to store API keys securely, third-party API integrations and Google's compromised credentials guide.

Find every place your keys can leak. ARGUS scans all your repos in one pass for secrets, code flaws, dependencies, IaC and container CVEs, and maps where your code talks to LLM providers. Its fix agent opens a verified pull request for a person to review and merge. It does not watch your provider bill, so keep the limits above. Start on the free plan at argus.nexusvoidhq.com/signup or read more about ARGUS.

Dealing with a stolen key right now? Work through our LLM API key compromised checklist step by step.

Frequently asked questions

Can Google Secret Manager itself be hacked to leak my API key?

It is rare for the vault itself to fail. Leaks usually come from copies your app makes after reading the key, or from an identity with Secret Accessor rights. Check IAM grants on the secret and Secret Manager Data Access audit logs before suspecting the service.

How do I see who accessed my secret in Secret Manager?

Reads are logged as AccessSecretVersion in Cloud Audit Logs, under Data Access logs. Those logs are disabled by default for most Google Cloud services, so if you never enabled them there is no history of past reads. Enable them now for future incidents.

Is rotating the API key enough after a leak?

No. Rotation stops the stolen key, but if the cause is still there the new key leaks the same way. Find the path first, rotate every secret the same identity could read, split keys per service, and set spend limits with the provider.

Can I get a refund for API credits used by someone who stole my key?

Sometimes. Google reviews compromise cases individually through Cloud Customer Care, and Anthropic asks you to contact support if suspicious activity continues. Neither promises a refund. Send timestamps, usage evidence and the steps you took to fix the leak.

Are NEXT_PUBLIC_ or VITE_ variables safe for API keys?

No. Next.js inlines NEXT_PUBLIC_ variables into JavaScript sent to the browser, and Vite says VITE_ variables should not hold API keys. Anyone can read them from your site. Call the LLM from a server route and keep the key there.

How do I stop AI coding agents from reading my .env file?

Use the agent's deny rules. Claude Code, for example, documents permission rules such as Read(./.env) to block reading env files. Better still, keep production keys off developer laptops entirely and give developers separate, low-limit keys.

DATA SOURCES

Google Threat Intelligence Group: LLMjacking (3 Nov 2026): https://cloud.google.com/blog/topics/threat-intelligence/llmjacking-monetizing-compromised-cloud-models; The Hacker News: LLMjacking scheme (10 May 2024): https://thehackernews.com/2024/05/researchers-uncover-llmjacking-scheme.html; The Hacker News: public Google Cloud API keys and Gemini (28 Feb 2026): https://thehackernews.com/2026/02/thousands-of-public-google-cloud-api.html; Google Cloud: Secret Manager access control: https://docs.cloud.google.com/secret-manager/docs/access-control; Google Cloud: Secret Manager audit logging: https://docs.cloud.google.com/secret-manager/docs/audit-logging; Google Cloud: Enable Data Access audit logs: https://docs.cloud.google.com/logging/docs/audit/configure-data-access; Google Cloud: Service account best practices: https://docs.cloud.google.com/iam/docs/best-practices-service-accounts; Google Cloud: Manage API keys: https://docs.cloud.google.com/docs/authentication/api-keys; Google Cloud: Resolve Cloud Billing issues: https://docs.cloud.google.com/billing/docs/how-to/resolve-issues; Google Cloud: Budgets: https://docs.cloud.google.com/billing/docs/how-to/budgets; Google Cloud: Handling compromised credentials: https://docs.cloud.google.com/docs/security/compromised-credentials; Google AI Studio: Gemini API keys: https://aistudio.google.com/docs/api-key; Next.js: Environment variables: https://nextjs.org/docs/app/guides/environment-variables; Vite: Env variables and modes: https://vite.dev/guide/env-and-mode; Docker: Build secrets: https://docs.docker.com/build/building/secrets/; GitHub: Security hardening for GitHub Actions: https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions; OWASP: Secrets Management Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html; Anthropic: API key best practices: https://support.claude.com/en/articles/9767949-api-key-best-practices-keeping-your-keys-safe-and-secure; Anthropic: Suspected compromised API key: https://support.claude.com/en/articles/8384961-what-should-i-do-if-i-suspect-my-api-key-has-been-compromised; Claude Code: Settings: https://code.claude.com/docs/en/settings

Liked this post? Share it:

Related posts