Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search unable to handle filter strings with special characters (parenthesis, plus, etc) in the DN #337

Open
AlaricWhitney opened this issue Aug 23, 2021 · 2 comments

Comments

@AlaricWhitney
Copy link

AlaricWhitney commented Aug 23, 2021

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.

@AlaricWhitney
Copy link
Author

I've submitted a PR to address the issues mentioned.

@vetinari
Copy link
Contributor

please check #338 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants