Skip to content

Commit 7fd9d05

Browse files
committed
Improved: Improve ObjectInputStream denyList (OFBIZ-12221)
Forgot to change ListOfSafeObjectsForInputStream to allowList in UtilObjectTests
1 parent 3f97578 commit 7fd9d05

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +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", "<" };
45+
private static final String[] DEFAULT_DENYLIST = {"rmi", "<"};
4646

4747
/** The regular expression used to match serialized types. */
4848
private final Pattern allowlistPattern;

framework/base/src/test/java/org/apache/ofbiz/base/util/UtilObjectTests.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
import static org.apache.ofbiz.base.util.UtilMisc.toSet;
2222
import static org.apache.ofbiz.base.util.UtilObject.getObjectException;
2323
import static org.apache.ofbiz.base.util.UtilObject.getObjectFromFactory;
24+
import static org.hamcrest.MatcherAssert.assertThat;
2425
import static org.hamcrest.Matchers.contains;
2526
import static org.junit.Assert.assertEquals;
2627
import static org.junit.Assert.assertNotNull;
2728
import static org.junit.Assert.assertNotSame;
2829
import static org.junit.Assert.assertNull;
29-
import static org.hamcrest.MatcherAssert.assertThat;
3030

3131
import java.io.ByteArrayInputStream;
3232
import java.io.ByteArrayOutputStream;
@@ -51,7 +51,7 @@ public class UtilObjectTests {
5151
@After
5252
public void cleanUp() {
5353
// Ensure that the default value of allowed deserialization classes is used.
54-
UtilProperties.setPropertyValueInMemory("SafeObjectInputStream", "ListOfSafeObjectsForInputStream", "");
54+
UtilProperties.setPropertyValueInMemory("SafeObjectInputStream", "allowList", "");
5555
}
5656

5757
public static final class ErrorInjector extends FilterInputStream {
@@ -333,22 +333,19 @@ public void testGetObjectExceptionSafe() throws IOException, ClassNotFoundExcept
333333
// Test reading a valid customized list of string object.
334334
@Test
335335
public void testGetObjectExceptionCustomized() throws IOException, ClassNotFoundException {
336-
UtilProperties.setPropertyValueInMemory("SafeObjectInputStream", "ListOfSafeObjectsForInputStream",
337-
"java.util.Arrays.ArrayList,java.lang.String");
336+
UtilProperties.setPropertyValueInMemory("SafeObjectInputStream", "allowList", "java.util.Arrays.ArrayList,java.lang.String");
338337
testGetObjectExceptionSafe();
339338

340339
// With extra whitespace
341-
UtilProperties.setPropertyValueInMemory("SafeObjectInputStream", "ListOfSafeObjectsForInputStream",
342-
"java.util.Arrays.ArrayList, java.lang.String");
340+
UtilProperties.setPropertyValueInMemory("SafeObjectInputStream", "allowList", "java.util.Arrays.ArrayList, java.lang.String");
343341
testGetObjectExceptionSafe();
344342
}
345343

346344
// Test reading a basic list of string object after forbidding such kind of objects.
347345
@Test(expected = ClassCastException.class)
348346
public void testGetObjectExceptionUnsafe() throws IOException, ClassNotFoundException {
349347
// Only allow object of type where the package prefix is 'org.apache.ofbiz'
350-
UtilProperties.setPropertyValueInMemory("SafeObjectInputStream", "ListOfSafeObjectsForInputStream",
351-
"org.apache.ofbiz..*");
348+
UtilProperties.setPropertyValueInMemory("SafeObjectInputStream", "allowList", "org.apache.ofbiz..*");
352349
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
353350
ObjectOutputStream oos = new ObjectOutputStream(bos)) {
354351
List<String> forbiddenObject = Arrays.asList("foo", "bar", "baz");

0 commit comments

Comments
 (0)