...
| Code Block | ||
|---|---|---|
| ||
public String sanitizeUser(String username) {
return Pattern.matches("[A-Za-z0-9_]+", username))
? username : "unauthorized user";
} |
...
This compliant solution uses a text logger that automatically sanitizes its input. A sanitized logger saves the developer from having to worry about unsanitized log messages.
| Code Block | ||
|---|---|---|
| ||
Logger sanLogger = new SanitizedTextLogger(logger);
if (loginSuccessful) {
sanLogger.severe("User login succeeded for: " + username);
} else {
sanLogger.severe("User login failed for: " + username);
} |
...
Allowing unvalidated user input to be logged can result in forging of log entries, leaking secure information, or storing sensitive data in a manner that violates a local law or regulation.
Rule | Severity | Likelihood |
|---|
Detectable | Repairable | Priority | Level |
|---|---|---|---|
IDS03-J | Medium | Probable |
No | No |
P4 |
L3 |
Automated Detection
| Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| The Checker Framework |
| Tainting Checker | Trust and security errors (see Chapter 8) | ||||||
| CodeSonar |
|
| JAVA.IO.TAINT.LOG | Tainted log | |||
| Fortify | Log_Forging | Implemented | |||
| Klocwork |
|
| SVLOG_FORGING | Implemented | |||
| Parasoft Jtest |
|
|
|
| CERT.IDS03.TDLOG |
| Protect against log forging |
Related Guidelines
Injection [RST] | |
CWE-144, Improper neutralization of line delimiters | |
| MITRE CAPEC | CAPEC-93, Log Injection-Tampering-Forging |
Bibliography
...