If unsanitized user input is written to a log entry, a malicious user may be able to forge new log entries.
+ +Forgery can occur if a user provides some input with characters that are interpreted +when the log output is displayed. If the log is displayed as a plain text file, then new +line characters can be used by a malicious user. If the log is displayed as HTML, then +arbitrary HTML may be included to spoof log entries.
++User input should be suitably sanitized before it is logged. +
+
+If the log entries are plain text then line breaks should be removed from user input, using for example
+String replace(char oldChar, char newChar)
or similar. Care should also be taken that user input is clearly marked
+in log entries, and that a malicious user cannot cause confusion in other ways.
+
+For log entries that will be displayed in HTML, user input should be HTML encoded before being logged, to prevent forgery and +other forms of HTML injection. +
+ +In the example, a username, provided by the user, is logged using `logger.warn` (from `org.slf4j.Logger`). +In the first case (`\bad` endpoint), the username is logged without any sanitization. +If a malicious user provides `Guest'%0AUser:'Admin` as a username parameter, +the log entry will be splitted in two different lines, where the first line will be `User:'Guest', while the second one will be `User:'Admin'`. +
+ In the second case (`\good` endpoint), replace
is used to ensure no line endings are present in the user input.
+If a malicious user provides `Guest'%0AUser:'Admin` as a username parameter,
+the log entry will not be splitted in two different lines, resulting in a single line `User:'Guest'User:'Admin'`.
+
In the example, a username, provided by the user, is logged using `logger.warn` (from `org.slf4j.Logger`). -In the first case (`\bad` endpoint), the username is logged without any sanitization. +In the first case (`/bad` endpoint), the username is logged without any sanitization. If a malicious user provides `Guest'%0AUser:'Admin` as a username parameter, the log entry will be splitted in two different lines, where the first line will be `User:'Guest', while the second one will be `User:'Admin'`.
- In the second case (`\good` endpoint), replace
is used to ensure no line endings are present in the user input.
+
In the second case (`/good` endpoint), replace
is used to ensure no line endings are present in the user input.
If a malicious user provides `Guest'%0AUser:'Admin` as a username parameter,
the log entry will not be splitted in two different lines, resulting in a single line `User:'Guest'User:'Admin'`.
In the example, a username, provided by the user, is logged using `logger.warn` (from `org.slf4j.Logger`). In the first case (`/bad` endpoint), the username is logged without any sanitization. If a malicious user provides `Guest'%0AUser:'Admin` as a username parameter, -the log entry will be splitted in two different lines, where the first line will be `User:'Guest', while the second one will be `User:'Admin'`. +the log entry will be splitted in two different lines, where the first line will be `User:'Guest'`, while the second one will be `User:'Admin'`.
In the second case (`/good` endpoint), replace
is used to ensure no line endings are present in the user input.
If a malicious user provides `Guest'%0AUser:'Admin` as a username parameter,
From 5ddb15fdd1e9debf1c24efa7a71c4cefbab2c65d Mon Sep 17 00:00:00 2001
From: ubuntu <43420907+dellalibera@users.noreply.github.com>
Date: Fri, 3 Jul 2020 19:53:43 +0200
Subject: [PATCH 5/6] Update .qhelp
---
.../src/experimental/Security/CWE/CWE-117/LogInjection.help | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/java/ql/src/experimental/Security/CWE/CWE-117/LogInjection.help b/java/ql/src/experimental/Security/CWE/CWE-117/LogInjection.help
index f43be0d05d58..7c6f1fd4dc06 100644
--- a/java/ql/src/experimental/Security/CWE/CWE-117/LogInjection.help
+++ b/java/ql/src/experimental/Security/CWE/CWE-117/LogInjection.help
@@ -33,11 +33,11 @@ other forms of HTML injection.
In the example, a username, provided by the user, is logged using `logger.warn` (from `org.slf4j.Logger`). In the first case (`/bad` endpoint), the username is logged without any sanitization. If a malicious user provides `Guest'%0AUser:'Admin` as a username parameter, -the log entry will be splitted in two different lines, where the first line will be `User:'Guest'`, while the second one will be `User:'Admin'`. +the log entry will be splitted in two separate lines, where the first line will be `User:'Guest'`, while the second one will be `User:'Admin'`.
In the second case (`/good` endpoint), replace
is used to ensure no line endings are present in the user input.
If a malicious user provides `Guest'%0AUser:'Admin` as a username parameter,
-the log entry will not be splitted in two different lines, resulting in a single line `User:'Guest'User:'Admin'`.
+the log entry will not be splitted in two separate lines, resulting in a single line `User:'Guest'User:'Admin'`.