File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
aws-android-sdk-core/src/main/java/com/amazonaws Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -109,9 +109,10 @@ private static List<Region> internalParse(
109109 Document document ;
110110 try {
111111
112- DocumentBuilderFactory factory =
113- DocumentBuilderFactory .newInstance ();
114-
112+ DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
113+ factory .setFeature ("http://apache.org/xml/features/disallow-doctype-decl" , true );
114+ factory .setXIncludeAware (false );
115+ factory .setExpandEntityReferences (false );
115116 DocumentBuilder documentBuilder = factory .newDocumentBuilder ();
116117 document = documentBuilder .parse (input );
117118
Original file line number Diff line number Diff line change @@ -45,7 +45,25 @@ public class XpathUtils {
4545 /** Shared logger */
4646 private static Log log = LogFactory .getLog (XpathUtils .class );
4747
48- private static DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
48+ private static DocumentBuilderFactory factory = getDocumentBuilderFactory ();
49+
50+
51+ /**
52+ * Creates new documentbuilderfactory object
53+ * @return DocumentBuilderFactory.
54+ */
55+ private static DocumentBuilderFactory getDocumentBuilderFactory () {
56+ try {
57+ DocumentBuilderFactory dbf = DocumentBuilderFactory .newInstance ();
58+ dbf .setFeature ("http://apache.org/xml/features/disallow-doctype-decl" , true );
59+ dbf .setXIncludeAware (false ); // Default false for java 8. Disable XML Inclusions leading to SSRF - https://portswigger.net/web-security/xxe/lab-xinclude-attack
60+ dbf .setExpandEntityReferences (false );
61+ return dbf ;
62+ }
63+ catch (ParserConfigurationException exception ){
64+ return null ;
65+ }
66+ }
4967
5068 /**
5169 * InputStream to Document.
You can’t perform that action at this time.
0 commit comments