[#4592] Improper Restriction of XML External Entity References ('XXE') in XMLasDOMBinding
This commit is contained in:
parent
c52c061b3a
commit
567de0a66e
@ -47,6 +47,7 @@ import java.sql.SQLXML;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
@ -159,11 +160,33 @@ public class XMLasDOMBinding extends AbstractVarcharBinding<Node> {
|
||||
try {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// [#4592] FIX START: Prevent OWASP attack vectors
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
}
|
||||
catch (ParserConfigurationException ignore) {}
|
||||
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
}
|
||||
catch (ParserConfigurationException ignore) {}
|
||||
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
}
|
||||
catch (ParserConfigurationException ignore) {}
|
||||
|
||||
factory.setXIncludeAware(false);
|
||||
factory.setExpandEntityReferences(false);
|
||||
// [#4592] FIX END
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
// [#9] [#107] In order to take advantage of namespace-related DOM
|
||||
// features, the internal builder should be namespace-aware
|
||||
factory.setNamespaceAware(true);
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
return builder;
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user