Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V5919. OWASP. Possible LDAP...
menu mobile close menu
Analyzing projects
Additional information
toggle menu Contents

V5919. OWASP. Possible LDAP injection. Potentially tainted data is used in an LDAP request.

Dec 01 2026

The analyzer has detected that potentially tainted data is used in an LDAP request. This could lead to an LDAP injection if the data is compromised.

LDAP injections fall under the following category in the OWASP Top 10 Application Security Risks 2025: A05:2025 Injection.

The example:

import(
  ....
  "github.com/go-ldap/ldap/v3"
)

func Search(w http.ResponseWriter, r *http.Request) {
  ....
  userId := r.FormValue("userId") 
  userPassword := r.FormValue("userPassword")

  filter := fmt.Sprintf(
    "(&(userId=%s)(userPassword=%s))", userId, userPassword
  )

  searchReq := ldap.NewSearchRequest(
    "dc=example,dc=com", 
    ...., 
    filter,
    ....,
  )

  result, err := LDAPConn.Search(searchReq)
  ....
}

In the example, the LDAP filter is created based on the user's ID and password, which come directly from an external source. The code is vulnerable because both values may contain special characters that change the filter's logic.

The developer expects the filter to look like this after substitution:

(&(userId=id123)(userPassword=p12345))

However, an attacker could turn it into:

(&(userId=*)(userRole=admin)(userPassword=*))

To do this, the attacker passes *)(role=admin string as userId and the * string as userPassword. The special character * used as an attribute value indicates a simple check to see if the attribute exists and has any value.

As a result, the filter bypasses both the user ID and password checks and grants access to the administrator's confidential data.

To reliably protect against the LDAP injection, escape special characters in data received from external sources before using them in a request. Use the ldap.EscapeFilter function:

func Search(w http.ResponseWriter, r *http.Request) {
  ....
  userId := ldap.EscapeFilter(r.FormValue("userId")) 
  userPassword := ldap.EscapeFilter(r.FormValue("userPassword"))
  ....
}

This diagnostic rule is classified as: