Improved: Improve UtilObject class (OFBIZ-12216)
This removes the inoffensive but annoying message in log (which does not show in trunk, see https://github.com/apache/ofbiz-framework/commit/27c9180/ Not the same as in trunk, simply handling with exception Rather than returning null, also shorten java.rmi.server to java.rmi to block more cases
This commit is contained in:
@@ -24,6 +24,7 @@ import static org.apache.ofbiz.base.util.UtilProperties.getPropertyValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InvalidClassException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectStreamClass;
|
||||
import java.util.Arrays;
|
||||
@@ -65,17 +66,13 @@ public final class SafeObjectInputStream extends ObjectInputStream {
|
||||
protected Class<?> resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
|
||||
String className = classDesc.getName();
|
||||
// BlackList exploits; eg: don't allow RMI here
|
||||
if (className.contains("java.rmi.server")) {
|
||||
Debug.logWarning("***Incompatible class***: "
|
||||
+ classDesc.getName()
|
||||
+ ". java.rmi.server classes are not allowed for security reason",
|
||||
"SafeObjectInputStream");
|
||||
return null;
|
||||
if (className.contains("java.rmi")) {
|
||||
throw new InvalidClassException(className, "Unauthorized deserialisation attempt");
|
||||
}
|
||||
if (!whitelistPattern.matcher(className).find()) {
|
||||
// DiskFileItem, FileItemHeadersImpl are not serializable.
|
||||
if (className.contains("org.apache.commons.fileupload")) {
|
||||
return null;
|
||||
throw new ClassNotFoundException("DiskFileItem and FileItemHeadersImpl are not serializable.");
|
||||
}
|
||||
Debug.logWarning("***Incompatible class***: "
|
||||
+ classDesc.getName()
|
||||
|
||||
@@ -93,12 +93,11 @@ public final class UtilObject {
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = getObjectException(bytes);
|
||||
// DiskFileItem, FileItemHeadersImpl are not serializable. So SafeObjectInputStream::resolveClass return null
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
} catch (IOException e) {
|
||||
Debug.logError(e, module);
|
||||
} catch (ClassNotFoundException e1) {
|
||||
// DiskFileItem, FileItemHeadersImpl are not serializable. So SafeObjectInputStream::resolveClass return ClassNotFoundException
|
||||
return null;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user