Skip to content

Commit 90b5e02

Browse files
committed
Improve qhelp
1 parent 8f1fc9e commit 90b5e02

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public void evaluate(Socket socket) throws IOException {
2+
try (BufferedReader reader = new BufferedReader(
3+
new InputStreamReader(socket.getInputStream()))) {
4+
5+
String expression = reader.readLine();
6+
// BAD: the user-provided expression is directly evaluated
7+
MVEL.eval(expression);
8+
}
9+
}
10+
11+
public void safeEvaluate(Socket socket) throws IOException {
12+
try (BufferedReader reader = new BufferedReader(
13+
new InputStreamReader(socket.getInputStream()))) {
14+
15+
String expression = reader.readLine();
16+
// GOOD: the user-provided expression is validated before evaluation
17+
validateExpression(expression);
18+
MVEL.eval(expression);
19+
}
20+
}
21+
22+
private void validateExpression(String expression) {
23+
// Validate that the expression does not contain unexpected code.
24+
// For instance, this can be done with allow-lists or deny-lists of code patterns.
25+
}

java/ql/src/Security/CWE/CWE-094/MvelInjection.qhelp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ Including user input in a MVEL expression should be avoided.
1919

2020
<example>
2121
<p>
22-
The following example uses untrusted data to build a MVEL expression
23-
and then runs it in the default powerfull context.
22+
In the following sample, the first example uses untrusted data to build a MVEL expression
23+
and then runs it in the default context. In the second example, the untrusted data is
24+
validated with a custom method that checks that the expression does not contain unexpected code
25+
before evaluating it.
2426
</p>
2527
<sample src="UnsafeMvelExpressionEvaluation.java" />
2628
</example>

java/ql/src/Security/CWE/CWE-094/UnsafeMvelExpressionEvaluation.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)