Unsanitized user input in LDAP request
- Rule ID: java_lang_ldap_injection
- Languages: java
- Source: ldap_injection.yml
Description
Using unsanitized user input in an LDAP request can lead to LDAP injection, which is when attackers can modify the LDAP tree structure by injecting malicious input. It's crucial to ensure that data passed to an LDAP query is either not controlled by the user or is properly sanitized.
Remediations
- Do sanitize user input before including it in LDAP queries to prevent LDAP injection attacks.
public class Cls extends HttpServlet
{
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
{
String userID = request.getParameter("userID");
String sanitizedUserID = sanitize(userID); // Ensure sanitization method effectively neutralizes LDAP injection vectors
String filter = "(&(objectclass=person))(|(uid=" + sanitizedUserID + ")(street={0}))";
String base = "ou=users,ou=system";
Object[] filters = new Object[] {"First avenue"};
javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls();
dirContext.search(base, filter, filters, sc);
}
}
References
Associated CWE
OWASP Top 10
Configuration
To skip this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --skip-rule=java_lang_ldap_injection
To run only this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --only-rule=java_lang_ldap_injection