Package edu.hm.hafner.analysis
Class SecureXmlParserFactory
java.lang.Object
edu.hm.hafner.analysis.SecureXmlParserFactory
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidConfigures aSAXParserFactoryso that it does not resolve external entities.Creates a new instance of aDocumentBuilderthat does not resolve external entities.Creates a new instance of aSAXParserthat does not resolve external entities.Creates aTransformerthat does not resolve external entities and stylesheets.createXmlStreamReader(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.readDocument(Reader reader, Charset charset) Parses the provided content into aDocument.
-
Constructor Details
-
SecureXmlParserFactory
public SecureXmlParserFactory()
-
-
Method Details
-
createDocumentBuilder
Creates a new instance of aDocumentBuilderthat does not resolve external entities.- Returns:
- a new instance of a
DocumentBuilder
-
createSaxParser
Creates a new instance of aSAXParserthat does not resolve external entities.- Returns:
- a new instance of a
SAXParser
-
configureSaxParserFactory
Configures aSAXParserFactoryso that it does not resolve external entities.- Parameters:
factory- the facotry to configure
-
createXmlStreamReader
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
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
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
Creates aTransformerthat does not resolve external entities and stylesheets.- Returns:
- the created
Transformer
-