From 85d87fbe4a8f1a3adc687735ae0ef9cb1a4e1a7f Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Thu, 12 Sep 2019 07:50:56 +0000 Subject: [PATCH] "Applied fix from trunk for revision: 1866834" ------------------------------------------------------------------------ r1866834 | jleroux | 2019-09-12 09:49:41 +0200 (jeu. 12 sept. 2019) | 8 lignes Improved: Improve ObjectInputStream class (OFBIZ-10837) Fixes CVE-2019-0189 Allows users to easily override the list of accepted objects by using the listOfSafeObjectsForInputStream property CVE-2019-0189 ------------------------------------------------------------------------ git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/branches/release17.12@1866836 13f79535-47bb-0310-9956-ffa450edef68 --- .../config/SafeObjectInputStream.properties | 27 +++++++++++++++++++ .../base/util/SafeObjectInputStream.java | 3 ++- .../apache/ofbiz/base/util/UtilObject.java | 18 ++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 framework/base/config/SafeObjectInputStream.properties diff --git a/framework/base/config/SafeObjectInputStream.properties b/framework/base/config/SafeObjectInputStream.properties new file mode 100644 index 0000000000..bdc5b4a425 --- /dev/null +++ b/framework/base/config/SafeObjectInputStream.properties @@ -0,0 +1,27 @@ +############################################################################### +# 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. +############################################################################### + +# Because of OFBIZ-10837 - Improve ObjectInputStream class. +# If you encounter a related issue (object not in the whitelist), +# you must provide a complete list of objects to pass to ObjectInputStream +# through ListOfSafeObjectsForInputStream property +# As an example, the a complete list of objects used by OFBiz OOTB is commented out by default here. +# You will need to add your objects/classes to this list. + +#listOfSafeObjectsForInputStream=byte\\\\[\\\\], foo, SerializationInjector, \\\\[Z,\\\\[B,\\\\[S,\\\\[I,\\\\[J,\\\\[F,\\\\[D,\\\\[C, java..*, sun.util.calendar..*, org.apache.ofbiz..* diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java index 6ddc959f3b..c48699a101 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java @@ -62,7 +62,8 @@ public class SafeObjectInputStream extends java.io.ObjectInputStream { if (!WHITELIST_PATTERN.matcher(classDesc.getName()).find()) { Debug.logWarning("***Incompatible class***: " + classDesc.getName() + ". Please see OFBIZ-10837. Report to dev ML if you use OFBiz without changes. " - + "Else add your class into UtilObject::getObjectException", "SafeObjectInputStream"); + + "Else follow https://s.apache.org/45war" + , "SafeObjectInputStream"); throw new ClassCastException("Incompatible class: " + classDesc.getName()); } diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java index 985d650dbc..a1c4bfe6c6 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java @@ -25,6 +25,7 @@ import java.io.InputStream; import java.io.ObjectOutputStream; import java.lang.reflect.Array; import java.util.Iterator; +import java.util.List; import java.util.ServiceLoader; import org.apache.ofbiz.base.lang.Factory; @@ -101,13 +102,22 @@ public final class UtilObject { /** Deserialize a byte array back to an object */ public static Object getObjectException(byte[] bytes) throws ClassNotFoundException, IOException { + String listOfSafeObjectsForInputStream = UtilProperties.getPropertyValue("SafeObjectInputStream", + "ListOfSafeObjectsForInputStream"); + List listOfSafeObjects = null; + if (UtilValidate.isNotEmpty(listOfSafeObjectsForInputStream)) { + listOfSafeObjects = java.util.Arrays.asList(listOfSafeObjectsForInputStream); + } else { + listOfSafeObjects = java.util.Arrays.asList("byte\\[\\]", "foo", "SerializationInjector", + "\\[Z","\\[B","\\[S","\\[I","\\[J","\\[F","\\[D","\\[C", + "java..*", "sun.util.calendar..*", "org.apache.ofbiz..*"); + } // "foo" and, "SerializationInjector" are used in UtilObjectTests::testGetObject + try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes); SafeObjectInputStream wois = new SafeObjectInputStream(bis, Thread.currentThread().getContextClassLoader(), - java.util.Arrays.asList("byte\\[\\]", "foo", "SerializationInjector", - "\\[Z","\\[B","\\[S","\\[I","\\[J","\\[F","\\[D","\\[C", - "java..*", "sun.util.calendar..*", "org.apache.ofbiz..*"));) { - // "foo" and, "SerializationInjector" are used in UtilObjectTests::testGetObject + listOfSafeObjects)) {; + return wois.readObject(); } }