Package slash.common.helpers
Class SecureXml
java.lang.Object
slash.common.helpers.SecureXml
XML parsing hardened against XXE and entity expansion attacks.
JAXB's Unmarshaller.unmarshal(InputStream|Reader|File|URL|InputSource) creates its own
SAX parser which resolves external entities and external DTDs: a route file with a DOCTYPE can
read local files into the converted output or make the server open network connections.
Route formats (GPX, KML, RTZ, TCX, ...) never need a DOCTYPE, so it is rejected outright.
- Author:
- Christian Pesch
-
Method Summary
Modifier and TypeMethodDescriptionstatic jakarta.xml.bind.Unmarshallerharden(jakarta.xml.bind.Unmarshaller unmarshaller) Wraps the unmarshaller so everyunmarshal(..)overload that would make JAXB create its own (unhardened) parser is routed through a hardenedXMLReaderinstead.static XMLInputFactoryharden(XMLInputFactory factory) static SAXParserstatic SAXParserFactorystatic XMLReader
-
Method Details
-
newSaxParserFactory
public static SAXParserFactory newSaxParserFactory() throws ParserConfigurationException, SAXException -
newSaxParser
-
newXmlReader
-
harden
-
harden
public static jakarta.xml.bind.Unmarshaller harden(jakarta.xml.bind.Unmarshaller unmarshaller) Wraps the unmarshaller so everyunmarshal(..)overload that would make JAXB create its own (unhardened) parser is routed through a hardenedXMLReaderinstead.
-