Skip to content

Commit 53e6ddf

Browse files
authored
Merge pull request github#6001 from atorralba/atorralba/promote-mvel-injection
Java: Promote MVEL injection query from experimental
2 parents 3b676d4 + 9fadb26 commit 53e6ddf

File tree

17 files changed

+348
-474
lines changed

17 files changed

+348
-474
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* The query "Expression language injection (MVEL) (`java/mvel-expression-injection`) has been promoted from experimental to the main query pack. Its results will now appear by default. This query was originally [submitted as an experimental query by @artem-smotrakov](https://github.com/github/codeql/pull/3329)
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/experimental/Security/CWE/CWE-094/MvelInjection.qhelp renamed to java/ql/src/Security/CWE/CWE-094/MvelInjection.qhelp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
<overview>
55
<p>
6-
MVEL is an expression language based on Java-syntax.
7-
The language offers many features
6+
MVEL is an expression language based on Java-syntax,
7+
which offers many features
88
including invocation of methods available in the JVM.
99
If a MVEL expression is built using attacker-controlled data,
10-
and then evaluated, then it may allow the attacker to run arbitrary code.
10+
and then evaluated, then it may allow attackers to run arbitrary code.
1111
</p>
1212
</overview>
1313

@@ -19,10 +19,12 @@ 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>
25-
<sample src="UnsafeMvelExpressionEvaluation.java" />
27+
<sample src="MvelExpressionEvaluation.java" />
2628
</example>
2729

2830
<references>
@@ -35,4 +37,4 @@ and then runs it in the default powerfull context.
3537
<a href="https://owasp.org/www-community/vulnerabilities/Expression_Language_Injection">Expression Language Injection</a>.
3638
</li>
3739
</references>
38-
</qhelp>
40+
</qhelp>

java/ql/src/experimental/Security/CWE/CWE-094/MvelInjection.ql renamed to java/ql/src/Security/CWE/CWE-094/MvelInjection.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
*/
1212

1313
import java
14-
import MvelInjectionLib
14+
import semmle.code.java.security.MvelInjectionQuery
1515
import DataFlow::PathGraph
1616

17-
from DataFlow::PathNode source, DataFlow::PathNode sink, MvelInjectionConfig conf
17+
from DataFlow::PathNode source, DataFlow::PathNode sink, MvelInjectionFlowConfig conf
1818
where conf.hasFlowPath(source, sink)
1919
select sink.getNode(), source, sink, "MVEL injection from $@.", source.getNode(), "this user input"

0 commit comments

Comments
 (0)