Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the switch to open class check, default is true #8537

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -389,6 +389,8 @@ public interface CommonConstants {

String DEFAULT_VERSION = "0.0.0";

String CLASS_DESERIALIZE_OPEN_CHECK = "dubbo.security.serialize.openCheckClass";

String CLASS_DESERIALIZE_BLOCK_ALL = "dubbo.security.serialize.blockAllClassExceptAllow";

String CLASS_DESERIALIZE_ALLOWED_LIST = "dubbo.security.serialize.allowedClassList";
Expand Down
Expand Up @@ -32,6 +32,7 @@ public class SerializeClassChecker {

private static volatile SerializeClassChecker INSTANCE = null;

private final boolean OPEN_CHECK_CLASS;
private final boolean BLOCK_ALL_CLASS_EXCEPT_ALLOW;
private final Set<String> CLASS_DESERIALIZE_ALLOWED_SET = new ConcurrentHashSet<>();
private final Set<String> CLASS_DESERIALIZE_BLOCKED_SET = new ConcurrentHashSet<>();
Expand All @@ -43,6 +44,9 @@ public class SerializeClassChecker {
private final AtomicLong counter = new AtomicLong(0);

private SerializeClassChecker() {
String openCheckClass = System.getProperty(CommonConstants.CLASS_DESERIALIZE_OPEN_CHECK, "true");
OPEN_CHECK_CLASS = Boolean.parseBoolean(openCheckClass);

String blockAllClassExceptAllow = System.getProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL, "false");
BLOCK_ALL_CLASS_EXCEPT_ALLOW = Boolean.parseBoolean(blockAllClassExceptAllow);

Expand Down Expand Up @@ -107,6 +111,10 @@ protected static void clearInstance() {
* @param name class name ( all are convert to lower case )
*/
public void validateClass(String name) {
if(!OPEN_CHECK_CLASS){
return;
}

name = name.toLowerCase(Locale.ROOT);
if (CACHE == CLASS_ALLOW_LFU_CACHE.get(name)) {
return;
Expand Down