Security rules
NGB066: Sensitive data copied to the clipboard
Reports credentials and payment data (passwords, access / refresh tokens, API keys, card numbers, CVV) written to the system clipboard with navigator.clipboard.writeText() / write(), the Angular CDK Clipboard.copy() / beginCopy() service, or the [cdkCopyToClipboard] template directive.
| Property | Value |
|---|---|
| Rule ID | NGB066 |
| Category | Sensitive data & payment security |
| Default severity | low |
| CWE | CWE-200, CWE-359 |
| Built-in presets | recommended: warn, strict: error |
Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.
What it checks
Reports credentials and payment data (passwords, access / refresh tokens, API keys, card numbers, CVV) written to the system clipboard with navigator.clipboard.writeText() / write(), the Angular CDK Clipboard.copy() / beginCopy() service, or the [cdkCopyToClipboard] template directive. Sensitivity comes from the value's name, its type, names along its data flow or a card-number literal; masked or hashed values are ignored.
Why it matters
The clipboard is shared with every application on the device and often synced: clipboard managers keep a history, remote-desktop and cloud-clipboard features copy it to other machines, mobile keyboards read it, and any later paste lands the secret in chats or tickets. Copying a bearer token or card number turns a protected value into one with no access control or expiry.
Detection behavior and supported patterns
navigator.clipboard.writeText(v)/navigator.clipboard.write(items)on the DOMClipboardclipboard.copy(v)/clipboard.beginCopy(v)onClipboardfrom@angular/cdk/clipboard<button [cdkCopyToClipboard]="accessToken">in templates (bound expression named like a credential or payment value)
Example
copyToken() { navigator.clipboard.writeText(this.auth.accessToken); }Safer alternative
copyReference() { navigator.clipboard.writeText(this.order.reference); }Remediation
Avoid copying secrets. When copying is a product requirement (password managers, one-time API key display), copy only on an explicit user action, clear the clipboard after a short timeout, and never copy long-lived tokens or full card data.
False-positive considerations
- Password managers and API-key settings pages copy secrets on purpose when the user clicks "copy"; keep the finding as a reminder to clear the clipboard after a timeout or document an exception.
Known limitations
- Values copied with
document.execCommand("copy")from a selected element are not traced. - Sensitivity is name- and type-based; secrets with neutral names are not recognized.
References
Run it
ngbastion explain NGB066