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 check #11217

Merged
merged 43 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
704c6d6
submit
AlbumenJ Sep 6, 2022
e4f6750
fix style
AlbumenJ Sep 8, 2022
e73d111
allow dubbo
AlbumenJ Sep 8, 2022
2f1a804
allow dubbo
AlbumenJ Sep 8, 2022
7f676db
update package
AlbumenJ Sep 8, 2022
44313b9
fix name
AlbumenJ Sep 8, 2022
3d5d75d
add uts
AlbumenJ Sep 11, 2022
efb5352
add uts
AlbumenJ Sep 11, 2022
e306b31
add notify
AlbumenJ Sep 11, 2022
c7b7506
add header
AlbumenJ Sep 11, 2022
43f8f76
fix style
AlbumenJ Sep 11, 2022
03ba9e9
Opt tests
AlbumenJ Sep 11, 2022
5967047
Add test cases
AlbumenJ Sep 11, 2022
d4c2393
fix class
AlbumenJ Sep 11, 2022
3558203
Add status check
AlbumenJ Sep 11, 2022
37067cc
fix order
AlbumenJ Sep 11, 2022
0bd3dee
fix order
AlbumenJ Sep 11, 2022
8f2e89c
change to warn
AlbumenJ Sep 11, 2022
0f844d7
Hessian 2 support allow list
AlbumenJ Sep 11, 2022
edb59de
fix digit
AlbumenJ Sep 11, 2022
6f80cef
fix ant
AlbumenJ Sep 11, 2022
00ea17e
Fix cases
AlbumenJ Sep 12, 2022
58893f7
fix case
AlbumenJ Sep 12, 2022
07e186c
Fix list
AlbumenJ Sep 12, 2022
2b91ebf
update fastjson2
AlbumenJ Sep 13, 2022
68f1b53
fix uts
AlbumenJ Sep 13, 2022
d51e9aa
try strict
AlbumenJ Sep 13, 2022
140a34d
fix list
AlbumenJ Sep 13, 2022
019a3be
add compatible constructor
AlbumenJ Sep 13, 2022
55ebbdd
update fj2
AlbumenJ Sep 13, 2022
049e58a
try set default
AlbumenJ Sep 13, 2022
aefa034
update list
AlbumenJ Sep 14, 2022
f128cf6
fix uts
AlbumenJ Sep 14, 2022
a96aeac
update list
AlbumenJ Sep 14, 2022
540d056
update fj2
AlbumenJ Sep 15, 2022
2ddde37
Merge branch '0911_h2_allow' into 0905_fj2_security
AlbumenJ Sep 15, 2022
4705ff1
Merge branch 'apache-3.1' into 0905_fj2_security-1
AlbumenJ Dec 28, 2022
9014fc8
Fix pom
AlbumenJ Dec 28, 2022
9dca0e8
Fix pom
AlbumenJ Dec 28, 2022
a3a8066
Fix SPI
AlbumenJ Dec 29, 2022
706f40e
Fix default
AlbumenJ Dec 29, 2022
0f2b1f2
fix serialization
AlbumenJ Dec 29, 2022
31231c1
update list
AlbumenJ Dec 29, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.dubbo.common.lang.ShutdownHookCallbacks;
import org.apache.dubbo.common.status.reporter.FrameworkStatusReportService;
import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository;
import org.apache.dubbo.common.utils.SerializeSecurityManager;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
Expand All @@ -33,6 +34,7 @@ public void initializeFrameworkModel(FrameworkModel frameworkModel) {
ScopeBeanFactory beanFactory = frameworkModel.getBeanFactory();
beanFactory.registerBean(FrameworkExecutorRepository.class);
beanFactory.registerBean(ConverterUtil.class);
beanFactory.registerBean(SerializeSecurityManager.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ public interface CommonConstants {

String SERIALIZE_BLOCKED_LIST_FILE_PATH = "security/serialize.blockedlist";

String SERIALIZE_ALLOW_LIST_FILE_PATH = "security/serialize.allowlist";

String QOS_LIVE_PROBE_EXTENSION = "dubbo.application.liveness-probe";

String QOS_READY_PROBE_EXTENSION = "dubbo.application.readiness-probe";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.
*/
package org.apache.dubbo.common.utils;

import java.util.Set;

public interface AllowClassNotifyListener {

SerializeCheckStatus DEFAULT_STATUS = SerializeCheckStatus.STRICT;

void notify(SerializeCheckStatus status, Set<String> prefixList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import java.lang.ref.SoftReference;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
Expand All @@ -46,7 +46,7 @@ public class ClassLoaderResourceLoader {
GlobalResourcesRepository.registerGlobalDisposable(() -> destroy());
}

public static Map<ClassLoader, Set<URL>> loadResources(String fileName, List<ClassLoader> classLoaders) throws InterruptedException {
public static Map<ClassLoader, Set<URL>> loadResources(String fileName, Collection<ClassLoader> classLoaders) throws InterruptedException {
Map<ClassLoader, Set<URL>> resources = new ConcurrentHashMap<>();
CountDownLatch countDownLatch = new CountDownLatch(classLoaders.size());
for (ClassLoader classLoader : classLoaders) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/
package org.apache.dubbo.common.utils;

public enum SerializeCheckStatus {
DISABLED,
WARN,
STRICT,
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.dubbo.common.utils;

import org.apache.dubbo.common.beanutil.JavaBeanSerializeUtil;
import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
Expand Down Expand Up @@ -52,10 +51,10 @@ public class SerializeClassChecker {
private final AtomicLong counter = new AtomicLong(0);

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

String blockAllClassExceptAllow = ConfigurationUtils.getProperty(CLASS_DESERIALIZE_BLOCK_ALL, "false");
String blockAllClassExceptAllow = System.getProperty(CLASS_DESERIALIZE_BLOCK_ALL, "false");

BLOCK_ALL_CLASS_EXCEPT_ALLOW = Boolean.parseBoolean(blockAllClassExceptAllow);

Expand All @@ -79,8 +78,8 @@ private SerializeClassChecker() {
logger.error(COMMON_IO_EXCEPTION, "", "", "Failed to load blocked class list! Will ignore default blocked list.", e);
}

String allowedClassList = ConfigurationUtils.getProperty(CLASS_DESERIALIZE_ALLOWED_LIST, "").trim().toLowerCase(Locale.ROOT);
String blockedClassList = ConfigurationUtils.getProperty(CLASS_DESERIALIZE_BLOCKED_LIST, "").trim().toLowerCase(Locale.ROOT);
String allowedClassList = System.getProperty(CLASS_DESERIALIZE_ALLOWED_LIST, "").trim().toLowerCase(Locale.ROOT);
String blockedClassList = System.getProperty(CLASS_DESERIALIZE_BLOCKED_LIST, "").trim().toLowerCase(Locale.ROOT);

if (StringUtils.isNotEmpty(allowedClassList)) {
String[] classStrings = allowedClassList.trim().split(",");
Expand Down Expand Up @@ -120,34 +119,45 @@ protected static void clearInstance() {
* @throws IllegalArgumentException if class is blocked
*/
public void validateClass(String name) {
validateClass(name, true);
}

public boolean validateClass(String name, boolean failOnError) {
if (!OPEN_CHECK_CLASS) {
return;
return true;
}

name = name.toLowerCase(Locale.ROOT);
if (CACHE == CLASS_ALLOW_LFU_CACHE.get(name)) {
return;
return true;
}

if (CACHE == CLASS_BLOCK_LFU_CACHE.get(name)) {
error(name);
if (failOnError) {
error(name);
}
return false;
}

for (String allowedPrefix : CLASS_DESERIALIZE_ALLOWED_SET) {
if (name.startsWith(allowedPrefix)) {
CLASS_ALLOW_LFU_CACHE.put(name, CACHE);
return;
return true;
}
}

for (String blockedPrefix : CLASS_DESERIALIZE_BLOCKED_SET) {
if (BLOCK_ALL_CLASS_EXCEPT_ALLOW || name.startsWith(blockedPrefix)) {
CLASS_BLOCK_LFU_CACHE.put(name, CACHE);
error(name);
if (failOnError) {
error(name);
}
return false;
}
}

CLASS_ALLOW_LFU_CACHE.put(name, CACHE);
return true;
}

private void error(String name) {
Expand Down