-
Notifications
You must be signed in to change notification settings - Fork 367
Description
Search
is unable to handle DN filter strings that contain special characters. Example:
searchRequest := NewSearchRequest(
"DC=example,DC=foo,DC=bar",
ScopeWholeSubtree, NeverDerefAliases, 0, 0, false,
`(&(objectCategory=group)(objectClass=group)(memberOf=CN=Main\+,OU=Groups,DC=example,DC=foo,DC=bar))`,
[]string{"dn", "cn"},
nil,
)
(error: LDAP Result Code 201 "Filter Compile Error": ldap: invalid characters for escape in filter: encoding/hex: invalid byte: U+002B '+')
Another example:
(&(objectCategory=group)(objectClass=group)(memberOf=CN=Main (Example),OU=Groups,DC=example,DC=foo,DC=bar))
(error: LDAP Result Code 201 "Filter Compile Error": ldap: finished compiling filter with extra at end: OU=Groups,DC=example,DC=foo,DC=bar))
I have discovered that the CompileFilter
does not process the filter string correctly, and requires the special characters to be converted to \xx hex values of the ascii characters first.
Example:
(&(objectCategory=group)(objectClass=group)(memberOf=CN=Main\+,OU=Groups,DC=example,DC=foo,DC=bar))
needs to be converted to (&(objectCategory=group)(objectClass=group)(memberOf=CN=Main\5c\2b,OU=Groups,DC=example,DC=foo,DC=bar))
(&(objectCategory=group)(objectClass=group)(memberOf=CN=Main (Example),OU=Groups,DC=example,DC=foo,DC=bar))
needs to be converted to (&(objectCategory=group)(objectClass=group)(memberOf=CN=Main \28Example\29,OU=Groups,DC=example,DC=foo,DC=bar))
I would suggest that a parsing method be added to convert special characters within a DN search string to hex values within the CompileFilter
method.