Credentials or API Keys in Client-Side Code
Secret credentials, such as private API keys, cloud access keys or service passwords, are embedded in JavaScript or other files sent to the browser, where anyone can read them.
| Severity | High |
| CVSS 3.1 | 8.2 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N Open in the calculator |
| CVSS 4.0 | 8.8 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:L/VA:N/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-798: Use of Hard-coded Credentials |
| OWASP Top 10 | A07:2025 Authentication Failures |
| MITRE ATT&CK | T1552.001 Credentials In Files |
| Category | Information Disclosure |
Description
The application includes secret credentials in code delivered to the browser, such as JavaScript bundles, inline scripts, source maps, configuration files fetched by the front end, or HTML. Anything sent to the browser can be read by any user, and by anyone at all where the files are public, so a secret placed there is disclosed whatever is done to hide it, including minification and obfuscation.
Typical findings include private API keys for payment, email, messaging or other third-party services, cloud storage or access keys, credentials for internal APIs or databases, and tokens for source control or build services. An attacker who extracts one can use it directly against the service it belongs to, with whatever rights it grants and usually without any further control: depending on the key, reading or changing data held in the organisation's account with a provider, sending email or messages in the organisation's name, reaching cloud storage or internal APIs, or running up charges. Because the code is public, the secret should be assumed to have been collected already, and its misuse is often hard to distinguish from the application's own use in the provider's logs.
Secrets are found by searching the delivered files, including source maps and older bundles still on the server, for known key formats and words such as secret, token and password, using browser developer tools or secret scanning tools. Not every key in client-side code is a finding: some are designed to be public and are restricted by other means, such as publishable payment keys, Firebase web configuration and browser keys for mapping services restricted to the site's own pages. Each key found should be identified and, where safe and within the agreed scope, tested to establish what it grants.
Remediation
Remove secrets from client-side code and treat every exposed one as compromised:
- Revoke or rotate each exposed credential at once, and review the provider's logs for misuse since it was first exposed.
- Move calls that need a secret to the server: the browser calls the application's own back end, which authenticates the user, applies authorisation and rate limits, and then calls the third-party service with a secret held only on the server, ideally in a secrets manager.
- Where the browser must call a service directly, use credentials designed for that purpose: publishable or browser keys restricted to the site and to the minimum scope, or short-lived, narrowly scoped tokens issued by the back end for each user.
- Remove secrets from source maps, configuration files and old bundles, stop publishing source maps to production unless they are needed, and add secret scanning to the build pipeline and source repository so that new secrets are caught before release.
- Remove exposed secrets from source control history too, in case the repository is ever exposed.
Confirm the fix by searching the delivered files again and checking that the old credentials no longer work.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.