Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/net/sf/freecol/common/io/FreeColXMLReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public FreeColXMLReader(InputStream inputStream) throws IOException {
super();

try {
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLInputFactory xif = newXMLInputFactory();
setParent(xif.createXMLStreamReader(inputStream, "UTF-8"));
} catch (XMLStreamException e) {
throw new IOException(e);
Expand All @@ -109,7 +109,7 @@ public FreeColXMLReader(Reader reader) throws IOException {
super();

try {
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLInputFactory xif = newXMLInputFactory();
setParent(xif.createXMLStreamReader(reader));
} catch (XMLStreamException e) {
throw new IOException(e);
Expand All @@ -118,6 +118,22 @@ public FreeColXMLReader(Reader reader) throws IOException {
this.readScope = ReadScope.NORMAL;
}

/**
* Create a new XMLInputFactory.
*
* Respond to CVE 2018-1000825.
*
* @return A new <code>XMLInputFactory</code>.
*/
private static XMLInputFactory newXMLInputFactory() {
XMLInputFactory xif = XMLInputFactory.newInstance();
// This disables DTDs entirely for that factory
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
// disable external entities
xif.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
return xif;
}


/**
* Should reads from this stream intern their objects into the
Expand Down
3 changes: 3 additions & 0 deletions src/net/sf/freecol/common/io/FreeColXMLWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.XMLConstants;

import net.sf.freecol.common.model.FreeColObject;
import net.sf.freecol.common.model.Location;
Expand Down Expand Up @@ -237,6 +238,8 @@ public void close() {
.toString()));
result = new StreamResult(this.outputWriter);
factory = TransformerFactory.newInstance();
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
transformer = factory.newTransformer();
for (int i = 0; i < indentProps.length; i += 2) {
transformer.setOutputProperty(indentProps[i],
Expand Down
3 changes: 3 additions & 0 deletions src/net/sf/freecol/common/model/FreeColObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.XMLConstants;

import net.sf.freecol.common.ObjectWithId;
import net.sf.freecol.common.io.FreeColXMLReader;
Expand Down Expand Up @@ -895,6 +896,8 @@ public static String readId(Element element) {
public void readFromXMLElement(Element element) {
try {
TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
Transformer xmlTransformer = factory.newTransformer();
StringWriter stringWriter = new StringWriter();
xmlTransformer.transform(new DOMSource(element),
Expand Down
3 changes: 3 additions & 0 deletions src/net/sf/freecol/common/networking/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.XMLConstants;

import net.sf.freecol.common.FreeColException;
import net.sf.freecol.common.debug.FreeColDebugger;
Expand Down Expand Up @@ -101,6 +102,8 @@ protected Connection(String name) {
Transformer myTransformer = null;
try {
TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
myTransformer = factory.newTransformer();
myTransformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes");
Expand Down
3 changes: 3 additions & 0 deletions src/net/sf/freecol/common/networking/DOMMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.XMLConstants;

import net.sf.freecol.common.io.FreeColXMLWriter;
import net.sf.freecol.common.debug.FreeColDebugger;
Expand Down Expand Up @@ -448,6 +449,8 @@ public static Element getChildElement(Element element, String tagName) {
public static String elementToString(Element element) {
try {
TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
Transformer xt = factory.newTransformer();
StringWriter sw = new StringWriter();
xt.transform(new DOMSource(element), new StreamResult(sw));
Expand Down
3 changes: 3 additions & 0 deletions src/net/sf/freecol/tools/GenerateDocumentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.XMLConstants;

import net.sf.freecol.common.i18n.Messages;
import net.sf.freecol.common.model.StringTemplate;
Expand Down Expand Up @@ -192,6 +193,8 @@ public static void generateDocumentation(String[] languages) {
Messages.loadMessageBundle(Messages.getLocale(languageCode));
try {
TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
Source xsl = new StreamSource(new File("doc", XSL));
Transformer stylesheet;
try {
Expand Down