
SSaha312872 (Community Member) asked a question.
Hi ,
I just got the error Deserialization of Untrusted Data (CWE ID 502) across all my application. The cod simply deserilze the json string to a class using ObjectMapper of Jackson data Bind. The version I have tried is 2.8.7 and 2.10.0
The description says : The application deserializes untrusted data without sufficiently verifying that the resulting data will be valid.
The code is as below .
public static <T> T convertJsonToObject(String json, Class<T> responseType) throws Exception {
if(json==null || responseType==null)
return null;
ObjectMapper objMapper= new ObjectMapper();
objMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objMapper.readValue(json,responseType);
}
I am not sure if there is anything changed on the Veracode side, Please suggest how to resolve these?
Thanks,
Sandeep
.png)
Hi @SSaha312872 (Community Member) ,
Starting with the September release of Veracode Static Analysis we've added support for reporting on potential unsafe deserialization with Jackson Databind through the ObjectMapper.readValue method.
As a number of recent CVEs show it is possible to use this library in a way that allows arbitrary code execution by an attacker:
* https://nvd.nist.gov/vuln/detail/CVE-2019-16942
* https://nvd.nist.gov/vuln/detail/CVE-2019-16943
* https://nvd.nist.gov/vuln/detail/CVE-2019-17267
Veracode Static Analysis currently reports any use of ObjectMapper.readValue that uses data from outside the application however this does not necessarily mean that this is automatically vulnerable to remote code execution.
The following blog by the Jackson maintainer has more information and is highly recommended: https://medium.com/@cowtowncoder/on-jackson-cves-dont-panic-here-is-what-you-need-to-know-54cd0d6e8062 .
In short though, in order to be vulnerable you must have the following:
We are investigating ways to be better able to detect 2, 3 and 4 but for how we recommend you manually verify this.
If, for example your serialisation destination does not rely on 'polymorphic typing' you might consider proposing a mitigation and having this mitigation reviewed by your security team (more information on this process here: https://help.veracode.com/reader/DGHxSJy3Gn3gtuSIN2jkRQ/~p4MSKOS8F8X8h0KwFTKoQ ).
Alternatively to remediate this flaw (have Veracode Static Analysis automatically close this flaw) you can investigate using alternative JSON libraries, this StackOverflow post had a good overview: https://stackoverflow.com/a/31743324/4512 .
In your specific case I would recommend going through the following:
Please let me know if you have any remaining questions or concerns.
Thank you,
Boy Baukema