SV.LOG_FORGING
This error occurs when an unvalidated user enters information in the system log file.
As of release 2023.2, this checker supports Jakarta EE.
Vulnerability and risk
Logging is an important part of security measures taken by an organization. Log entries allow you to create automatic alert tools, gain statistics, or trace an attacker when there is a security breakdown. Log forging allows an attacker to manipulate log records by adding false entries. This may confuse automatic scanning utilities and allow attacks to happen unnoticed or allow attackers to misdirect the reviewer after an attack has happened.
Klocwork security vulnerability (SV) checkers identify calls that create potentially dangerous data; these calls are considered unsafe sources. An unsafe source can be any data provided by the user, since the user could be an attacker or has the potential for introducing human error.
Mitigation and prevention
Strings should be escaped for all characters that have special meaning for a particular log, for example CR for text log, or angle brackets for an XML log, and should be filtered for all non-text characters.
Example 1
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String amount = req.getParameter("amount");
try {
int iAmount = Integer.parseInt(amount);
processAmount(iAmount);
} catch (NumberFormatException e) {
req.getSession().getServletContext().log("Incorrect int value specified for the 'amount' " + amount);
}
}
SV.LOG.FORGING is reported for line 20: Unvalidated user input is stored in 'amount' variable on line 15, and on line 20 it is concatenated with a constant string and written to log. This sequence makes log forging possible.
External guidance
Security training
Application security training materials provided by Secure Code Warrior.
Extension
This checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information.