Skip to content

Commit

Permalink
[JBEAP-19150] JSF trying to load DTD over the network
Browse files Browse the repository at this point in the history
  • Loading branch information
Moulali Shikalwadi committed Apr 30, 2020
1 parent e2d3e41 commit 249b7f3
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions jsf-ri/src/main/java/com/sun/faces/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import javax.servlet.ServletRegistration;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.validation.SchemaFactory;
Expand All @@ -99,6 +100,7 @@
import javax.xml.xpath.XPathFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.sun.faces.RIConstants;
import com.sun.faces.config.WebConfiguration;
Expand Down Expand Up @@ -1328,11 +1330,25 @@ public static String getFacesConfigXmlVersion(FacesContext facesContext) {
XPath xpath = factory.newXPath();
xpath.setNamespaceContext(new JavaeeNamespaceContext());
stream = url.openStream();
result = xpath.evaluate("string(/javaee:faces-config/@version)", new InputSource(stream));
DocumentBuilderFactory dbf = createDocumentBuilderFactory();
try {
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

} catch (ParserConfigurationException pce) {
}
dbf.setNamespaceAware(true);
dbf.setValidating(false);
dbf.setXIncludeAware(false);
dbf.setExpandEntityReferences(false);
result = xpath.evaluate("string(/javaee:faces-config/@version)",
dbf.newDocumentBuilder().parse(stream));
}
} catch (MalformedURLException mue) {
} catch (XPathExpressionException | IOException xpee) {
} finally {
} catch (Exception e) {
} finally {
if (stream != null) {
try {
stream.close();
Expand All @@ -1358,11 +1374,24 @@ public static String getWebXmlVersion(FacesContext facesContext) {
XPath xpath = factory.newXPath();
xpath.setNamespaceContext(new JavaeeNamespaceContext());
stream = url.openStream();
result = xpath.evaluate("string(/javaee:web-app/@version)", new InputSource(stream));
DocumentBuilderFactory dbf = createDocumentBuilderFactory();
try {
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

} catch (ParserConfigurationException e) {
}
dbf.setNamespaceAware(true);
dbf.setValidating(false);
dbf.setXIncludeAware(false);
dbf.setExpandEntityReferences(false);
result = xpath.evaluate("string(/javaee:web-app/@version)", dbf.newDocumentBuilder().parse(stream));
}
} catch (MalformedURLException mue) {
} catch (XPathExpressionException | IOException xpee) {
} finally {
} catch (Exception e) {
} finally {
if (stream != null) {
try {
stream.close();
Expand Down

0 comments on commit 249b7f3

Please sign in to comment.