Security rules
NGB016: Sensitive data logging
Reports credentials (passwords, access/refresh/ID tokens, API keys, session IDs) and payment data (card number, CVV/CVC) passed to browser logging or telemetry APIs.
| Property | Value |
|---|---|
| Rule ID | NGB016 |
| Category | Sensitive data & payment security |
| Default severity | high |
| CWE | CWE-532 |
| Built-in presets | recommended: error, strict: error, payments: error |
Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.
What it checks
Reports credentials (passwords, access/refresh/ID tokens, API keys, session IDs) and payment data (card number, CVV/CVC) passed to browser logging or telemetry APIs. Evidence comes from the value's own name, the properties of its declared type, names along its traced data flow, or a Luhn-valid card number literal. Values passed through a recognizable redaction step are not reported.
Why it matters
Browser console output is visible to anyone with access to the device and is often captured by session-replay and error-tracking tools. Telemetry services store logged values on third-party infrastructure, outside your access controls and retention policies. Logged tokens can be replayed; logged card data puts the application in PCI DSS scope.
Detection behavior and supported patterns
console.log/info/warn/error/debug/trace/dir/table(…)(type-resolvedConsole)- Sentry
captureMessage/captureException/setUser/setContext/setExtra/addBreadcrumb(imports from@sentry/*) gtag(…),dataLayer.push(…),posthog.capture(…),datadogLogs.logger.*(…),datadogRum.addAction(…),appInsights.trackEvent/trackTrace(…)- Sensitivity by head noun:
accessToken,refresh_token,password,apiKey,sessionId,cvv,cardNumber,pan; metadata such astokenExpiry,passwordHint,maskedPan,last4is ignored - Redaction recognized: calls named
mask*,redact*,hash*,truncate*,.slice(-4),.replace(…, "*")
Example
this.auth.login(creds).subscribe(res => console.log('login ok', res.accessToken));Safer alternative
this.auth.login(creds).subscribe(res => console.log('login ok', { userId: res.userId }));Remediation
Do not log credentials or payment data. Log stable identifiers (user ID, request ID) or a masked form (****1234). Configure telemetry SDKs with beforeSend scrubbing as a second line of defence.
False-positive considerations
- Variables named like secrets that hold non-secret values (e.g. a boolean called
token). - Logging statements removed from production builds are still reported; consider removing them from source instead.
Known limitations
- Generic objects (
console.log(user)) are reported only when their declared type exposes a sensitive property; untyped objects are not inspected. - Custom logger services are not treated as sinks unless they delegate to a modeled API inside the scanned code.
- Telemetry objects are matched by their conventional global/import names; renamed instances are missed.
References
Run it
ngbastion explain NGB016