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