Skip to content

Commit c9b121a

Browse files
committed
Disable external entities for StAX drivers.
1 parent 2b1568b commit c9b121a

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

xstream/src/java/com/thoughtworks/xstream/io/xml/SjsxpDriver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009, 2011, 2013, 2014 XStream Committers.
2+
* Copyright (C) 2009, 2011, 2013, 2014, 2015 XStream Committers.
33
* All rights reserved.
44
*
55
* The software in this package is published under the terms of the BSD
@@ -66,7 +66,9 @@ public SjsxpDriver(final XmlFriendlyNameCoder nameCoder) {
6666
protected XMLInputFactory createInputFactory() {
6767
Exception exception = null;
6868
try {
69-
return (XMLInputFactory)Class.forName("com.sun.xml.internal.stream.XMLInputFactoryImpl").newInstance();
69+
final XMLInputFactory instance = (XMLInputFactory)Class.forName("com.sun.xml.internal.stream.XMLInputFactoryImpl").newInstance();
70+
instance.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
71+
return instance;
7072
} catch (final InstantiationException e) {
7173
exception = e;
7274
} catch (final IllegalAccessException e) {

xstream/src/java/com/thoughtworks/xstream/io/xml/StandardStaxDriver.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright (C) 2013, 2014 XStream Committers.
2+
* Copyright (C) 2013, 2014, 2015 XStream Committers.
33
* All rights reserved.
44
*
55
* The software in this package is published under the terms of the BSD
66
* style license a copy of which has been included with this distribution in
77
* the LICENSE.txt file.
8-
*
8+
*
99
* Created on 27. July 2013 by Joerg Schaible
1010
*/
1111
package com.thoughtworks.xstream.io.xml;
@@ -26,7 +26,7 @@
2626
* <em>javax.xml.stream.XMLOutputFactory</em>, all implementations configured in <em>lib/stax.properties</em> or
2727
* registered with the Service API.
2828
* </p>
29-
*
29+
*
3030
* @author J&ouml;rg Schaible
3131
* @since 1.4.5
3232
*/
@@ -76,7 +76,9 @@ protected XMLInputFactory createInputFactory() {
7676
try {
7777
final Class<? extends XMLInputFactory> staxInputFactory = JVM.getStaxInputFactory();
7878
if (staxInputFactory != null) {
79-
return staxInputFactory.newInstance();
79+
final XMLInputFactory instance = staxInputFactory.newInstance();
80+
instance.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
81+
return instance;
8082
} else {
8183
throw new StreamException("Java runtime has no standard XMLInputFactory implementation.", exception);
8284
}

xstream/src/java/com/thoughtworks/xstream/io/xml/StaxDriver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
3-
* Copyright (C) 2006, 2007, 2009, 2011, 2013, 2014 XStream Committers.
3+
* Copyright (C) 2006, 2007, 2009, 2011, 2013, 2014, 2015 XStream Committers.
44
* All rights reserved.
55
*
66
* The software in this package is published under the terms of the BSD
@@ -248,7 +248,9 @@ protected XMLStreamReader createParser(final Source source) throws XMLStreamExce
248248
* @since 1.4
249249
*/
250250
protected XMLInputFactory createInputFactory() {
251-
return XMLInputFactory.newInstance();
251+
final XMLInputFactory instance = XMLInputFactory.newInstance();
252+
instance.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
253+
return instance;
252254
}
253255

254256
/**

xstream/src/java/com/thoughtworks/xstream/io/xml/WstxDriver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009, 2011, 2014 XStream Committers.
2+
* Copyright (C) 2009, 2011, 2014, 2015 XStream Committers.
33
* All rights reserved.
44
*
55
* The software in this package is published under the terms of the BSD
@@ -66,7 +66,9 @@ public WstxDriver(final NameCoder nameCoder) {
6666

6767
@Override
6868
protected XMLInputFactory createInputFactory() {
69-
return new WstxInputFactory();
69+
final XMLInputFactory instance = new WstxInputFactory();
70+
instance.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
71+
return instance;
7072
}
7173

7274
@Override

0 commit comments

Comments
 (0)