Skip to content

Commit 2a8fd65

Browse files
committed
Fixed: Remove support for serialization and deserialization of custom Java objects in XmlSerializer for security reasons
1 parent 81f802f commit 2a8fd65

1 file changed

Lines changed: 8 additions & 26 deletions

File tree

framework/entity/src/main/java/org/apache/ofbiz/entity/serialize/XmlSerializer.java

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.FileNotFoundException;
2222
import java.io.IOException;
23-
import java.io.Serializable;
2423
import java.lang.ref.WeakReference;
2524
import java.math.BigDecimal;
2625
import java.math.RoundingMode;
@@ -48,10 +47,8 @@
4847
import javax.xml.parsers.ParserConfigurationException;
4948

5049
import org.apache.ofbiz.base.util.Debug;
51-
import org.apache.ofbiz.base.util.StringUtil;
5250
import org.apache.ofbiz.base.util.UtilGenerics;
5351
import org.apache.ofbiz.base.util.UtilMisc;
54-
import org.apache.ofbiz.base.util.UtilObject;
5552
import org.apache.ofbiz.base.util.UtilXml;
5653
import org.apache.ofbiz.entity.Delegator;
5754
import org.apache.ofbiz.entity.GenericPK;
@@ -259,18 +256,11 @@ public static Element serializeSingle(Object object, Document document) throws S
259256
}
260257

261258
public static Element serializeCustom(Object object, Document document) throws SerializeException {
262-
if (object instanceof Serializable) {
263-
byte[] objBytes = UtilObject.getBytes(object);
264-
if (objBytes == null) {
265-
throw new SerializeException("Unable to serialize object; null byte array returned");
266-
}
267-
String byteHex = StringUtil.toHexString(objBytes);
268-
Element element = document.createElement("cus-obj");
269-
// this is hex encoded so does not need to be in a CDATA block
270-
element.appendChild(document.createTextNode(byteHex));
271-
return element;
272-
}
273-
throw new SerializeException("Cannot serialize object of class " + object.getClass().getName());
259+
Debug.logError("Serialization of custom Java objects (cus-obj) is no longer supported. "
260+
+ "This feature has been removed for security reasons. Object class: "
261+
+ object.getClass().getName(), MODULE);
262+
throw new SerializeException("Serialization of custom Java objects is not supported. "
263+
+ "Object class: " + object.getClass().getName());
274264
}
275265

276266
public static Element makeElement(String elementName, Object value, Document document) {
@@ -467,17 +457,9 @@ public static Object deserializeSingle(Element element, Delegator delegator) thr
467457
public static Object deserializeCustom(Element element) throws SerializeException {
468458
String tagName = element.getLocalName();
469459
if ("cus-obj".equals(tagName)) {
470-
String value = UtilXml.elementValue(element);
471-
if (value != null) {
472-
byte[] valueBytes = StringUtil.fromHexString(value);
473-
if (valueBytes != null) {
474-
Object obj = UtilObject.getObject(valueBytes);
475-
if (obj != null) {
476-
return obj;
477-
}
478-
}
479-
}
480-
throw new SerializeException("Problem deserializing object from byte array + " + element.getLocalName());
460+
Debug.logError("Deserialization of cus-obj elements is no longer supported. "
461+
+ "This feature has been removed for security reasons.", MODULE);
462+
throw new SerializeException("Deserialization of cus-obj elements is not supported.");
481463
}
482464
throw new SerializeException("Cannot deserialize element named " + element.getLocalName());
483465
}

0 commit comments

Comments
 (0)