Skip to content

Commit d476459

Browse files
committed
Use InlineExpectationsTest
1 parent b30c92e commit d476459

File tree

5 files changed

+52
-85
lines changed

5 files changed

+52
-85
lines changed

java/ql/test/query-tests/security/CWE-094/MvelInjection.expected

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

java/ql/test/query-tests/security/CWE-094/MvelInjection.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

java/ql/test/query-tests/security/CWE-094/MvelInjectionTest.expected

Whitespace-only changes.

java/ql/test/query-tests/security/CWE-094/MvelInjection.java renamed to java/ql/test/query-tests/security/CWE-094/MvelInjectionTest.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,73 +19,72 @@
1919
import org.mvel2.templates.TemplateCompiler;
2020
import org.mvel2.templates.TemplateRuntime;
2121

22-
public class MvelInjection {
22+
public class MvelInjectionTest {
2323

2424
public static void testWithMvelEval(Socket socket) throws IOException {
25-
MVEL.eval(read(socket));
25+
MVEL.eval(read(socket)); // $hasMvelInjection
2626
}
2727

2828
public static void testWithMvelCompileAndExecute(Socket socket) throws IOException {
2929
Serializable expression = MVEL.compileExpression(read(socket));
30-
MVEL.executeExpression(expression);
30+
MVEL.executeExpression(expression); // $hasMvelInjection
3131
}
3232

3333
public static void testWithExpressionCompiler(Socket socket) throws IOException {
3434
ExpressionCompiler compiler = new ExpressionCompiler(read(socket));
3535
ExecutableStatement statement = compiler.compile();
36-
statement.getValue(new Object(), new ImmutableDefaultFactory());
37-
statement.getValue(new Object(), new Object(), new ImmutableDefaultFactory());
36+
statement.getValue(new Object(), new ImmutableDefaultFactory()); // $hasMvelInjection
37+
statement.getValue(new Object(), new Object(), new ImmutableDefaultFactory()); // $hasMvelInjection
3838
}
3939

4040
public static void testWithCompiledExpressionGetDirectValue(Socket socket) throws IOException {
4141
ExpressionCompiler compiler = new ExpressionCompiler(read(socket));
4242
CompiledExpression expression = compiler.compile();
43-
expression.getDirectValue(new Object(), new ImmutableDefaultFactory());
43+
expression.getDirectValue(new Object(), new ImmutableDefaultFactory()); // $hasMvelInjection
4444
}
4545

4646
public static void testCompiledAccExpressionGetValue(Socket socket) throws IOException {
47-
CompiledAccExpression expression = new CompiledAccExpression(
48-
read(socket).toCharArray(), Object.class, new ParserContext());
49-
expression.getValue(new Object(), new ImmutableDefaultFactory());
47+
CompiledAccExpression expression =
48+
new CompiledAccExpression(read(socket).toCharArray(), Object.class, new ParserContext());
49+
expression.getValue(new Object(), new ImmutableDefaultFactory()); // $hasMvelInjection
5050
}
5151

5252
public static void testMvelScriptEngineCompileAndEvaluate(Socket socket) throws Exception {
5353
String input = read(socket);
5454

5555
MvelScriptEngine engine = new MvelScriptEngine();
5656
CompiledScript compiledScript = engine.compile(input);
57-
compiledScript.eval();
57+
compiledScript.eval(); // $hasMvelInjection
5858

5959
Serializable script = engine.compiledScript(input);
60-
engine.evaluate(script, new SimpleScriptContext());
60+
engine.evaluate(script, new SimpleScriptContext()); // $hasMvelInjection
6161
}
6262

6363
public static void testMvelCompiledScriptCompileAndEvaluate(Socket socket) throws Exception {
6464
MvelScriptEngine engine = new MvelScriptEngine();
6565
ExpressionCompiler compiler = new ExpressionCompiler(read(socket));
6666
ExecutableStatement statement = compiler.compile();
6767
MvelCompiledScript script = new MvelCompiledScript(engine, statement);
68-
script.eval(new SimpleScriptContext());
68+
script.eval(new SimpleScriptContext()); // $hasMvelInjection
6969
}
7070

7171
public static void testTemplateRuntimeEval(Socket socket) throws Exception {
72-
TemplateRuntime.eval(read(socket), new HashMap());
72+
TemplateRuntime.eval(read(socket), new HashMap()); // $hasMvelInjection
7373
}
7474

7575
public static void testTemplateRuntimeCompileTemplateAndExecute(Socket socket) throws Exception {
76-
TemplateRuntime.execute(
77-
TemplateCompiler.compileTemplate(read(socket)), new HashMap());
76+
TemplateRuntime.execute(TemplateCompiler.compileTemplate(read(socket)), new HashMap()); // $hasMvelInjection
7877
}
7978

8079
public static void testTemplateRuntimeCompileAndExecute(Socket socket) throws Exception {
8180
TemplateCompiler compiler = new TemplateCompiler(read(socket));
82-
TemplateRuntime.execute(compiler.compile(), new HashMap());
81+
TemplateRuntime.execute(compiler.compile(), new HashMap()); // $hasMvelInjection
8382
}
8483

8584
public static void testMvelRuntimeExecute(Socket socket) throws Exception {
8685
ExpressionCompiler compiler = new ExpressionCompiler(read(socket));
8786
CompiledExpression expression = compiler.compile();
88-
MVELRuntime.execute(false, expression, new Object(), new ImmutableDefaultFactory());
87+
MVELRuntime.execute(false, expression, new Object(), new ImmutableDefaultFactory()); // $hasMvelInjection
8988
}
9089

9190
public static String read(Socket socket) throws IOException {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java
2+
import semmle.code.java.dataflow.TaintTracking
3+
import semmle.code.java.dataflow.FlowSources
4+
import semmle.code.java.security.MvelInjection
5+
import TestUtilities.InlineExpectationsTest
6+
7+
class Conf extends TaintTracking::Configuration {
8+
Conf() { this = "test:cwe:mvel-injection" }
9+
10+
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
11+
12+
override predicate isSink(DataFlow::Node sink) { sink instanceof MvelEvaluationSink }
13+
14+
override predicate isSanitizer(DataFlow::Node sanitizer) {
15+
sanitizer instanceof MvelInjectionSanitizer
16+
}
17+
18+
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
19+
any(MvelInjectionAdditionalTaintStep c).step(node1, node2)
20+
}
21+
}
22+
23+
class HasMvelInjectionTest extends InlineExpectationsTest {
24+
HasMvelInjectionTest() { this = "HasMvelInjectionTest" }
25+
26+
override string getARelevantTag() { result = "hasMvelInjection" }
27+
28+
override predicate hasActualResult(Location location, string element, string tag, string value) {
29+
tag = "hasMvelInjection" and
30+
exists(DataFlow::Node src, DataFlow::Node sink, Conf conf | conf.hasFlow(src, sink) |
31+
sink.getLocation() = location and
32+
element = sink.toString() and
33+
value = ""
34+
)
35+
}
36+
}

0 commit comments

Comments
 (0)