Unsanitized user input in LDAP request

Overview

  • Rule ID: java_lang_ldap_injection

  • Applicable Languages: Java

  • Weakness ID: CWE-90

Description

Utilizing unsanitized user input in an LDAP request can result in LDAP injection, where attackers manipulate the LDAP tree structure by injecting malicious input. It's essential to verify that data supplied to an LDAP query is either not user-controlled or undergoes thorough sanitization.

Remediation Guidelines

  • 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

Configuration

To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our SAST TOOL

Last updated