CVE-2016-15011: Improper Restriction of XML External Entity Reference (CWE-611)
value: A vulnerability classified as problematic was found in e-Contract dssp up to 1.3.1. Affected by this vulnerability is the function checkSignResponse of the file dssp-client/src/main/java/be/e_contract/dssp/client/SignResponseVerifier.java. The manipulation leads to xml external entity reference. Upgrading to version 1.3.2 is able to address this issue. The identifier of the patch is ec4238349691ec66dd30b416ec6eaab02d722302. It is recommended to upgrade the affected component. The identifier VDB-217549 was assigned to this vulnerability.
CWE description: The product processes an XML document that can contain XML entities with URIs that resolve to documents outside of the intended sphere of control, causing the product to embed incorrect documents into its output.
CVSS v3 base score: 9.8
Published: 2023-01-06T10:15Z
Repository: https://github.com/e-Contract/dssp
Language: Java
Files changed: dssp-client/src/main/java/be/e_contract/dssp/client/SignResponseVerifier.java, dssp-client/src/main/java/be/e_contract/dssp/client/metadata/DigitalSignatureServiceMetadata.java
Commit date: 2016-04-26 14:44:31 +0200
Commit message: 5342: fix XML external entity injection

Diff: diff --git a/dssp-client/src/main/java/be/e_contract/dssp/client/SignResponseVerifier.java b/dssp-client/src/main/java/be/e_contract/dssp/client/SignResponseVerifier.java
index 31f62e1..7b06e95 100644
--- a/dssp-client/src/main/java/be/e_contract/dssp/client/SignResponseVerifier.java
+++ b/dssp-client/src/main/java/be/e_contract/dssp/client/SignResponseVerifier.java
@@ -45,10 +45,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 import be.e_contract.dssp.client.exception.ClientRuntimeException;
 import be.e_contract.dssp.client.exception.SubjectNotAuthorizedException;
 import be.e_contract.dssp.client.exception.UserCancelException;
 import be.e_contract.dssp.client.impl.SecurityTokenKeySelector;
@@ -113,29 +114,36 @@ public class SignResponseVerifier {
 		try {
 			decodedSignResponseMessage = Base64.decode(signResponseMessage);
 		} catch (Base64DecodingException e) {
 			throw new SecurityException("no Base64");
 		}
+
+		// DOM parsing
+		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+		documentBuilderFactory.setNamespaceAware(true);
+		documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+		DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+		InputStream signResponseInputStream = new ByteArrayInputStream(decodedSignResponseMessage);
+		Document signResponseDocument;
+		try {
+			signResponseDocument = documentBuilder.parse(signResponseInputStream);
+		} catch (SAXParseException e) {
+			throw new SecurityException("no valid SignResponse XML");
+		}
+
 		// JAXB parsing
 		JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class,
 				be.e_contract.dssp.ws.jaxb.dss.async.ObjectFactory.class,
 				be.e_contract.dssp.ws.jaxb.wsa.ObjectFactory.class, be.e_contract.dssp.ws.jaxb.wsu.ObjectFactory.class);
 		Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
 		SignResponse signResponse;
 		try {
-			signResponse = (SignResponse) unmarshaller.unmarshal(new ByteArrayInputStream(decodedSignResponseMessage));
+			signResponse = (SignResponse) unmarshaller.unmarshal(signResponseDocument);
 		} catch (UnmarshalException e) {
 			throw new SecurityException("no valid SignResponse XML");
 		}
 
