Skip to content

Commit

Permalink
Merge pull request #286 from arunvenmany-ibm/sast_issue_fix_1.0
Browse files Browse the repository at this point in the history
using access extenal dtd property as not allowed in xmleventreader of…
  • Loading branch information
arunvenmany-ibm authored Aug 7, 2024
2 parents 4329148 + 8da183d commit 9a55260
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.XMLEvent;
import javax.xml.transform.stream.StreamSource;

public class XmlReader {
private static final Logger LOGGER = Logger.getLogger(XmlReader.class.getName());
Expand Down Expand Up @@ -87,7 +88,7 @@ public static boolean hasServerRoot(File xmlFile) {
}

private static XMLInputFactory getXmlInputFactory() {
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLInputFactory factory = XMLInputFactory.newFactory();
try {
factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
Expand Down Expand Up @@ -119,7 +120,7 @@ public static Map<String, String> getElementValues(Path file, Set<String> elemen
XMLInputFactory factory = getXmlInputFactory();
XMLEventReader reader = null;
try {
reader = factory.createXMLEventReader(new FileInputStream(file.toFile()));
reader = factory.createXMLEventReader(new StreamSource(file.toFile()));
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (!event.isStartElement()) {
Expand All @@ -134,9 +135,7 @@ public static Map<String, String> getElementValues(Path file, Set<String> elemen
}
}
}
} catch (FileNotFoundException e) {
LOGGER.severe("Unable to access file "+ file.toFile().getName());
} catch (XMLStreamException e) {
} catch (XMLStreamException e) {
LOGGER.severe("Error received trying to read XML file " + file.toFile().getName() + " : "+e.getMessage());
} finally {
if (reader != null) {
Expand Down

0 comments on commit 9a55260

Please sign in to comment.