CCyberwiki

Abuse of leaked API keys

Abuse of leaked API keys
ClassSecrets
Also known asAPI key abuse; LLMjacking (for hosted AI models)
CWECommonly follows CWE-798: Use of Hard-coded Credentials
OWASP Top 10A07:2025 Authentication Failures
Typical severityHigh
AffectsKeys for paid or data-bearing services: cloud accounts, AI model APIs, payment providers, maps and email services

Someone finds an API key or other service credential in a public repository, in a website's JavaScript or on a server they have broken into, and sends requests with it to the service that issued it. The service bills those requests to the key's owner and answers them with the owner's data. That is abuse of a leaked API key. How keys get out in the first place is the subject of Exposed credentials in source code repositories and Client-side code exposure.

Description

An API key works like a bearer pass. The provider checks that the string is valid and that the request falls within the key's permissions, and never asks who sent it. Google says of its own keys that a key "is not paired with your identity" and that anyone can use it.1 A request from an attacker's laptop looks the same as one from the owner's server unless the key is restricted to particular addresses, apps or services.

Most leaked keys were written into the code to begin with, a weakness the 2025 Top 10 files under Authentication Failures.2 Fraudsters scan public code for exposed keys around the clock.3 In one honeypot study, AWS keys committed to a new GitHub repository were found and used within five minutes, including keys left only in an earlier commit of the git history.4

Mechanism

In the campaigns Unit 42 and Sysdig documented, a scanner first collected candidate keys by cloning public repositories or reading files on a server already broken into. A checker then sent each key a cheap request to learn whether it was live, which services it reached and what quota it had. Keys that passed were put to use or sold.

In the 2024 case Sysdig analysed, the attackers' script tested stolen credentials against ten AI services, among them OpenAI, Anthropic, Mistral, AWS Bedrock, Azure and GCP Vertex AI, without running any real prompt.5 On AWS, they called the Bedrock model API with an invalid token limit:

aws bedrock-runtime invoke-model \
  --model-id anthropic.claude-v2 \
  --body '{"prompt": "Human: ...Assistant:", "max_tokens_to_sample": -1}' \
  --cli-binary-format raw-in-base64-out out.txt

A ValidationException error told them the key had access and the model was switched on; AccessDenied would have meant it did not. They also called GetModelInvocationLoggingConfiguration to see whether prompts were being logged, since CloudTrail records the call but not the prompt.5 Working keys were then served through an open-source LLM reverse proxy, which lets one operator hand out access to many stolen accounts without revealing the keys themselves.5

Impact

The direct cost is the provider's bill. Sysdig estimated the worst case for Claude 2 on Bedrock, at the initial quota of 500,000 tokens a minute in four regions, at $46,080 a day.5 Cloud keys with permission to start servers are used for Cryptojacking: the campaign Unit 42 tracked ran Monero miners on the victims' EC2 instances.4 Both are forms of Denial of wallet.

Running a key up to its quota also blocks the owner's own traffic, so the application stops working while the bill rises.56 Keys that read data expose it: a Stripe secret key can be used to make charges and read customer data.3

Notable incidents

EleKtra-Leak (2020 to 2023). Unit 42 at Palo Alto Networks published AWS keys in decoy GitHub repositories. GitHub's secret scanning reported them to AWS, which attached the AWSCompromisedKeyQuarantine policy within two minutes; the attackers began reconnaissance four minutes after that. With the quarantine removed, they started EC2 instances for mining. Between 30 August and 6 October 2023 the mining pool showed 474 distinct miners, which Unit 42 read as EC2 instances in victims' accounts, and the activity dated back to at least December 2020.4

LLMjacking (2024). Sysdig named the theft of hosted AI model access "LLMjacking". In the case it described, the credentials were taken from a server running a Laravel version with CVE-2021-3129, and the aim was to sell model access while the account owner paid.5

Detection

