CVE-2020-36640 (published 2023-01-05T10:15Z)

A vulnerability, which was classified as problematic, was found in bonitasoft bonita-connector-webservice up to 1.3.0. This affects the function TransformerConfigurationException of the file src/main/java/org/bonitasoft/connectors/ws/SecureWSConnector.java. The manipulation leads to xml external entity reference. Upgrading to version 1.3.1 is able to address this issue. The patch is named a12ad691c05af19e9061d7949b6b828ce48815d5. It is recommended to upgrade the affected component. The associated identifier of this vulnerability is VDB-217443.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-611
cwe_name: Improper Restriction of XML External Entity Reference
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.
extended_description: 
            XML documents optionally contain a Document Type Definition (DTD), which, among other features, enables the definition of XML entities. It is possible to define an entity by providing a substitution string in the form of a URI. The XML parser can access the contents of this URI and embed these contents back into the XML document for further processing.
            By submitting an XML file that defines an external entity with a file:// URI, an attacker can cause the processing application to read the contents of a local file. For example, a URI such as "file:///c:/winnt/win.ini" designates (in Windows) the file C:\Winnt\win.ini, or file:///etc/passwd designates the password file in Unix-based systems. Using URIs with other schemes such as http://, the attacker can force the application to make outgoing requests to servers that the attacker cannot reach directly, which can be used to bypass firewall restrictions or hide the source of attacks such as port scanning.
            Once the content of the URI is read, it is fed back into the application that is processing the XML. This application may echo back the data (e.g. in an error message), thereby exposing the file contents.
         
         

