Skip to content

Commit 6c50e89

Browse files
author
Michael Dohmen
committed
Close a XML External Entity vulnerability
1 parent b334354 commit 6c50e89

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎src/main/java/org/oxt/toolbox/visualization/VisualizerImpl.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javax.xml.XMLConstants;
2525
import javax.xml.parsers.DocumentBuilder;
2626
import javax.xml.parsers.DocumentBuilderFactory;
27+
import javax.xml.parsers.ParserConfigurationException;
2728
import javax.xml.transform.OutputKeys;
2829
import javax.xml.transform.Transformer;
2930
import javax.xml.transform.TransformerException;
@@ -169,9 +170,9 @@ private StringWriter xsltTransformationFromFile(String inputFile, String xslPath
169170

170171
// Create an instance of the TransformerFactory
171172
TransformerFactory transfomerFactory = TransformerFactory.newInstance();
172-
173+
173174
// Obtain the XSLT transformer
174-
Transformer transformer = transfomerFactory.newTransformer(new StreamSource(xslPath));
175+
Transformer transformer = transfomerFactory.newTransformer(new StreamSource(xslPath));
175176
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
176177
StringWriter sw = new StringWriter();
177178
StreamResult result = new StreamResult(sw);
@@ -191,15 +192,17 @@ private void extracted() throws Exception {
191192
* @return
192193
* @throws TransformerException
193194
*/
194-
private StringWriter xsltTransformationFromStringWriter(StringWriter inputString, String xslPath) throws TransformerException {
195+
private StringWriter xsltTransformationFromStringWriter(StringWriter inputString, String xslPath) throws TransformerException, ParserConfigurationException {
195196
// second transformation
196197
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
197198
factory.setNamespaceAware(true);
199+
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
200+
198201
StreamSource source = new StreamSource(new StringReader(inputString.toString()));
199202

200203
// Create an instance of the TransformerFactory
201204
TransformerFactory transfomerFactory = TransformerFactory.newInstance();
202-
205+
203206
// Obtain the XSLT transformer
204207
Transformer transformer = transfomerFactory.newTransformer(new StreamSource(xslPath));
205208
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

0 commit comments

Comments
 (0)