3
3
import java .lang .invoke .LambdaMetafactory ;
4
4
import java .lang .invoke .StringConcatFactory ;
5
5
import java .lang .reflect .InvocationTargetException ;
6
- import java .lang .reflect .Method ;
7
6
import java .net .URL ;
8
7
import java .net .URLClassLoader ;
9
8
import java .util .HashSet ;
@@ -41,10 +40,16 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {
41
40
}
42
41
// If this is not a user provided class, we are loading something used by a user provided class.
43
42
// If it is either an allowed class or package, we can load with our standard class loader.
44
- // Otherwise, throw an exception.
45
43
if (this .allowedClasses .contains (name )) {
46
44
return this .approvedClassLoader .loadClass (name );
47
45
}
46
+
47
+ // Validation code has a few additional allowed classes.
48
+ if (this .permissionLevel == RunPermissionLevel .VALIDATOR
49
+ && this .validatorAllowedClasses .contains (name )) {
50
+ return this .approvedClassLoader .loadClass (name );
51
+ }
52
+
48
53
// allow .<specific-class> usage from allowed packages. If this code
49
54
// has validation permissions, also check the
50
55
// validator permissions allowed package list.
@@ -107,11 +112,7 @@ private boolean isInAllowedPackage(String[] allowedPackageList, String name) {
107
112
String .class .getName (),
108
113
StringBuffer .class .getName (),
109
114
StringBuilder .class .getName (),
110
- Throwable .class .getName (),
111
- ThreadLocal .class .getName (), // EasyMock support
112
- CloneNotSupportedException .class .getName (), // EasyMock support
113
- Method .class .getName (), // EasyMock support
114
- InvocationTargetException .class .getName ()); // EasyMock support
115
+ Throwable .class .getName ());
115
116
116
117
// Allowed packages (any individual class is allowed from these classes)
117
118
private static final String [] allowedPackages =
@@ -126,11 +127,16 @@ private boolean isInAllowedPackage(String[] allowedPackageList, String name) {
126
127
"org.code.neighborhood." ,
127
128
"org.code.theater." ,
128
129
"org.code.lang" ,
129
- "org.easymock." ,
130
130
"jdk.internal.reflect.SerializationConstructorAccessorImpl" // EasyMock support
131
131
};
132
132
133
133
// Allowed packages for code with elevated permissions, such as validation code.
134
134
private static final String [] validatorAllowedPackages =
135
- new String [] {"org.code.validation" , "java.lang.reflect" };
135
+ new String [] {"org.code.validation" , "java.lang.reflect" , "org.easymock." };
136
+
137
+ private static final Set <String > validatorAllowedClasses =
138
+ Set .of (
139
+ ThreadLocal .class .getName (), // EasyMock support
140
+ CloneNotSupportedException .class .getName (), // EasyMock support
141
+ InvocationTargetException .class .getName ()); // EasyMock support
136
142
}
0 commit comments