Skip to content

Commit ae6a2ec

Browse files
committed
Fixed security vulnerabilities identified by sonarqube
1 parent 0675859 commit ae6a2ec

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

jsoar-core/src/main/java/org/jsoar/kernel/io/xml/AbstractXmlFileToWme.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.File;
99
import java.io.IOException;
1010

11+
import javax.xml.XMLConstants;
1112
import javax.xml.parsers.DocumentBuilder;
1213
import javax.xml.parsers.DocumentBuilderFactory;
1314
import javax.xml.parsers.ParserConfigurationException;
@@ -125,6 +126,8 @@ protected Element getRootElement(File f)
125126
try
126127
{
127128
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
129+
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
130+
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
128131
DocumentBuilder db = dbf.newDocumentBuilder();
129132
Document dom = db.parse(f);
130133
return dom.getDocumentElement();

jsoar-core/src/main/java/org/jsoar/util/XmlTools.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.io.Reader;
1313
import java.io.StringReader;
1414

15+
import javax.xml.XMLConstants;
1516
import javax.xml.parsers.DocumentBuilder;
1617
import javax.xml.parsers.DocumentBuilderFactory;
1718
import javax.xml.parsers.ParserConfigurationException;
@@ -54,6 +55,8 @@ public class XmlTools
5455
public static DocumentBuilder createDocumentBuilder()
5556
{
5657
final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
58+
docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
59+
docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
5760
try
5861
{
5962
return docFactory.newDocumentBuilder();
@@ -99,6 +102,8 @@ public static void write(Node node, OutputStream out) throws IOException
99102
try
100103
{
101104
TransformerFactory xformFactory = TransformerFactory.newInstance();
105+
xformFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
106+
xformFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
102107
Transformer idTransform = xformFactory.newTransformer();
103108
idTransform.setOutputProperty(OutputKeys.VERSION, "1.0");
104109
idTransform.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

0 commit comments

Comments
 (0)