API Key Exposure (API Key Exposure)
Why API Key Exposure Matters
API keys in JavaScript source code are visible to anyone who views the page source or inspects network requests. Attackers actively scan websites, GitHub repositories, and npm packages for exposed credentials. Automated tools can find and exploit exposed keys within minutes of publication.
The damage from exposed API keys depends on the key's permissions. An exposed Stripe secret key could enable fraudulent charges. An exposed AWS key with admin permissions could compromise an entire cloud infrastructure. An exposed SendGrid key could be used to send spam from your domain, destroying your email reputation.
Prevention requires multiple layers: environment variables for secrets (never hardcoded), .gitignore for .env files, server-side proxying for API calls that require secrets, key rotation for any potentially exposed credentials, and least-privilege key permissions so that even an exposed key has limited capabilities.
Real-World Example
In 2022, researchers found over 4,000 Android apps leaking AWS credentials hardcoded in their source code. These keys had permissions ranging from S3 bucket access to full account administration. Attackers regularly scan public GitHub repositories using automated tools, and exposed keys are typically exploited within minutes of being pushed.
How to Test for API Key Exposure
A security audit scans your website's JavaScript for patterns that match common API key formats - AWS keys, Stripe keys, SendGrid keys, and other service credentials. If exposed keys are found, rotate them immediately and move the API calls to a server-side proxy.