757831
From b1c0ca75ca38a7a8b50bfdfdf2c324169a6ddf02 Mon Sep 17 00:00:00 2001
757831
From: Michael Simacek <msimacek@redhat.com>
757831
Date: Mon, 19 Mar 2018 16:01:57 +0100
757831
Subject: [PATCH] Disallow EventData deserialization by default
757831
757831
---
757831
 .../src/main/java/org/slf4j/ext/EventData.java      | 21 +++++++++++++++------
757831
 1 file changed, 15 insertions(+), 6 deletions(-)
757831
757831
diff --git a/slf4j-ext/src/main/java/org/slf4j/ext/EventData.java b/slf4j-ext/src/main/java/org/slf4j/ext/EventData.java
757831
index dc5b502..fa5c125 100644
757831
--- a/slf4j-ext/src/main/java/org/slf4j/ext/EventData.java
757831
+++ b/slf4j-ext/src/main/java/org/slf4j/ext/EventData.java
757831
@@ -76,12 +76,21 @@ public class EventData implements Serializable {
757831
      */
757831
     @SuppressWarnings("unchecked")
757831
     public EventData(String xml) {
757831
-        ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
757831
-        try {
757831
-            XMLDecoder decoder = new XMLDecoder(bais);
757831
-            this.eventData = (Map<String, Object>) decoder.readObject();
757831
-        } catch (Exception e) {
757831
-            throw new EventException("Error decoding " + xml, e);
757831
+        if ("1".equals(System.getProperty("org.slf4j.ext.allowInsecureDeserialization"))) {
757831
+            ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
757831
+            try {
757831
+                XMLDecoder decoder = new XMLDecoder(bais);
757831
+                this.eventData = (Map<String, Object>) decoder.readObject();
757831
+            } catch (Exception e) {
757831
+                throw new EventException("Error decoding " + xml, e);
757831
+            }
757831
+        } else {
757831
+            throw new UnsupportedOperationException(
757831
+                    "Constructing EventData from XML is vulnerable to remote " +
757831
+                    "excution and is not allowed by default. If you're " +
757831
+                    "completely sure the source data is trusted, you can enable " +
757831
+                    "it by setting org.slf4j.ext.allowInsecureDeserialization " +
757831
+                    "JVM property to 1");
757831
         }
757831
     }
757831
 
757831
-- 
757831
2.14.3
757831