Skip to main content

Code reviews rule: Exposure of sensitive information in logs

Written by David Martin
Updated this week

Exposure of sensitive information in logs

Why is this an issue?

This rule identifies a Security vulnerability where sensitive information is written to debug logs. Salesforce debug logs can be accessed by administrators and may be retained for extended periods. Logging sensitive data such as passwords, API keys, credit card numbers, or personal information creates a risk of data exposure.

Examples

Example of incorrect code:

public void processPayment(String creditCardNumber, String cvv) {
System.debug('Processing payment for card: ' + creditCardNumber);
System.debug('CVV: ' + cvv);
// Process payment...
}

Example of correct code:

public void processPayment(String creditCardNumber, String cvv) {
System.debug('Processing payment for card ending in: ' + creditCardNumber.right(4));
// Never log CVV
// Process payment...
}

How can I fix violations?

This rule supports autofix.

To manually fix violations:

  1. Remove sensitive data from logs: Never log passwords, tokens, credit card numbers, CVVs, or other sensitive information.

  2. Mask sensitive data: If you must log references to sensitive data, mask or truncate it (e.g., show only the last 4 digits).

  3. Use appropriate log levels: Use LoggingLevel.ERROR or LoggingLevel.WARN for production-relevant logs, avoiding verbose debugging in production code.

  4. Review before deployment: Audit all System.debug() statements before deploying to production.

When should I disable this rule?

You should rarely disable this rule. However, you may dismiss specific violations if the data being logged is confirmed to be non-sensitive and the log statement is necessary for debugging.

Resources

Did this answer your question?