Fix information:
repo_url: https://github.com/bonitasoft/bonita-connector-webservice
commit_details: repo_url: https://github.com/bonitasoft/bonita-connector-webservice
author: Adrien
author_date: 2020-10-12 14:22:59+02:00
msg: fix(vulnerabilities): fix XXE attacks vulnerabilities and other code smell (#17)

* Access to external entities and network access should always be
disable to avoid XXS attacks vulnerabilities.
* Log error properly
* refactor logger name to be compliant with java naming conventions
repository: repo_url: https://github.com/bonitasoft/bonita-connector-webservice
repo_name: bonitasoft/bonita-connector-webservice
description: Enables interactions in your Bonita processes with a SOAP Webservices.
repo_language: Java
owner: bonitasoft
file_changes: filename: SecureWSConnector.java
change_type: ModificationType.MODIFY
diff: @@ -29,6 +29,7 @@ import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.logging.Logger;
 
+import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -109,7 +110,7 @@ public class SecureWSConnector extends AbstractConnector {
 
     private static final String PROXY_PASSWORD = "proxyPassword";
 
-    private final Logger LOGGER = Logger.getLogger(this.getClass().getName());
+    private final Logger logger = Logger.getLogger(this.getClass().getName());
 
     private Transformer transformer;
 
@@ -181,20 +182,19 @@ public class SecureWSConnector extends AbstractConnector {
         }
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     protected void executeBusinessLogic() throws ConnectorException {
         configureProxy();
         final String serviceNS = (String) getInputParameter(SERVICE_NS);
-        LOGGER.info(SERVICE_NS + " " + serviceNS);
+        logger.info(SERVICE_NS + " " + serviceNS);
         final String serviceName = (String) getInputParameter(SERVICE_NAME);
-        LOGGER.info(SERVICE_NAME + " " + serviceName);
+        logger.info(SERVICE_NAME + " " + serviceName);
         final String portName = (String) getInputParameter(PORT_NAME);
-        LOGGER.info(PORT_NAME + " " + portName);
+        logger.info(PORT_NAME + " " + portName);
         final String binding = (String) getInputParameter(BINDING);
-        LOGGER.info(BINDING + " " + binding);
+        logger.info(BINDING + " " + binding);
         final String endpointAddress = (String) getInputParameter(ENDPOINT_ADDRESS);
-        LOGGER.info(ENDPOINT_ADDRESS + " " + endpointAddress);
+        logger.info(ENDPOINT_ADDRESS + " " + endpointAddress);
 
         final QName serviceQName = new QName(serviceNS, serviceName);
         final QName portQName = new QName(serviceNS, portName);
@@ -205,15 +205,15 @@ public class SecureWSConnector extends AbstractConnector {
         dispatch.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
         final Object authUserName = getInputParameter(USER_NAME);
         if (authUserName != null) {
-            LOGGER.info(USER_NAME + " " + authUserName);
+            logger.info(USER_NAME + " " + authUserName);
             dispatch.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, authUserName);
             final Object authPassword = getInputParameter(PASSWORD);
-            LOGGER.info(PASSWORD + " ********");
+            logger.info(PASSWORD + " ********");
             dispatch.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, authPassword);
         }
 
         final String soapAction = (String) getInputParameter(SOAP_ACTION);
-        LOGGER.info(SOAP_ACTION + " " + soapAction);
+        logger.info(SOAP_ACTION + " " + soapAction);
 
         if (soapAction != null) {
             dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
@@ -245,9 +245,9 @@ public class SecureWSConnector extends AbstractConnector {
         String initialEnvelope = (String) getInputParameter(ENVELOPE);
         String sanitizedEnvelope = sanitizeString(initialEnvelope);
         if (!Objects.equals(initialEnvelope, sanitizedEnvelope)) {
-            LOGGER.warning("Invalid XML characters have been detected in the envelope, they will be removed.");
+            logger.warning("Invalid XML characters have been detected in the envelope, they will be removed.");
         }
-        LOGGER.info(ENVELOPE + " " + sanitizedEnvelope);
+        logger.info(ENVELOPE + " " + sanitizedEnvelope);
 
         Boolean oneWayInvoke = (Boolean) getInputParameter(ONE_WAY_INVOKE);
         if (oneWayInvoke == null) {
@@ -268,9 +268,9 @@ public class SecureWSConnector extends AbstractConnector {
         restoreConfiguration();
 
         Boolean buildResponseDocumentEnvelope = (Boolean) getInputParameter(BUILD_RESPONSE_DOCUMENT_ENVELOPE);
-        LOGGER.info(BUILD_RESPONSE_DOCUMENT_ENVELOPE + " " + buildResponseDocumentEnvelope);
+        logger.info(BUILD_RESPONSE_DOCUMENT_ENVELOPE + " " + buildResponseDocumentEnvelope);
         Boolean buildResponseDocumentBody = (Boolean) getInputParameter(BUILD_RESPONSE_DOCUMENT_BODY);
-        LOGGER.info(BUILD_RESPONSE_DOCUMENT_BODY + " " + buildResponseDocumentBody);
+        logger.info(BUILD_RESPONSE_DOCUMENT_BODY + " " + buildResponseDocumentBody);
         if (buildResponseDocumentEnvelope == null) {
             buildResponseDocumentEnvelope = false;
         }
@@ -288,7 +288,7 @@ public class SecureWSConnector extends AbstractConnector {
         }
 
         Boolean printRequestAndResponse = (Boolean) getInputParameter(PRINT_REQUEST_AND_RESPONSE);
-        LOGGER.info(PRINT_REQUEST_AND_RESPONSE + " " + printRequestAndResponse);
+        logger.info(PRINT_REQUEST_AND_RESPONSE + " " + printRequestAndResponse);
         if (printRequestAndResponse == null) {
             printRequestAndResponse = false;
         }
@@ -323,30 +323,30 @@ public class SecureWSConnector extends AbstractConnector {
         if (host == null || host.isEmpty()) {
             return;
         }
-        LOGGER.info(PROXY_HOST + " " + host);
+        logger.info(PROXY_HOST + " " + host);
         final String protocol = (String) getInputParameter(PROXY_PROTOCOL);
-        LOGGER.info(PROXY_PROTOCOL + " " + protocol);
+        logger.info(PROXY_PROTOCOL + " " + protocol);
         final String port = (String) getInputParameter(PROXY_PORT);
-        LOGGER.info(PROXY_PORT + " " + port);
+        logger.info(PROXY_PORT + " " + port);
 
         if (SOCKS.equals(protocol)) {
             System.setProperty("socksProxyHost", host);
-            LOGGER.info("Setting environment variable: socksProxyHost=" + host);
+            logger.info("Setting environment variable: socksProxyHost=" + host);
             System.setProperty("socksProxyPort", port);
-            LOGGER.info("Setting environment variable: socksProxyPort=" + port);
+            logger.info("Setting environment variable: socksProxyPort=" + port);
         } else {
             final String hostKey = String.format("%s.proxyHost", protocol.toLowerCase());
             System.setProperty(hostKey, host);
-            LOGGER.info("Setting environment variable: " + hostKey + "=" + host);
+            logger.info("Setting environment variable: " + hostKey + "=" + host);
             final String portKey = String.format("%s.proxyPort", protocol.toLowerCase());
             System.setProperty(portKey, port);
-            LOGGER.info("Setting environment variable: " + portKey + "=" + port);
+            logger.info("Setting environment variable: " + portKey + "=" + port);
         }
 
         final String user = (String) getInputParameter(PROXY_USER);
-        LOGGER.info(PROXY_USER + " " + user);
+        logger.info(PROXY_USER + " " + user);
         final String password = (String) getInputParameter(PROXY_PASSWORD);
-        LOGGER.info(PROXY_PASSWORD + " ********");
+        logger.info(PROXY_PASSWORD + " ********");
         if (user != null && !user.isEmpty()) {
             Authenticator.setDefault(new Authenticator() {
 
@@ -392,7 +392,10 @@ public class SecureWSConnector extends AbstractConnector {
         Document responseDocumentBody = null;
         if (responseDocumentEnvelope != null) {
             try {
-                responseDocumentBody = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+                DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+                documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+                documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+                responseDocumentBody = documentBuilderFactory.newDocumentBuilder().newDocument();
             } catch (final ParserConfigurationException pce) {
                 throw new ConnectorException(pce);
             }
@@ -417,7 +420,7 @@ public class SecureWSConnector extends AbstractConnector {
                 getTransformer().transform(new DOMSource(responseDocumentBody), new StreamResult(System.err));
             }
         } catch (final TransformerException e) {
-            e.printStackTrace();
+            logger.severe(e.getMessage());
         }
     }
 
@@ -452,7 +455,10 @@ public class SecureWSConnector extends AbstractConnector {
 
     Transformer getTransformer() throws TransformerConfigurationException {
         if (transformer == null) {
-            transformer = TransformerFactory.newInstance().newTransformer();
+            TransformerFactory transformerFactory = TransformerFactory.newInstance();
+            transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+            transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
+            transformer = transformerFactory.newTransformer();
             transformer.setOutputProperty(OutputKeys.INDENT, "yes");
             transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
         }

programming_language: Java