0

I was trying to fix XEE issue and have tried other options but won't work. Would be great if there were any pointers.

Below is my code snippet..

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Source xmlSource = new DOMSource(feed);
Result outputTarget = new StreamResult(outputStream);
TransformerFactory.newInstance().newTransformer().transform(xmlSource,outputTarget);
is = new ByteArrayInputStream(outputStream.toByteArray());
SPoint
  • 582
  • 2
  • 10
  • Duplicate of https://stackoverflow.com/questions/35479324/prevent-xxe-fortify-issue-for-trasnformerfactory? – Dave Satch May 07 '19 at 07:17

1 Answers1

0

Have a look at OWASP XXE Prevention Cheat Sheet

based of what i see in your code, you should modifiy it like this :

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Source xmlSource = new DOMSource(feed);
Result outputTarget = new StreamResult(outputStream);

TransformerFactory tf = TransformerFactory.newInstance();
tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");

tf.newTransformer().transform(xmlSource,outputTarget);
is = new ByteArrayInputStream(outputStream.toByteArray());
SPoint
  • 582
  • 2
  • 10