flask-ldap3-login icon indicating copy to clipboard operation
flask-ldap3-login copied to clipboard

get_user_groups() malforms CN causing false query results and empty user_groups

Open bandwiches opened this issue 3 years ago • 1 comments

Issue

Long story short, I'm using LDAP3LoginManager.authenticate() to authenticate users. Bind, user search, and user authentication all work successfully, but the resulting user_groups is an empty list.

The issue seems to stem from this line:

https://github.com/nickw444/flask-ldap3-login/blob/3e77aeb680e360c12167244ba0611b0dcef9e283/flask_ldap3_login/init.py#L550

Verification

Logs

Directly binding a connection to a server with user:'CN=LastName\, FirstName,...'
Authentication was successful for user 'username'
Searching for groups for specific user with filter '(&(objectclass=group)(member=CN=LastName\5c, FirstName...)'

Troubleshooting

  • Opened a python shell importing python-ldap3
  • Tested search query using the filter provided by flask_ldap3_login logs
    • This failed to return any results
  • Tested search query removing the 5c
    • Success

bandwiches avatar Apr 25 '21 03:04 bandwiches

This doesn't feel quite right to me. A couple questions:

Can you try again in the python shell double-checking that you've escaped the backslash in the string literal? i.e. try filter = '(&(objectclass=group)(member=CN=LastName\\5c, FirstName...)' If you just paste the filter into a shell, that \5c will turn into an ASCII ENQ byte followed by a literal c, which can't possibly work. (Those debug logs don't use the repr of the strings, they're just surrounded by literal single quote characters. I might argue that that's a bug on its own, but that's off topic for this issue.)

Assuming the issue still manifests with that string-escaping in place, can you let us know what LDAP server you're interacting with?

gmacon avatar Apr 28 '21 01:04 gmacon