From 06623086e231ef094ec80b65a18b0fe8c8457bb7 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Thu, 19 Nov 2015 08:45:02 +0100 Subject: XML-Entity Injection in DataUrl Servlet gefixt --- .../java/at/gv/egiz/sl/util/SLMarschaller.java | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/gv/egiz') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java index 8f570ccc..e53fc230 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java @@ -32,6 +32,9 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,11 +72,30 @@ public class SLMarschaller { } public static Object unmarshal(InputStream is) throws JAXBException { - return unmarshaller.unmarshal(is); + XMLInputFactory xif = XMLInputFactory.newFactory(); + xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); + xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); + XMLStreamReader xmlStreamReader; + try { + xmlStreamReader = xif.createXMLStreamReader(is); + return unmarshaller.unmarshal(xmlStreamReader); + } catch (XMLStreamException e) { + throw new JAXBException(e); + } + } public static Object unmarshalFromString(String message) throws JAXBException { StringReader sr = new StringReader(message); - return unmarshaller.unmarshal(sr); + XMLInputFactory xif = XMLInputFactory.newFactory(); + xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); + xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); + XMLStreamReader xmlStreamReader; + try { + xmlStreamReader = xif.createXMLStreamReader(sr); + return unmarshaller.unmarshal(xmlStreamReader); + } catch (XMLStreamException e) { + throw new JAXBException(e); + } } } -- cgit v1.2.3