Description
Passwords, tokens, session IDs, API keys and personal data can spread from logs or standard output to consoles, collectors and backups.
Potential impact
People with access to diagnostic tools or retained logs may see personal data or reuse valid credentials even without database access.
Remediation
Omit secrets, including Authorization values. Use a fixed marker to show that a value was present or a separate ID to correlate events. Hashing a secret alone is insufficient. Limit log access and retention, and encrypt logs in transit.
Examples
The excerpts omit logger and variable declarations.
Before
java
logger.info("password={}", password);
logger.debug("token={}", accessToken);
After
java
logger.info("login attempt for userId={}", userId);
logger.debug("token present={}", accessToken != null);
The revised example logs whether a token is present. Keep userId only if diagnostics require it, since it can identify a person.