Skip to main content
HighClient-sideOWASP A07:2021CWE-798

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

  1. 1Treat the exposed credential as compromised: revoke and reissue it immediately.
  2. 2Remove the hardcoded value and source it from a runtime-fetched, per-user value if the copy-to-clipboard feature is still needed.
  3. 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

JavaScript
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.

See every client-side check

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.

Propose a checkHow a check is built

Scan your own site for clipboard writetext() contains a hardcoded credential

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Clipboard writeText() Contains a Hardcoded Credential | VulnRadar