OpenJDK / jdk-updates / jdk11u
changeset 52562:4c2769189ed5
8231422: Better serial filter handling
Reviewed-by: rriggs
author | robm |
---|---|
date | Tue, 07 Jan 2020 03:41:33 +0000 |
parents | 688e846b87bd |
children | 0f515f4b45fe |
files | src/java.base/share/classes/java/io/ObjectInputFilter.java src/java.base/share/classes/jdk/internal/util/StaticProperty.java src/java.base/share/conf/security/java.security test/jdk/java/io/Serializable/serialFilter/GlobalFilterTest.java test/jdk/java/io/Serializable/serialFilter/security.policy |
diffstat | 5 files changed, 43 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java.base/share/classes/java/io/ObjectInputFilter.java Mon Oct 21 16:52:21 2019 -0700 +++ b/src/java.base/share/classes/java/io/ObjectInputFilter.java Tue Jan 07 03:41:33 2020 +0000 @@ -35,6 +35,7 @@ import java.util.function.Function; import jdk.internal.misc.SharedSecrets; +import jdk.internal.util.StaticProperty; /** * Filter classes, array lengths, and graph metrics during deserialization. @@ -256,7 +257,7 @@ static { configuredFilter = AccessController .doPrivileged((PrivilegedAction<ObjectInputFilter>) () -> { - String props = System.getProperty(SERIAL_FILTER_PROPNAME); + String props = StaticProperty.jdkSerialFilter(); if (props == null) { props = Security.getProperty(SERIAL_FILTER_PROPNAME); }
--- a/src/java.base/share/classes/jdk/internal/util/StaticProperty.java Mon Oct 21 16:52:21 2019 -0700 +++ b/src/java.base/share/classes/jdk/internal/util/StaticProperty.java Tue Jan 07 03:41:33 2020 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,6 +42,7 @@ private static final String USER_HOME = initProperty("user.home"); private static final String USER_DIR = initProperty("user.dir"); private static final String USER_NAME = initProperty("user.name"); + private static final String JDK_SERIAL_FILTER = System.getProperty("jdk.serialFilter"); private StaticProperty() {} @@ -104,4 +105,18 @@ public static String userName() { return USER_NAME; } + + /** + * + * Return the {@code jdk.serialFilter} system property. + * + * <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked + * in this method. The caller of this method should take care to ensure + * that the returned property is not made accessible to untrusted code.</strong> + * + * @return the {@code user.name} system property + */ + public static String jdkSerialFilter() { + return JDK_SERIAL_FILTER; } +}
--- a/src/java.base/share/conf/security/java.security Mon Oct 21 16:52:21 2019 -0700 +++ b/src/java.base/share/conf/security/java.security Tue Jan 07 03:41:33 2020 +0000 @@ -954,8 +954,8 @@ # Patterns are separated by ";" (semicolon). # Whitespace is significant and is considered part of the pattern. # -# If the system property jdk.serialFilter is also specified, it supersedes -# the security property value defined here. +# If the system property jdk.serialFilter is also specified on the command +# line, it supersedes the security property value defined here. # # If a pattern includes a "=", it sets a limit. # If a limit appears more than once the last value is used.
--- a/test/jdk/java/io/Serializable/serialFilter/GlobalFilterTest.java Mon Oct 21 16:52:21 2019 -0700 +++ b/test/jdk/java/io/Serializable/serialFilter/GlobalFilterTest.java Tue Jan 07 03:41:33 2020 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -41,9 +41,11 @@ import org.testng.annotations.DataProvider; /* @test + * @bug 8231422 * @build GlobalFilterTest SerialFilterTest * @run testng/othervm GlobalFilterTest - * @run testng/othervm -Djdk.serialFilter=java.** GlobalFilterTest + * @run testng/othervm -Djdk.serialFilter=java.** + * -Dexpected-jdk.serialFilter=java.** GlobalFilterTest * @run testng/othervm/policy=security.policy GlobalFilterTest * @run testng/othervm/policy=security.policy * -Djava.security.properties=${test.src}/java.security-extra1 @@ -53,6 +55,10 @@ */ @Test public class GlobalFilterTest { + private static final String serialPropName = "jdk.serialFilter"; + private static final String badSerialFilter = "java.lang.StringBuffer;!*"; + private static final String origSerialFilterProperty = + System.setProperty(serialPropName, badSerialFilter); /** * DataProvider of patterns and objects derived from the configured process-wide filter. @@ -61,8 +67,8 @@ @DataProvider(name="globalPatternElements") Object[][] globalPatternElements() { String globalFilter = - System.getProperty("jdk.serialFilter", - Security.getProperty("jdk.serialFilter")); + System.getProperty("expected-" + serialPropName, + Security.getProperty(serialPropName)); if (globalFilter == null) { return new Object[0][]; } @@ -99,12 +105,20 @@ */ @Test() static void globalFilter() { + ObjectInputFilter filter = ObjectInputFilter.Config.getSerialFilter(); + + // Check that the System.setProperty(jdk.serialFilter) DOES NOT affect the filter. + String asSetSystemProp = System.getProperty(serialPropName, + Security.getProperty(serialPropName)); + Assert.assertNotEquals(Objects.toString(filter, null), asSetSystemProp, + "System.setProperty(\"jdk.serialfilter\", ...) should not change filter: " + + asSetSystemProp); + String pattern = - System.getProperty("jdk.serialFilter", - Security.getProperty("jdk.serialFilter")); - ObjectInputFilter filter = ObjectInputFilter.Config.getSerialFilter(); + System.getProperty("expected-" + serialPropName, + Security.getProperty(serialPropName)); System.out.printf("global pattern: %s, filter: %s%n", pattern, filter); - Assert.assertEquals(pattern, Objects.toString(filter, null), + Assert.assertEquals(Objects.toString(filter, null), pattern, "process-wide filter pattern does not match"); }
--- a/test/jdk/java/io/Serializable/serialFilter/security.policy Mon Oct 21 16:52:21 2019 -0700 +++ b/test/jdk/java/io/Serializable/serialFilter/security.policy Tue Jan 07 03:41:33 2020 +0000 @@ -4,7 +4,7 @@ permission java.io.SerializablePermission "serialFilter"; // Permissions needed to run the test - permission java.util.PropertyPermission "*", "read"; + permission java.util.PropertyPermission "*", "read,write"; permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete"; permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; permission java.security.SecurityPermission "*";