Skip to content

Commit 996f701

Browse files
committed
Refine PropertyDescriptor filtering
Restrict property paths under `Class` and properties of types `ClassLoader` or `ProtectionDomain`.
1 parent 90cfde9 commit 996f701

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import java.beans.IntrospectionException;
2121
import java.beans.Introspector;
2222
import java.beans.PropertyDescriptor;
23+
import java.security.ProtectionDomain;
2324
import java.util.Collections;
2425
import java.util.LinkedHashMap;
2526
import java.util.List;
@@ -281,9 +282,13 @@ private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
281282
// This call is slow so we do it once.
282283
PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
283284
for (PropertyDescriptor pd : pds) {
284-
if (Class.class == beanClass &&
285-
("classLoader".equals(pd.getName()) || "protectionDomain".equals(pd.getName()))) {
286-
// Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those
285+
if (Class.class == beanClass && (!"name".equals(pd.getName()) && !pd.getName().endsWith("Name"))) {
286+
// Only allow all name variants of Class properties
287+
continue;
288+
}
289+
if (pd.getPropertyType() != null && (ClassLoader.class.isAssignableFrom(pd.getPropertyType())
290+
|| ProtectionDomain.class.isAssignableFrom(pd.getPropertyType()))) {
291+
// Ignore ClassLoader and ProtectionDomain types - nobody needs to bind to those
287292
continue;
288293
}
289294
if (logger.isTraceEnabled()) {
@@ -321,6 +326,11 @@ private void introspectInterfaces(Class<?> beanClass, Class<?> currClass) throws
321326
// GenericTypeAwarePropertyDescriptor leniently resolves a set* write method
322327
// against a declared read method, so we prefer read method descriptors here.
323328
pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
329+
if (pd.getPropertyType() != null && (ClassLoader.class.isAssignableFrom(pd.getPropertyType())
330+
|| ProtectionDomain.class.isAssignableFrom(pd.getPropertyType()))) {
331+
// Ignore ClassLoader and ProtectionDomain types - nobody needs to bind to those
332+
continue;
333+
}
324334
this.propertyDescriptors.put(pd.getName(), pd);
325335
}
326336
}

0 commit comments

Comments
 (0)