This vulnerability occurs when an application creates log entries using unvalidated external data, allowing attackers to inject malicious characters or commands that can corrupt log files, trigger parsing errors, or enable log injection attacks.

Log injection happens when user-supplied data containing special characters like newlines (\n), carriage returns (\r), or log-specific control sequences is written directly into log files without proper sanitization. Attackers can exploit this to forge fake log entries, break log file formatting, or obfuscate their malicious activities by injecting deceptive lines that mislead forensic analysis. To prevent this, developers should treat log entries as structured data rather than free-form text. Always sanitize or encode external inputs before writing them to logs, using appropriate logging frameworks that automatically handle escaping. Consider using parameterized logging functions that separate data from the log message template, which neutralizes dangerous characters while maintaining log integrity and readability.
Impact: Modify Application DataHide ActivitiesExecute Unauthorized Code or Commands
Interpretation of the log files may be hindered or misdirected if an attacker can supply data to the application that is subsequently logged verbatim. In the most benign case, an attacker may be able to insert false entries into the log file by providing the application with input that includes appropriate characters. Forged or otherwise corrupted log files can be used to cover an attacker's tracks, possibly by skewing statistics, or even to implicate another party in the commission of a malicious act. If the log file is processed automatically, the attacker can render the file unusable by corrupting the format of the file or injecting unexpected characters. An attacker may inject code or other commands into the log file and take advantage of a vulnerability in the log processing utility.
Strategy: Input Validation
Strategy: Output Encoding
Strategy: Input Validation
javaMedium