Skip to content

Commit e47b94f

Browse files
committed
Security permissions for Groovy JsonSlurper
This commit adds the necessary class permissions and property permissions for basic Groovy JsonSlurper functionality.
1 parent 7140d18 commit e47b94f

File tree

7 files changed

+36
-1
lines changed

7 files changed

+36
-1
lines changed

core/src/main/resources/org/elasticsearch/bootstrap/untrusted.policy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ grant {
2525

2626
// groovy IndyInterface bootstrap requires this property for indy logging
2727
permission java.util.PropertyPermission "groovy.indy.logging", "read";
28+
29+
// needed by Groovy JsonSlurper
30+
permission java.util.PropertyPermission "groovy.json.internKeys", "read";
31+
permission java.util.PropertyPermission "jdk.map.althashing.threshold", "read";
32+
permission java.util.PropertyPermission "groovy.json.faststringutils.write.to.final.fields", "read";
33+
permission java.util.PropertyPermission "groovy.json.faststringutils.disable", "read";
2834

2935
// needed by Rhino engine exception handling
3036
permission java.util.PropertyPermission "rhino.stack.style", "read";

modules/lang-groovy/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ esplugin {
2424

2525
dependencies {
2626
compile 'org.codehaus.groovy:groovy:2.4.4:indy'
27+
compile 'org.codehaus.groovy:groovy-json:2.4.4:indy'
2728
}
2829

2930
integTest {
@@ -36,7 +37,10 @@ integTest {
3637
thirdPartyAudit.excludes = [
3738
// classes are missing, we bring in a minimal groovy dist
3839
// for example we do not need ivy, scripts arent allowed to download code
39-
'com.thoughtworks.xstream.XStream',
40+
'com.thoughtworks.xstream.XStream',
41+
'groovy.json.internal.FastStringUtils',
42+
'groovy.json.internal.FastStringUtils$StringImplementation$1',
43+
'groovy.json.internal.FastStringUtils$StringImplementation$2',
4044
'groovyjarjarasm.asm.util.Textifiable',
4145
'org.apache.ivy.Ivy',
4246
'org.apache.ivy.core.event.IvyListener',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1214cc694b9945278ef61e16dfbfe743dd1cceaf
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*
14+
*/
15+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Apache Commons CLI
2+
Copyright 2001-2009 The Apache Software Foundation
3+
4+
This product includes software developed by
5+
The Apache Software Foundation (http://www.apache.org/).

modules/lang-groovy/src/main/plugin-metadata/plugin-security.policy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ grant {
5656
permission org.elasticsearch.script.ClassPermission "groovy.lang.MetaClass";
5757
permission org.elasticsearch.script.ClassPermission "groovy.lang.Range";
5858
permission org.elasticsearch.script.ClassPermission "groovy.lang.Reference";
59+
permission org.elasticsearch.script.ClassPermission "groovy.json.JsonSlurper";
60+
permission org.elasticsearch.script.ClassPermission "groovy.json.internal.JsonParserCharArray";
5961
};

modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovySecurityTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public void testEvilGroovyScripts() throws Exception {
9696
// assuming a inflation threshold below 100 (15 is current value on Oracle JVMs), checks that the relevant permission is available.
9797
assertSuccess("(1..100).collect{ it + 1 }");
9898

99+
assertSuccess("new groovy.json.JsonSlurper().parseText('{ \"foo\": \"bar\" }')");
100+
99101
// Fail cases:
100102
assertFailure("pr = Runtime.getRuntime().exec(\"touch /tmp/gotcha\"); pr.waitFor()", MissingPropertyException.class);
101103

0 commit comments

Comments
 (0)