I am trying to develop some app and scanned my code using checkmarx and got issue under - LDAP injection in the below method.
Update(request.getparameter("userID"))
we are calling this method and using request.getparameter() to get the corresponding value, checkmarx is showing issue at request.getparameter("userID"),
Issue Description is "This element’s value then flows through the code without being properly sanitized or validated, and is eventually used in an LDAP query in method"
so following is one of the ways I tried
String userID = request.getparameter("userID");
if(userID == null && userID.isEmpty){
throw new ServletException();
}
else
Update(userID);
with the above changes also the issue is not resolved.
Any idea to resolve this issue ?
Seems like Checkmarx is correct in flagging your code as vulnerable to LDAP Injection.
What is LDAP Injection?
Quote taken from CWE-90: Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection')
How to mitigate?
Quote and example taken from LDAP Injection Vulnerability | CWE-90 Weakness | Exploitation and Remediation