Skip to content

Commit 474bf57

Browse files
committed
Minor corrections in QLDoc, qhelp and example code
1 parent f1df542 commit 474bf57

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

java/ql/lib/semmle/code/java/security/LogInjectionQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import semmle.code.java.security.LogInjection
88
* A taint-tracking configuration for tracking untrusted user input used in log entries.
99
*/
1010
class LogInjectionConfiguration extends TaintTracking::Configuration {
11-
LogInjectionConfiguration() { this = "Log Injection" }
11+
LogInjectionConfiguration() { this = "LogInjectionConfiguration" }
1212

1313
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
1414

java/ql/src/Security/CWE/CWE-117/LogInjection.qhelp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ other forms of HTML injection.
2929
</recommendation>
3030

3131
<example>
32-
<p>In the example, a username, provided by the user, is logged using <code>logger.warn</code> (from <code>org.slf4j.Logger</code>).
32+
<p>In the first example, a username, provided by the user, is logged using <code>logger.warn</code> (from <code>org.slf4j.Logger</code>).
3333
In the first case (<code>/bad</code> endpoint), the username is logged without any sanitization.
3434
If a malicious user provides <code>Guest'%0AUser:'Admin</code> as a username parameter,
3535
the log entry will be split into two separate lines, where the first line will be <code>User:'Guest'</code> and the second one will be <code>User:'Admin'</code>.
3636
</p>
3737
<sample src="LogInjectionBad.java" />
3838

39-
<p> In the second case (<code>/good</code> endpoint), <code>matches()</code> is used to ensure the user input only has alphanumeric characters.
40-
If a malicious user provides `Guest'%0AUser:'Admin` as a username parameter,
41-
the log entry will not be split into two separate lines, resulting in a single line <code>User:'Guest'User:'Admin'</code>.</p>
39+
<p> In the second example (<code>/good</code> endpoint), <code>matches()</code> is used to ensure the user input only has alphanumeric characters.
40+
If a malicious user provides `Guest'%0AUser:'Admin` as a username parameter, the log entry will not be logged at all, preventing the injection.</p>
4241

4342
<sample src="LogInjectionGood.java" />
4443
</example>

java/ql/src/Security/CWE/CWE-117/LogInjection.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
* @name Log Injection
3-
* @description Building log entries from user-controlled data is vulnerable to
4-
* insertion of forged log entries by a malicious user.
3+
* @description Building log entries from user-controlled data may allow
4+
* insertion of forged log entries by malicious users.
55
* @kind path-problem
66
* @problem.severity error
7+
* @security-severity 7.8
78
* @precision high
89
* @id java/log-injection
910
* @tags security

java/ql/src/Security/CWE/CWE-117/LogInjectionGood.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public class LogInjection {
1616
public String good(@RequestParam(value = "username", defaultValue = "name") String username) {
1717
// The regex check here, allows only alphanumeric characters to pass.
1818
// Hence, does not result in log injection
19-
if (username.matches("\w*")) {
19+
if (username.matches("\\w*")) {
2020
log.warn("User:'{}'", username);
21-
21+
2222
return username;
2323
}
2424
}

0 commit comments

Comments
 (0)