Abuse shows first in usage. Google exposes per-key request counts through the Cloud Monitoring metric serviceruntime.googleapis.com/api/request_count, filtered by the credential_id label, and notes that an abnormally high count usually means the key was taken.1 OpenAI shows usage on the Usage page,6 and a Stripe account's API request logs are the place to audit.3 On AWS, Sysdig's detection rule flags Bedrock InvokeModel calls that end in ValidationException, the signature of the probe above, and Bedrock's model invocation logging records the prompts that CloudTrail omits.5

Some providers detect exposure for the owner. GitHub sends keys found in public repositories and public npm packages to the issuing provider, which decides whether to revoke the key, issue a new one or contact the owner.7 Stripe may deactivate an exposed key itself but does not promise to find every one.3 Unit 42 found mining instances outside the quarantine, from keys leaked in ways the automatic check did not catch.4

Prevention

Secret keys stay out of anything a visitor downloads when browser and mobile code calls the owner's own server, which holds the key in an environment variable and calls the provider.6 The other controls limit what a key can do once it is out (Principle of least privilege):

Table 1. Controls that limit a leaked key, by provider
ProviderControl
GoogleAPI restrictions to the services the key needs (for an AI Studio key, only Gemini API); one application restriction type per key: websites, IP addresses, iOS bundle IDs or Android package and certificate. Send the key in the x-goog-api-key header, not in the URL.18
OpenAIMonthly spend limit with hard enforcement; IP allowlisting; project keys with an expiry date.6
StripeRestricted keys with only the permissions a component needs; requests limited to fixed IP addresses, or blocked by country or ASN.3
AWSLeast-permission IAM policies and service control policies.5

A spend alert reports the cost while the requests keep coming. On OpenAI only hard enforcement stops them, and spend can pass the limit slightly before it takes effect.6 Short-lived credentials narrow the window: OpenAI's workload identity federation trades an identity from a trusted provider for a short-lived token in place of a stored key.6 Unused Google keys can be deleted and the rest rotated on a schedule.8 The steps after a leak are in Responding to a leaked API key.

Prompt for a coding agent

List every API key, token and cloud credential this project uses, and where each one is read. Flag any that appear in source code, in files sent to the browser, or in variables with a public prefix such as NEXT_PUBLIC_ or VITE_. Move each secret key to a server-side environment variable and route browser calls through a server endpoint that holds the key. For each provider, list the dashboard settings that should be set: API and application restrictions for Google keys, spend limits with hard enforcement and IP allowlists for OpenAI, restricted keys for Stripe. Do not print any key values in your answer.

In SecFlash

SecFlash reports a key it finds in the repository or its history as SF-SEC-702 on the Security page, and a secret key in the live site's JavaScript or HTML as SF-EXP-301 and SF-EXP-304 on the Exposure page. Keys meant to be public, such as Google Maps or Firebase web keys, appear as SF-EXP-306, with the setting each one depends on.

See also

References

  1. a b c Yankulin, Leonid (22 May 2026). "Securing Your Gemini and Google API Keys". Google Cloud Blog. Google.
  2. back "A07:2025 Authentication Failures". OWASP Top 10:2025. OWASP Foundation.
  3. a b c d e "Best practices for managing secret API keys". Stripe Documentation. Stripe.
  4. a b c d Gamazo, William; Quist, Nathaniel (30 October 2023). "CloudKeys in the Air: Tracking Malicious Operations of Exposed IAM Keys". Unit 42. Palo Alto Networks.
  5. a b c d e f g h Brucato, Alessandro (6 May 2024). "LLMjacking: Stolen Cloud Credentials Used in New AI Attack". Sysdig Threat Research. Sysdig.
  6. a b c d e f "Best practices for API key safety". OpenAI Help Center. OpenAI.
  7. back "Secret scanning for partners". GitHub Docs. GitHub.
  8. a b "Best practices for managing API keys". Google Cloud Documentation. Google.