-		// DOM parsing
-		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
-		documentBuilderFactory.setNamespaceAware(true);
-		DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
-		InputStream signResponseInputStream = new ByteArrayInputStream(decodedSignResponseMessage);
-		Document signResponseDocument = documentBuilder.parse(signResponseInputStream);
-
 		// signature verification
 		NodeList signatureNodeList = signResponseDocument.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#",
 				"Signature");
 		if (signatureNodeList.getLength() != 1) {
 			throw new SecurityException("requires 1 ds:Signature element");
diff --git a/dssp-client/src/main/java/be/e_contract/dssp/client/metadata/DigitalSignatureServiceMetadata.java b/dssp-client/src/main/java/be/e_contract/dssp/client/metadata/DigitalSignatureServiceMetadata.java
index 8d023f0..099f2dc 100644
--- a/dssp-client/src/main/java/be/e_contract/dssp/client/metadata/DigitalSignatureServiceMetadata.java
+++ b/dssp-client/src/main/java/be/e_contract/dssp/client/metadata/DigitalSignatureServiceMetadata.java
@@ -26,10 +26,14 @@ import java.util.List;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
 
 import be.e_contract.dssp.ws.jaxb.dssp.DigitalSignatureServiceDescriptorType;
 import be.e_contract.dssp.ws.jaxb.metadata.EntityDescriptorType;
 import be.e_contract.dssp.ws.jaxb.metadata.KeyDescriptorType;
 import be.e_contract.dssp.ws.jaxb.metadata.KeyTypes;
@@ -44,10 +48,12 @@ import be.e_contract.dssp.ws.jaxb.xmldsig.X509DataType;
  *
  * @author Frank Cornelis
  */
 public class DigitalSignatureServiceMetadata implements Serializable {
 
+	private static final long serialVersionUID = 1L;
+
 	private final static QName _X509DataTypeX509Certificate_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#",
 			"X509Certificate");
 
 	private final String webServiceAddress;
 
@@ -61,14 +67,20 @@ public class DigitalSignatureServiceMetadata implements Serializable {
 	 * @param metadataLocation
 	 *            the URL of the DSS metadata document.
 	 * @throws Exception
 	 */
 	public DigitalSignatureServiceMetadata(String metadataLocation) throws Exception {
+		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+		documentBuilderFactory.setNamespaceAware(true);
+		documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+		DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+		Document document = documentBuilder.parse(new URL(metadataLocation).openStream());
+
 		JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
 		Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
 		JAXBElement<EntityDescriptorType> entityDescriptorElement = (JAXBElement<EntityDescriptorType>) unmarshaller
-				.unmarshal(new URL(metadataLocation));
+				.unmarshal(document);
 		EntityDescriptorType entityDescriptor = entityDescriptorElement.getValue();
 		List<RoleDescriptorType> roleDescriptors = entityDescriptor
 				.getRoleDescriptorOrIDPSSODescriptorOrSPSSODescriptor();
 		String webServiceAddress = null;
 		String browserPostAddress = null;

Vulnerable code: 			signResponse = (SignResponse) unmarshaller.unmarshal(new ByteArrayInputStream(decodedSignResponseMessage));
		// DOM parsing
		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
		documentBuilderFactory.setNamespaceAware(true);
		DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
		InputStream signResponseInputStream = new ByteArrayInputStream(decodedSignResponseMessage);
		Document signResponseDocument = documentBuilder.parse(signResponseInputStream);

				.unmarshal(new URL(metadataLocation));
Fixed code: import org.xml.sax.SAXParseException;

		// DOM parsing
		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
		documentBuilderFactory.setNamespaceAware(true);
		documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
		DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
		InputStream signResponseInputStream = new ByteArrayInputStream(decodedSignResponseMessage);
		Document signResponseDocument;
		try {
			signResponseDocument = documentBuilder.parse(signResponseInputStream);
		} catch (SAXParseException e) {
			throw new SecurityException("no valid SignResponse XML");
		}

			signResponse = (SignResponse) unmarshaller.unmarshal(signResponseDocument);
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
	private static final long serialVersionUID = 1L;

		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
		documentBuilderFactory.setNamespaceAware(true);
		documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
		DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
		Document document = documentBuilder.parse(new URL(metadataLocation).openStream());

				.unmarshal(document);