-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathgroovy.policy
271 lines (226 loc) · 11.3 KB
/
groovy.policy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/* Notes on the contents of this policy file:
*
* The following methods in groovy have privileged operations wrapping
* setAccessible. If these wrappers are not provided, most codebases below
* must have the following grant:
* permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
* MetaMethod.createMetaMethod
* MetaMethod.invoke(Object Object[])
* ReflectionMetaMethod.invoke(Object Object[])
* DefaultGroovyMethods.dump(Object)
*/
/*
* This keystore contains the public key of the pair used to sign GroovyTestJar.jar
* See SecurityTest.testReadSignedJar()
*/
// NOT CURRENTLY USED!
//keystore "file:${user.dir}/security/groovykeys";
/*
* ================= Codebases requiring java.security.AllPermission ===============
* The following codebases require java.security.AllPermission. They are considered trusted
* for purposes of groovy security enforcement. In a deployed groovy environment, these classes
* would all be in a set of jars. If these jars are signed, the grants could be strengthened to
* by adding a signedBy clause to the grant.
*/
// Eclipse default output directory to allow running security tests in that IDE
grant codeBase "file:${user.dir}/bin/-" {
permission java.security.AllPermission;
};
// IntelliJ IDEA default output directory to allow running security tests in that IDE
grant codeBase "file:${user.dir}/out/-" {
permission java.security.AllPermission;
};
// Gradle build output directory
grant codeBase "file:${user.dir}/build/-" {
permission java.security.AllPermission;
};
grant codeBase "file:${user.dir}/subprojects/groovy-test/build/-" {
permission java.security.AllPermission;
};
// Gradle dependency cache
grant codeBase "file:${user.home}/.gradle/-" {
permission java.security.AllPermission;
};
grant codeBase "file:${groovy.lib}/-" {
permission java.security.AllPermission;
};
/*
* When running from maven, this codebase is required.
* If not running from maven, the codesource will not be found, but will not cause an error.
*/
grant codeBase "file:${maven.home}/-" {
permission java.security.AllPermission;
};
/*
* When running from Gradle, this codebase is required.
* If not running from Gradle, the codesource will not be found, but will not cause an error.
*/
grant codeBase "file:${gradle.home}/-" {
permission java.security.AllPermission;
};
grant codeBase "file:${gradle.junit}" {
permission java.security.AllPermission;
};
/*
* When running the junit plugin from within eclipse, this codebase is required.
* If not running from eclipse, the codesource will not be found, but will not cause an error.
*/
grant codeBase "file:${user.dir}/../../plugins/-" {
permission java.security.AllPermission;
};
/*
* ================= Default codebases created by groovy. ===============
* The following codebases are assigned when groovy parses a groovy script
*/
/*
* GroovyShell.parse(InputStream,...) is given a codebase of "groovy.shell" because no actual
* codebase can be determined. The other forms of parse(File) and parse(GroovyCodeSource) allow
* for more control. These permission should be set to control scripts that are passed into
* the shell in the form of a string or other groovy code of unknown provenance.
*/
grant codeBase "file:/groovy/shell" {
permission java.lang.RuntimePermission "accessDeclaredMembers";
// For StreamClassloaderInScriptTest.groovy test
permission java.io.FilePermission "${user.dir}${/}blahblah.dat", "read,write,delete";
};
/*
* Similar to "file:/groovy/shell", but implying a direct call to GroovyClassLoader.parse() without
* passing through GroovyShell.
*/
grant codeBase "file:/groovy/script" {
permission java.lang.RuntimePermission "accessDeclaredMembers";
};
/*
* The TestSupport class has a loadClass method that takes a ClassNode and runs it
* through defineClass() of the class loader. The codebase for this operation is
* set to "/groovy/testSupport".
*/
grant codeBase "file:/groovy/testSupport" {
permission java.lang.RuntimePermission "accessDeclaredMembers";
};
/*
* ================= SecurityTest codebases ===============
* The following grants are for individual security test cases where the
* codebase is explicitly specified (e.g. the script is a raw string rather
* than read from a file). Note that even though the codebases conform to
* the file URL syntax, they are not physical files: they represent virtual
* codebases.
* The permission grant that is commented out is the permission that is
* expected to be missing by the test case. It is here as a comment for
* information.
*/
//Since a codebase is a URL, we can make use of the natural hierarchy permission implications
//to grant a 'global' accessDeclaredPermission here.
grant codeBase "file:/groovy/security/-" {
permission java.lang.RuntimePermission "accessDeclaredMembers";
permission java.lang.RuntimePermission "getClassLoader";
};
grant codeBase "file:/groovy/security/testForbiddenPackage" {
//permission java.lang.RuntimePermission "accessClassInPackage.sun.*";
};
grant codeBase "file:/groovy/security/javax/print/deny" {
//permission java.lang.RuntimePermission "accessClassInPackage.javax.print";
};
grant codeBase "file:/groovy/security/javax/print/allow" {
permission java.lang.RuntimePermission "accessClassInPackage.javax.print";
};
/*
* ================= .groovy script file codebases ===============
* The following grants are for individual security test cases.
* The permission grant that is commented out is the permission that is
* expected to be missing by the test case. It is here as a comment for
* information.
*/
grant codeBase "file:${user.dir}/src/test/groovy/-" {
// Required by most groovy scripts during execution because of the heavy use of reflection/
// introspection. The groovy code could potentially be changed to eliminate this requirement
// by adding privileged operations in many places.
permission java.lang.RuntimePermission "accessDeclaredMembers";
};
grant codeBase "file:${user.dir}/src/test/groovy/groovy/security/forbiddenCodeBase.gvy" {
//The following grant is commented out so that the test case will throw an AccessControlException
//permission groovy.security.GroovyCodeSourcePermission "/groovy/security/forbiddenCodeBase";
};
// Grant permission to .groovy files extracted from a signed jar that has been signedBy "Groovy"
grant signedBy "Groovy" {
permission java.lang.RuntimePermission "accessDeclaredMembers";
permission java.util.PropertyPermission "user.home", "read";
};
grant codeBase "file:${user.dir}/src/test/groovy/bugs/BadScriptNameBug.groovy" {
permission java.lang.RuntimePermission "createClassLoader";
permission java.util.PropertyPermission "groovy.compiler.strictNames", "read";
};
grant codeBase "file:${user.dir}/src/test/groovy/groovy/ClosureMethodTest.groovy" {
permission java.lang.RuntimePermission "getClassLoader";
};
grant codeBase "file:${user.dir}/src/test/groovy/groovy/ClosureWithDefaultParamTest.groovy" {
permission java.lang.RuntimePermission "getClassLoader";
permission java.io.FilePermission "src${/}test${/}-", "read";
// Required because test calls File.eachLine which eventually invokes
// groovy.util.CharsetToolkit#getDefaultSystemCharset which does not wrap
// the property access in a privileged block.
permission java.util.PropertyPermission "file.encoding", "read";
};
grant codeBase "file:${user.dir}/src/test/groovy/bugs/ConstructorBug.groovy" {
permission java.lang.RuntimePermission "createClassLoader";
// Required because GroovyCodeSource calls to File#getCanonicalPath (at least on the Windows FileSystem)
permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "groovy.compiler.strictNames", "read";
permission java.io.FilePermission "src${/}test${/}groovy${/}bugs${/}TestBase.groovy", "read";
permission java.io.FilePermission "src${/}test${/}groovy${/}bugs${/}TestDerived.groovy", "read";
permission java.io.FilePermission "${user.dir}${/}target${/}classes${/}test${/}groovy${/}bugs${/}TestBase.class", "read";
permission java.io.FilePermission "${user.dir}${/}target${/}classes${/}test${/}groovy${/}bugs${/}TestDerived.class", "read";
};
grant codeBase "file:${user.dir}/src/test/groovy/groovy/script/ScriptTest.groovy" {
permission java.io.FilePermission "src${/}test${/}groovy${/}-", "read";
permission groovy.security.GroovyCodeSourcePermission "/groovy/shell";
// Required because GroovyCodeSource calls to File#getCanonicalPath (at least on the Windows FileSystem)
permission java.util.PropertyPermission "user.dir", "read";
// Required by MethodTestScript.groovy run as a script
permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
// Required by StreamClassloaderInScriptTest.groovy run as a script
permission java.io.FilePermission "${user.dir}${/}blahblah.dat", "read,write,delete";
// Required for JUnit to report errors for scripts that are junit test cases
permission java.util.PropertyPermission "user.home", "read";
permission java.io.FilePermission "${user.home}${/}junit.properties", "read";
// Required for Gradle 4.7+ printing a line triggered by running the script
permission java.util.PropertyPermission "line.separator", "read";
};
grant codeBase "file:${user.dir}/src/test/groovy/groovy/script/EvalInScript.groovy" {
permission java.io.FilePermission "src${/}test${/}groovy${/}script${/}HelloWorld.groovy", "read";
permission groovy.security.GroovyCodeSourcePermission "/groovy/shell";
// Required because GroovyCodeSource calls to File#getCanonicalPath (at least on the Windows FileSystem)
permission java.util.PropertyPermission "user.dir", "read";
};
grant codeBase "file:${user.dir}/src/test/groovy/groovy/script/MethodTestScript.groovy" {
permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
};
grant codeBase "file:${user.dir}/src/test/groovy/groovy/script/StreamClassloaderInScriptTest.groovy" {
permission groovy.security.GroovyCodeSourcePermission "/groovy/shell";
permission java.io.FilePermission "${user.dir}${/}blahblah.dat", "read,write,delete";
};
grant {
// Required to load Global AST Transforms
permission java.io.FilePermission "${user.dir}${/}target${/}resources${/}main${/}META-INF${/}services${/}-", "read";
permission java.io.FilePermission "${user.dir}${/}target${/}libs${/}-", "read";
// Required for StreamClassloaderInScriptTest
permission java.io.FilePermission "${java.home}${/}-", "read";
};