View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v2.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.net.server;
15  
16  import java.io.IOException;
17  import java.io.InputStream;
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import ch.qos.logback.classic.LoggerContext;
22  import org.slf4j.helpers.BasicMarker;
23  
24  import ch.qos.logback.classic.Level;
25  import ch.qos.logback.classic.Logger;
26  import ch.qos.logback.classic.spi.ClassPackagingData;
27  import ch.qos.logback.classic.spi.IThrowableProxy;
28  import ch.qos.logback.classic.spi.LoggerContextVO;
29  import ch.qos.logback.classic.spi.LoggerRemoteView;
30  import ch.qos.logback.classic.spi.LoggingEventVO;
31  import ch.qos.logback.classic.spi.StackTraceElementProxy;
32  import ch.qos.logback.classic.spi.ThrowableProxy;
33  import ch.qos.logback.classic.spi.ThrowableProxyVO;
34  import ch.qos.logback.core.net.HardenedObjectInputStream;
35  
36  public class HardenedLoggingEventInputStream extends HardenedObjectInputStream {
37  
38      static final String ARRAY_PREFIX = "[L";
39  
40      static public List<String> getWhilelist() {
41          List<String> whitelist = new ArrayList<String>();
42          whitelist.add(LoggingEventVO.class.getName());
43          whitelist.add(LoggerContextVO.class.getName());
44          whitelist.add(LoggerRemoteView.class.getName());
45          whitelist.add(ThrowableProxyVO.class.getName());
46          whitelist.add(BasicMarker.class.getName());
47          whitelist.add(Level.class.getName());
48          whitelist.add(Logger.class.getName());
49          whitelist.add(StackTraceElement.class.getName());
50          whitelist.add(StackTraceElement[].class.getName());
51          whitelist.add(ThrowableProxy.class.getName());
52          whitelist.add(ThrowableProxy[].class.getName());
53          whitelist.add(IThrowableProxy.class.getName());
54          whitelist.add(IThrowableProxy[].class.getName());
55          whitelist.add(StackTraceElementProxy.class.getName());
56          whitelist.add(StackTraceElementProxy[].class.getName());
57          whitelist.add(ClassPackagingData.class.getName());
58  
59          return whitelist;
60      }
61  
62      public HardenedLoggingEventInputStream(LoggerContext loggerContext, InputStream is) throws IOException {
63          super(loggerContext, is, getWhilelist());
64      }
65  
66      public HardenedLoggingEventInputStream(LoggerContext loggerContext, InputStream is, List<String> additionalAuthorizedClasses)
67              throws IOException {
68          this(loggerContext, is);
69          super.addToWhitelist(additionalAuthorizedClasses);
70      }
71  }