Rahul Mallick
Rahul Mallick

Reputation: 89

How to handle large payload xml attacks when using gsoap library for parsing xml request in C?

I recently came across a scenario where during the parsing of a xml attribute, it's getting stuck during the parsing since the input is very large. The input is intentionally made large, so need to handle this scenario.

SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_in(struct soap *soap, const char *tag){
...
n = sizeof(soap->tag);
while ((c = soap_get(soap)) > 32)
{
   if (n > 1)
   {
     *s++ = (char)c;
     n--;
   }
}
...
}

The above snippet is a part of the function which is trying to read through the large input and getting stuck. It is defined in the gsoap libraries stdsoap2.cpp file. https://sourceforge.net/projects/gsoap2/

It was possible to handle the scenario by adding a counter variable and reading the input xml until that counter variable was less than of the value of predefine macro SOAP_TAGLEN (1024) which is for the maximum length of XML element tag/attribute name or host/path name + 1.

But that would cause modification to the gsoap library code itself. What I want to know is what is the recommended way of handling these bad payloads when using gsoap library ? Is there any specific function that can validate the input or will setting any specific member of the soap variable handle these conditions ? Currently haven't been able to understand why the large input check is not explicitly added in the library defined function itself. Any insights of handling these bad payloads and how to use the gsoap library for these scenarios would be helpful.

Upvotes: 0

Views: 74

Answers (0)

Related Questions