Overview
This rule detects instances where information derived from sensitive fields in the data model is exposed in logs, particularly via the System.debug method. Sensitive information should never be included in logs. While logging all information may be helpful during development and debugging, it's crucial to ensure that any sensitive user data and system information are not accidentally exposed in debug logs (e.g., usernames, passwords, contact information, PII, etc.).
Code Reviews classifies this as an Error because it represents a significant security vulnerability that can lead to unauthorized data disclosure and compliance violations, directly compromising data confidentiality.
β
Why This Matters
Exposing sensitive information in logs can lead to:
Unauthorized Data Disclosure: Log files are often accessible to developers, administrators, or potentially attackers. If sensitive data (like PII, financial details, or credentials) is logged, it creates an unauthorized access point.
Compliance Violations: Logging sensitive data without proper redaction violates various data protection regulations (e.g., GDPR, HIPAA, CCPA) and internal security policies.
Increased Attack Surface: Log files can become a target for attackers seeking to exfiltrate sensitive data or gain insights into system vulnerabilities.
Reputational Damage: A data breach involving sensitive information exposed in logs can severely harm an organization's reputation and lead to a loss of customer trust.
Debugging Misconceptions: While logging all information may be helpful during development, it's important to make sure that any sensitive user data and system information are not accidentally exposed. Debug logs should not contain any sensitive data such as usernames, passwords, contact information, PII, etc..
What Triggers This Rule
Code Reviews flags Apex code that uses System.debug() to output values directly from:
Sensitive fields in SObjects (e.g., fields marked as
IsEncryptedin Salesforce, or fields identified as PII/PHI in your organization's data dictionary).Variables holding sensitive information (e.g., API keys, tokens, unencrypted passwords).
Full SObject records or collections that might contain sensitive fields.
Recommended Safeguards
To prevent the exposure of sensitive information in logs:
Avoid Logging Sensitive Data: Never include sensitive user data or system information directly in
System.debug()statements.Redact or Mask Sensitive Information: If logging is necessary for debugging, implement logic to mask or redact sensitive data before it is written to the logs. For example, log only the last few characters of an ID or replace PII with placeholders.
Use Contextual Logging: Focus on logging contextual information that aids in debugging (e.g., flow of execution, method entry/exit, non-sensitive variable values) rather than raw data.
Implement Secure Logging Frameworks: For complex applications, consider using a custom Apex logging framework that automatically redacts or encrypts sensitive data before writing to logs, and manages log retention securely.
Automate Log Analysis: Regularly review debug logs using automated tools to detect and alert on any accidental exposure of sensitive information.
Developer Training: Educate your development team on secure logging practices and the importance of data privacy. Emphasize the risks associated with exposing sensitive information in logs and best practices for debugging without compromising security.
Cleanup Development Logs: Ensure that
System.debug()statements used for temporary debugging are removed or disabled before deploying code to production or higher environments.
Summary
Exposure of sensitive information in logs is an Error. Sensitive information should never be included in logs. While logging all information may be helpful during development, it's important to make sure that any sensitive user data and system information are not accidentally exposed. Debug logs should not contain any sensitive data such as usernames, passwords, contact information, PII, etc.. Code Reviews detects System.debug statements that expose sensitive data, guiding developers to implement secure logging practices to protect confidentiality and maintain compliance.
