Skip to content

Commit 7ddd4fa

Browse files
committed
(fix): check innerClazz while get property
1 parent 20a3c7f commit 7ddd4fa

3 files changed

Lines changed: 38 additions & 28 deletions

File tree

‎src/main/java/com/googlecode/aviator/AviatorEvaluatorInstance.java‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import com.googlecode.aviator.code.interpreter.InterpretCodeGenerator;
5959
import com.googlecode.aviator.exception.CompileExpressionErrorException;
6060
import com.googlecode.aviator.exception.ExpressionNotFoundException;
61+
import com.googlecode.aviator.exception.ExpressionRuntimeException;
6162
import com.googlecode.aviator.exception.ExpressionSyntaxErrorException;
6263
import com.googlecode.aviator.exception.UnsupportedFeatureException;
6364
import com.googlecode.aviator.lexer.ExpressionLexer;
@@ -1885,4 +1886,37 @@ public StringSegments compileStringSegments(final String lexeme, final String so
18851886
return new StringSegments(Collections.<StringSegment>emptyList(), 0);
18861887
}
18871888
}
1889+
1890+
1891+
/**
1892+
* check if class is in Options.ALLOWED_CLASS_SET
1893+
*
1894+
* @param checkIfAllow check or not
1895+
* @param clazz the class for check
1896+
* @return the class for check
1897+
*/
1898+
public Class<?> checkIfClassIsAllowed(final boolean checkIfAllow, final Class<?> clazz) {
1899+
if (checkIfAllow) {
1900+
Set<Class<?>> allowedList = this.getOptionValue(Options.ALLOWED_CLASS_SET).classes;
1901+
if (allowedList != null) {
1902+
// Null list means allowing all classes
1903+
if (!allowedList.contains(clazz)) {
1904+
throw new ExpressionRuntimeException(
1905+
"`" + clazz + "` is not in allowed class set, check Options.ALLOWED_CLASS_SET");
1906+
}
1907+
}
1908+
Set<Class<?>> assignableList =
1909+
this.getOptionValue(Options.ASSIGNABLE_ALLOWED_CLASS_SET).classes;
1910+
if (assignableList != null) {
1911+
for (Class<?> aClass : assignableList) {
1912+
if (aClass.isAssignableFrom(clazz)) {
1913+
return clazz;
1914+
}
1915+
}
1916+
throw new ExpressionRuntimeException(
1917+
"`" + clazz + "` is not in allowed class set, check Options.ALLOWED_CLASS_SET");
1918+
}
1919+
}
1920+
return clazz;
1921+
}
18881922
}

‎src/main/java/com/googlecode/aviator/utils/Env.java‎

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import com.googlecode.aviator.AviatorEvaluatorInstance;
3535
import com.googlecode.aviator.Expression;
3636
import com.googlecode.aviator.Feature;
37-
import com.googlecode.aviator.Options;
38-
import com.googlecode.aviator.exception.ExpressionRuntimeException;
3937
import com.googlecode.aviator.runtime.function.FunctionUtils;
4038
import com.googlecode.aviator.runtime.type.Range;
4139

@@ -199,32 +197,7 @@ public Class<?> resolveClassSymbol(final String name, final boolean checkIfAllow
199197
throw new ClassNotFoundException(name);
200198
}
201199
put2cache(name, clazz);
202-
return checkIfClassIsAllowed(checkIfAllow, clazz);
203-
}
204-
205-
private Class<?> checkIfClassIsAllowed(final boolean checkIfAllow, final Class<?> clazz) {
206-
if (checkIfAllow) {
207-
Set<Class<?>> allowedList = this.instance.getOptionValue(Options.ALLOWED_CLASS_SET).classes;
208-
if (allowedList != null) {
209-
// Null list means allowing all classes
210-
if (!allowedList.contains(clazz)) {
211-
throw new ExpressionRuntimeException(
212-
"`" + clazz + "` is not in allowed class set, check Options.ALLOWED_CLASS_SET");
213-
}
214-
}
215-
Set<Class<?>> assignableList =
216-
this.instance.getOptionValue(Options.ASSIGNABLE_ALLOWED_CLASS_SET).classes;
217-
if (assignableList != null) {
218-
for (Class<?> aClass : assignableList) {
219-
if (aClass.isAssignableFrom(clazz)) {
220-
return clazz;
221-
}
222-
}
223-
throw new ExpressionRuntimeException(
224-
"`" + clazz + "` is not in allowed class set, check Options.ALLOWED_CLASS_SET");
225-
}
226-
}
227-
return clazz;
200+
return this.instance.checkIfClassIsAllowed(checkIfAllow, clazz);
228201
}
229202

230203
private Class<?> resolveFromImportedPackages(final String name) {

‎src/main/java/com/googlecode/aviator/utils/Reflector.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,9 @@ public static Object fastGetProperty(final String name, final String[] names,
797797

798798
if (target.innerClazz != null) {
799799
final AviatorEvaluatorInstance instance = RuntimeUtils.getInstance(env);
800+
// check innerClazz is allowed
801+
instance.checkIfClassIsAllowed(true, target.innerClazz);
802+
800803
if (tryResolveStaticMethod && instance.isFeatureEnabled(Feature.StaticMethods)
801804
&& names.length == 2) {
802805
val = fastGetProperty(target.innerClazz, rName, PropertyType.StaticMethod);

0 commit comments

Comments
 (0)