How to fix: Clipboard writeText() Contains a Hardcoded Credential
A navigator.clipboard.writeText() call contains a literal, credential-shaped string (an OpenAI/Google/GitHub/Slack token pattern) rather than a variable.
Why it matters
The exact secret value is shipped in the client bundle and readable by anyone who views the page source, not merely referenced or proxied.
This pattern typically comes from a debug 'copy my API key to clipboard' convenience button that was wired up against a real key during development and never parameterized before shipping, a classic AI-assisted prototyping leftover.
How to fix it
- 1Treat the exposed credential as compromised: revoke and reissue it immediately.
- 2Remove the hardcoded value and source it from a runtime-fetched, per-user value if the copy-to-clipboard feature is still needed.
- 3Add a pre-commit/CI secret scanner so credential-shaped literals never reach a client bundle.
Code examples
Fetch the value at runtime instead of hardcoding it
button.addEventListener('click', async () => {
const { apiKey } = await fetch('/api/me/key').then(r => r.json());
navigator.clipboard.writeText(apiKey);
});References
Detected automatically by VulnRadar. The check id is cs-clipboard-writetext-hardcoded-secret, stable across every scan so you can filter or diff on it.
More client-side checks
- HighCSP Allows 'unsafe-inline' Scripts
- MediumCSP Allows 'unsafe-eval'
- HighpostMessage Without Origin Validation
- HighSensitive Data Stored in localStorage
- HighDOM XSS via location.hash Assignment
- Highdocument.write() in Page Scripts
- Higheval() in Client-Side JavaScript
- MediumExternal Script Without Subresource Integrity
Questions
- How severe is Clipboard writeText() Contains a Hardcoded Credential?
- VulnRadar rates this high severity in the client-side category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id cs-clipboard-writetext-hardcoded-secret, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Clipboard writeText() Contains a Hardcoded Credential map to?
- It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.