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

Parentheses in search filter are not properly escaped. #1115

Open
niksite opened this issue Dec 7, 2023 · 0 comments
Open

Parentheses in search filter are not properly escaped. #1115

niksite opened this issue Dec 7, 2023 · 0 comments

Comments

@niksite
Copy link

niksite commented Dec 7, 2023

I am performing a fairly straightforward search for f"(cn={name})", where name is John (Jim) Doe.

When I make the request as follows, it works:

ldapsearch ... -s sub "cn=Joe \\\28Jim\\\29 Doe"   

Using ngrep, I can see that it sends the following (which is the correct LDAP encoding of parentheses):

...........�...cn..Joe \28Jim\29 Doe0.

However, when I use the .search(..., f"(cn={name})") query, it actually fails with the error message ldap3.core.exceptions.LDAPInvalidFilterError: malformed filter.

If I use name = escape_filter_chars(name), the LDAP server returns the following error:

{'result': 53, 'description': 'unwillingToPerform', 'dn': '', 'message': 'Invalid Filter jim', 'referrals': None, 'type': 'searchResDone'}

Using ngrep, I can see that the query is as follows (which is not correctly encoded for LDAP).

...........�...cn..Joe (Jim) Doe0.

If I use the ridiculous name = escape_filter_chars(escape_filter_chars(name)), then it finally works:

...........�...cn..Joe \28Jim\29 Doe0.

It seems that the escaped data is being unescaped at some point before it is sent.

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

No branches or pull requests

1 participant