Skip to content

Commit 569426b

Browse files
committed
Consider subtypes of Expression and ExpressionParser
Add parseRaw as additional taint step
1 parent b0852f6 commit 569426b

File tree

10 files changed

+392
-13
lines changed

10 files changed

+392
-13
lines changed

java/ql/src/semmle/code/java/security/SpelInjection.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private predicate isSimpleEvaluationContextBuilderCall(Expr expr) {
105105
*/
106106
private class ExpressionEvaluationMethod extends Method {
107107
ExpressionEvaluationMethod() {
108-
this.getDeclaringType() instanceof Expression and
108+
this.getDeclaringType().getASupertype*() instanceof Expression and
109109
this.hasName(["getValue", "getValueTypeDescriptor", "getValueType", "setValue"])
110110
}
111111
}
@@ -116,8 +116,8 @@ private class ExpressionEvaluationMethod extends Method {
116116
*/
117117
private predicate expressionParsingStep(DataFlow::Node node1, DataFlow::Node node2) {
118118
exists(MethodAccess ma, Method m | ma.getMethod() = m |
119-
m.getDeclaringType().getAnAncestor*() instanceof ExpressionParser and
120-
m.hasName("parseExpression") and
119+
m.getDeclaringType().getASupertype*() instanceof ExpressionParser and
120+
m.hasName(["parseExpression", "parseRaw"]) and
121121
ma.getAnArgument() = node1.asExpr() and
122122
node2.asExpr() = ma
123123
)

java/ql/test/query-tests/security/CWE-094/SpelInjectionTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.net.Socket;
44
import org.springframework.expression.Expression;
55
import org.springframework.expression.ExpressionParser;
6+
import org.springframework.expression.spel.standard.SpelExpression;
67
import org.springframework.expression.spel.standard.SpelExpressionParser;
78
import org.springframework.expression.spel.support.SimpleEvaluationContext;
89
import org.springframework.expression.spel.support.StandardEvaluationContext;
@@ -23,6 +24,17 @@ public void testGetValue(Socket socket) throws IOException {
2324
expression.getValue(); // $hasSpelInjection
2425
}
2526

27+
public void testGetValueWithParseRaw(Socket socket) throws IOException {
28+
InputStream in = socket.getInputStream();
29+
30+
byte[] bytes = new byte[1024];
31+
int n = in.read(bytes);
32+
String input = new String(bytes, 0, n);
33+
SpelExpressionParser parser = new SpelExpressionParser();
34+
SpelExpression expression = parser.parseRaw(input);
35+
expression.getValue(); // $hasSpelInjection
36+
}
37+
2638
public void testGetValueWithChainedCalls(Socket socket) throws IOException {
2739
InputStream in = socket.getInputStream();
2840

java/ql/test/stubs/springframework-5.3.8/org/springframework/expression/Expression.java

Lines changed: 53 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/springframework-5.3.8/org/springframework/expression/ExpressionException.java

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/springframework-5.3.8/org/springframework/expression/ExpressionParser.java

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/springframework-5.3.8/org/springframework/expression/ParseException.java

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/springframework-5.3.8/org/springframework/expression/ParserContext.java

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/springframework-5.3.8/org/springframework/expression/common/TemplateAwareExpressionParser.java

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)