Exposed Secrets in JavaScript (Exposed Secrets)
Summary
- API keys, passwords, tokens, and certificates accidentally made public
- Common locations: source code, git history, error messages, client-side JavaScript
- Automated scanners detect exposed secrets within minutes on public repos
- Prevention: environment variables, secret managers, pre-commit hooks
- Remediation requires rotation, not just deletion from the repository
The Importance of Exposed Secrets
Modern JavaScript bundlers (webpack, Vite, etc.) can accidentally include server-side environment variables in client bundles if the build configuration does not properly separate public and private variables. A .env file with DATABASE_URL or STRIPE_SECRET_KEY that gets bundled into the frontend exposes those credentials to anyone who views the page source.
Source maps, while useful for debugging, can expose original source code including comments with credentials, development URLs, and internal logic. If source maps are deployed to production, they reveal implementation details that help attackers find vulnerabilities.
Automated secret scanning tools search JavaScript bundles for high-entropy strings, known API key patterns, and common credential formats. Running such scans as part of your deployment pipeline catches exposed secrets before they reach production.
How to Check
A security audit scans your site's JavaScript bundles for patterns matching common secrets (API keys, database URLs, private keys). It checks for exposed source maps and development configurations. Run this scan after every deployment to catch accidentally bundled credentials.