Skip to content
Open
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
14 changes: 11 additions & 3 deletions authorizenet/apicontrollersbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys
import xml.dom.minidom
import requests
from lxml import objectify
from lxml import etree, objectify

from authorizenet.constants import constants
from authorizenet import apicontractsv1
Expand Down Expand Up @@ -142,21 +142,29 @@ def execute(self):
self._httpResponse.encoding = constants.response_encoding
self._httpResponse = self._httpResponse.text[3:] #strip BOM
self.afterexecute()

# Create secure XML parser to prevent XXE attacks
secure_parser = etree.XMLParser(
resolve_entities=False,
no_network=True,
dtd_validation=False,
load_dtd=False
)
try:
self._response = apicontractsv1.CreateFromDocument(self._httpResponse)
#objectify code
xmlResponse= self._response.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype())
xmlResponse = xmlResponse.replace(constants.nsNamespace1, b'')
xmlResponse = xmlResponse.replace(constants.nsNamespace2, b'')
self._mainObject = objectify.fromstring(xmlResponse)
self._mainObject = objectify.fromstring(xmlResponse, parser=secure_parser)

except Exception as objectifyexception:
anetLogger.error( 'Create Document Exception: %s, %s', type(objectifyexception), objectifyexception.args )
responseString = self._httpResponse

# removing encoding attribute as objectify fails if it is present
responseString = responseString.replace('encoding=\"utf-8\"', '')
self._mainObject = objectify.fromstring(responseString)
self._mainObject = objectify.fromstring(responseString, parser=secure_parser)
else:
if type(self.getresponseclass()) != type(self._mainObject):
if self._response.messages.resultCode == "Error":
Expand Down