Skip to content

Commit 3f97578

Browse files
committed
Improved: Improve ObjectInputStream denyList (OFBIZ-12221)
In SafeObjectInputStream.properties Renames listOfSafeObjectsForInputStream to allowList and fixes it Introduces a denyList Adapts SafeObjectInputStream class to new denyList
1 parent fcc0078 commit 3f97578

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

framework/base/config/SafeObjectInputStream.properties

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@
1717
# under the License.
1818
###############################################################################
1919

20-
# Because of OFBIZ-10837 - Improve ObjectInputStream class.
21-
# If you encounter a related issue (object not in the allowlist),
22-
# you must provide a complete list of objects to pass to ObjectInputStream
23-
# through ListOfSafeObjectsForInputStream property
24-
# As an example, the a complete list of objects used by OFBiz OOTB is here.
20+
# Because of OFBIZ-10837 "Improve ObjectInputStream class."
21+
# If you encounter a related issue (object not in the allowList),
22+
# you must provide a complete list of objects to pass to ObjectInputStream through allowList property
23+
# As an example, the a complete list of objects used by OFBiz OOTB is here in allowList.
2524
# You will need to add your objects/classes to this list.
26-
# OFBiz committers: don't forget to add newobjects in SafeObjectInputStream class too (as default there).
2725

26+
# OFBiz committers:
27+
# . don't forget to add new objects in SafeObjectInputStream class too (as default there).
28+
# . "foo" and "SerializationInjector" are used in OFBiz tests
2829

29-
listOfSafeObjectsForInputStream=byte\\\\[\\\\], foo, SerializationInjector, \\\\[Z,\\\\[B,\\\\[S,\\\\[I,\\\\[J,\\\\[F,\\\\[D,\\\\[C, java..*, sun.util.calendar..*, org.apache.ofbiz..*, org.codehaus.groovy.runtime.GStringImpl, groovy.lang.GString
30+
allowList=byte\\[\\], foo, SerializationInjector, \\[Z,\\[B,\\[S,\\[I,\\[J,\\[F,\\[D,\\[C, java..*, sun.util.calendar..*, org.apache.ofbiz..*, org.codehaus.groovy.runtime.GStringImpl, groovy.lang.GString
31+
32+
#-- List of strings rejected for serialisation
33+
#-- The same comments than for allowList apply to denyList
34+
denyList=rmi, <

framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public final class SafeObjectInputStream extends ObjectInputStream {
4242
"\\[Z", "\\[B", "\\[S", "\\[I", "\\[J", "\\[F", "\\[D", "\\[C",
4343
"java..*", "sun.util.calendar..*", "org.apache.ofbiz..*",
4444
"org.codehaus.groovy.runtime.GStringImpl", "groovy.lang.GString"};
45+
private static final String[] DEFAULT_DENYLIST = { "rmi", "<" };
4546

4647
/** The regular expression used to match serialized types. */
4748
private final Pattern allowlistPattern;
@@ -53,9 +54,9 @@ public final class SafeObjectInputStream extends ObjectInputStream {
5354
*/
5455
public SafeObjectInputStream(InputStream in) throws IOException {
5556
super(in);
56-
String safeObjectsProp = getPropertyValue("SafeObjectInputStream", "ListOfSafeObjectsForInputStream", "");
57-
String[] allowlist = safeObjectsProp.isEmpty() ? DEFAULT_ALLOWLIST_PATTERN : safeObjectsProp.split(",");
58-
allowlistPattern = Arrays.stream(allowlist)
57+
String allowListProp = getPropertyValue("SafeObjectInputStream", "allowList", "");
58+
String[] allowList = allowListProp.isEmpty() ? DEFAULT_ALLOWLIST_PATTERN : allowListProp.split(",");
59+
allowlistPattern = Arrays.stream(allowList)
5960
.map(String::trim)
6061
.filter(str -> !str.isEmpty())
6162
.collect(collectingAndThen(joining("|", "(", ")"), Pattern::compile));
@@ -65,9 +66,13 @@ public SafeObjectInputStream(InputStream in) throws IOException {
6566
protected Class<?> resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
6667
String className = classDesc.getName();
6768
// DenyList
68-
if (className.contains("java.rmi") // Don't allow RMI
69-
|| className.contains("<")) { // Prevent generics markup in string type names
70-
throw new InvalidClassException(className, "Unauthorized deserialisation attempt");
69+
String rejectedObjectsProp = getPropertyValue("security", "denyList", "");
70+
String[] denyList = rejectedObjectsProp.isEmpty() ? DEFAULT_DENYLIST : rejectedObjectsProp.split(",");
71+
// For now DEFAULT_DENYLIST: don't allow RMI, prevent generics markup in string type names
72+
for (String deny : denyList) {
73+
if (className.contains(deny)) {
74+
throw new InvalidClassException(className, "Unauthorized deserialisation attempt");
75+
}
7176
}
7277
if (!allowlistPattern.matcher(className).find()) {
7378
Debug.logWarning("***Incompatible class***: " + className

0 commit comments

Comments
 (0)