Package edu.hm.hafner.analysis
Class SecureXmlParserFactory
- java.lang.Object
-
- edu.hm.hafner.analysis.SecureXmlParserFactory
-
public class SecureXmlParserFactory extends Object
Factory for XML Parsers that prevent XML External Entity attacks. Those attacks occur when untrusted XML input containing a reference to an external entity is processed by a weakly configured XML parser.- Author:
- Ullrich Hafner
- See Also:
- XML External Entity Prevention Cheat Sheet, XML parsers should not be vulnerable to XXE attacks
-
-
Constructor Summary
Constructors Constructor Description SecureXmlParserFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigureSaxParserFactory(SAXParserFactory factory)Configures aSAXParserFactoryso that it does not resolve external entities.DocumentBuildercreateDocumentBuilder()Creates a new instance of aDocumentBuilderthat does not resolve external entities.SAXParsercreateSaxParser()Creates a new instance of aSAXParserthat does not resolve external entities.TransformercreateTransformer()Creates aTransformerthat does not resolve external entities and stylesheets.XMLStreamReadercreateXmlStreamReader(Reader reader)Creates a new instance of aXMLStreamReaderthat does not resolve external entities.voidparse(Reader reader, Charset charset, DefaultHandler handler)Creates aSAXParserthat does not resolve external entities and parses the provided content with the given SAXDefaultHandler.DocumentreadDocument(Reader reader, Charset charset)Parses the provided content into aDocument.
-
-
-
Method Detail
-
createDocumentBuilder
public DocumentBuilder createDocumentBuilder()
Creates a new instance of aDocumentBuilderthat does not resolve external entities.- Returns:
- a new instance of a
DocumentBuilder
-
createSaxParser
public SAXParser createSaxParser()
Creates a new instance of aSAXParserthat does not resolve external entities.- Returns:
- a new instance of a
SAXParser
-
configureSaxParserFactory
public void configureSaxParserFactory(SAXParserFactory factory)
Configures aSAXParserFactoryso that it does not resolve external entities.- Parameters:
factory- the facotry to configure
-
createXmlStreamReader
public XMLStreamReader createXmlStreamReader(Reader reader)
Creates a new instance of aXMLStreamReaderthat does not resolve external entities.- Parameters:
reader- the reader to wrap- Returns:
- a new instance of a
XMLStreamReader
-
parse
public void parse(Reader reader, Charset charset, DefaultHandler handler)
Creates aSAXParserthat does not resolve external entities and parses the provided content with the given SAXDefaultHandler.- Parameters:
reader- the content that should be parsedcharset- the charset to use when reading the contenthandler- the SAX handler to parse the file- Throws:
ParsingException- if the file could not be parsed
-
readDocument
public Document readDocument(Reader reader, Charset charset)
Parses the provided content into aDocument.- Parameters:
reader- the content that should be parsedcharset- the charset to use when reading the content- Returns:
- the file content as document
- Throws:
ParsingException- if the file could not be parsed
-
createTransformer
public Transformer createTransformer()
Creates aTransformerthat does not resolve external entities and stylesheets.- Returns:
- the created
Transformer
-
-