Merge pull request #6001 from atorralba/atorralba/promote-mvel-injection

Java: Promote MVEL injection query from experimental
This commit is contained in:
Anders Schack-Mulligen
2021-08-02 14:40:26 +02:00
committed by GitHub
17 changed files with 348 additions and 474 deletions

View File

@@ -0,0 +1,25 @@
public void evaluate(Socket socket) throws IOException {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(socket.getInputStream()))) {
String expression = reader.readLine();
// BAD: the user-provided expression is directly evaluated
MVEL.eval(expression);
}
}
public void safeEvaluate(Socket socket) throws IOException {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(socket.getInputStream()))) {
String expression = reader.readLine();
// GOOD: the user-provided expression is validated before evaluation
validateExpression(expression);
MVEL.eval(expression);
}
}
private void validateExpression(String expression) {
// Validate that the expression does not contain unexpected code.
// For instance, this can be done with allow-lists or deny-lists of code patterns.
}

View File

@@ -0,0 +1,40 @@
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
<qhelp>
<overview>
<p>
MVEL is an expression language based on Java-syntax,
which offers many features
including invocation of methods available in the JVM.
If a MVEL expression is built using attacker-controlled data,
and then evaluated, then it may allow attackers to run arbitrary code.
</p>
</overview>
<recommendation>
<p>
Including user input in a MVEL expression should be avoided.
</p>
</recommendation>
<example>
<p>
In the following sample, the first example uses untrusted data to build a MVEL expression
and then runs it in the default context. In the second example, the untrusted data is
validated with a custom method that checks that the expression does not contain unexpected code
before evaluating it.
</p>
<sample src="MvelExpressionEvaluation.java" />
</example>
<references>
<li>
MVEL Documentation:
<a href="http://mvel.documentnode.com/">Language Guide for 2.0</a>.
</li>
<li>
OWASP:
<a href="https://owasp.org/www-community/vulnerabilities/Expression_Language_Injection">Expression Language Injection</a>.
</li>
</references>
</qhelp>

View File

@@ -0,0 +1,19 @@
/**
* @name Expression language injection (MVEL)
* @description Evaluation of a user-controlled MVEL expression
* may lead to remote code execution.
* @kind path-problem
* @problem.severity error
* @precision high
* @id java/mvel-expression-injection
* @tags security
* external/cwe/cwe-094
*/
import java
import semmle.code.java.security.MvelInjectionQuery
import DataFlow::PathGraph
from DataFlow::PathNode source, DataFlow::PathNode sink, MvelInjectionFlowConfig conf
where conf.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "MVEL injection from $@.", source.getNode(), "this user input"