Requirement: When i pass the following request to my application,
1) How to do XML validation on such input xml which is risk
2) How to disable XXE in libxml2 i.e. should not parse the ENTITY field
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY foo SYSTEM "file:///etc/issue">
]><TRANSACTION>
<FUNCTION_TYPE>LINE_ITEM</FUNCTION_TYPE>
<COMMAND>ADD</COMMAND>
<COUNTER>3</COUNTER>
<MAC>qof2EtycqT9YMcmOfKowpyXVbRpgM/7rncS3liK4JOs=</MAC>
<MAC_LABEL>P_206</MAC_LABEL>
<RUNNING_TAX_AMOUNT>0.00</RUNNING_TAX_AMOUNT>
<RUNNING_TRANS_AMOUNT>1.00</RUNNING_TRANS_AMOUNT>
<LINE_ITEMS>
<MERCHANDISE>
<LINE_ITEM_ID>1</LINE_ITEM_ID>
<DESCRIPTION>&foo;</DESCRIPTION>
<QUANTITY>1</QUANTITY>
<UNIT_PRICE>5.00</UNIT_PRICE>
<EXTENDED_PRICE>5.00</EXTENDED_PRICE>
</MERCHANDISE>
</LINE_ITEMS>
</TRANSACTION>
I understand starting with libxml2 version 2.9, XXE has been disabled by default. But we are using 2.7.7 version currently.
According to this link XML_ENTITY_PROCESSING
The Enum xmlParserOption should not have the following options defined in libxml2:
XML_PARSE_NOENT: Expands entities and substitutes them with replacement text XML_PARSE_DTDLOAD: Load the external DTD
Till now i was using xmlParseMemory
function to parse an XML in-memory block and build a tree. This function does not take any parameter to set the xmlParserOption.
Then i Changed to xmlReadMemory
function which also does same thing as xmlParseMemory
function but takes different parameters.
docPtr = xmlReadMemory(szXMLMsg, iLen, "noname.xml", NULL, XML_PARSE_RECOVER);
Still I observe that ENTITY field is getting parsed. Could anyone help me? Please let me know if you need any more additional information.
Thank you for your time.
Regards
Praveen