Skip to content

Commit 9b87157

Browse files
committed
Disallow method pointer expressions in Groovy scripting
1 parent 647327f commit 9b87157

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/main/java/org/elasticsearch/script/groovy/GroovySandboxExpressionChecker.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121

2222
import com.google.common.collect.ImmutableSet;
2323
import org.codehaus.groovy.ast.ClassNode;
24-
import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
25-
import org.codehaus.groovy.ast.expr.Expression;
26-
import org.codehaus.groovy.ast.expr.GStringExpression;
27-
import org.codehaus.groovy.ast.expr.MethodCallExpression;
24+
import org.codehaus.groovy.ast.expr.*;
2825
import org.codehaus.groovy.control.customizers.SecureASTCustomizer;
2926
import org.elasticsearch.common.settings.Settings;
3027

@@ -68,6 +65,7 @@ public GroovySandboxExpressionChecker(Settings settings, Set<String> blacklistAd
6865
"wait",
6966
"notify",
7067
"notifyAll",
68+
"invokeMethod",
7169
"finalize"
7270
};
7371

@@ -119,7 +117,9 @@ public GroovySandboxExpressionChecker(Settings settings, Set<String> blacklistAd
119117
*/
120118
@Override
121119
public boolean isAuthorized(Expression expression) {
122-
if (expression instanceof MethodCallExpression) {
120+
if (expression instanceof MethodPointerExpression) {
121+
return false;
122+
} else if (expression instanceof MethodCallExpression) {
123123
MethodCallExpression mce = (MethodCallExpression) expression;
124124
String methodName = mce.getMethodAsString();
125125
if (methodBlacklist.contains(methodName)) {

src/test/java/org/elasticsearch/script/GroovySandboxScriptTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ public void testSandboxedGroovyScript() {
9090

9191
testFailure("def methodName = 'ex'; Runtime.\\\"${'get' + 'Runtime'}\\\"().\\\"${methodName}ec\\\"(\\\"touch /tmp/gotcha2\\\")",
9292
"Expression [MethodCallExpression] is not allowed: java.lang.Runtime.$(get + Runtime)().$methodNameec(touch /tmp/gotcha2)");
93+
94+
testFailure("def c = [doc['foo'].value, 3, 4].&size; c()",
95+
"Expression [MethodPointerExpression] is not allowed");
96+
97+
testFailure("[doc['foo'].value, 3, 4].invokeMethod([1,2],\\\"size\\\", new Object[0])",
98+
"Expression [MethodCallExpression] is not allowed: [doc[foo].value, 3, 4].invokeMethod([1, 2], size, [])");
9399
}
94100

95101
@Test

0 commit comments

Comments
 (0)