snipe-it icon indicating copy to clipboard operation
snipe-it copied to clipboard

LDAP filter bug/solution

Open markkeller opened this issue 9 years ago • 5 comments

Hello. This is in reference to issue #3314. I experienced the same problem as @JarrodR87 in that the LDAP authentication methods did not appear to apply the search filter that was indicated in the settings. I believe I have a fix for this problem.

Before I get any further, let me give you some background:

I work for a large institution which uses Active Directory for IAM. We have tens of thousands of users. The department I work for has a delegated OU, in which we created a security group for asset managers. I was able to get LDAP set up and configured seemingly correctly with an appropriate filter set, but it would not filter out users when they authenticated through the login page. Meaning any of the users in our AD forest could log into the system and create an account, regardless of group membership. Curiously, I found that if I ran a bulk import through LDAP, it would correctly grab all users which had membership in the security group.

I dove into the code in app/Models/Ldap.php (commit e7ac860), and I saw that the only filter being applied (line 103) was:

$filterQuery = $settings->ldap_auth_filter_query . $username;

I modified this to include the full filter and it worked like a charm:

$filterQuery = "(" . $settings->ldap_filter . "(" . $settings->ldap_auth_filter_query . $username . "))";

markkeller avatar Jul 07 '17 20:07 markkeller

Just wanted to say, this patch is awesome @markkeller . I've validated with the latest version of Snipe-IT, this patch is still needed.

Currently it's on line 97.

$ diff Ldap.php-old Ldap.php
97c97
<         $filterQuery = $settings->ldap_auth_filter_query . $username;
---
>         $filterQuery = '(' . $settings->ldap_filter . '(' . $settings->ldap_auth_filter_query . $username . '))';

This allows the filter to work as expected.

@snipe would it be possible to include this in the code?

sylikc avatar Dec 10 '17 05:12 sylikc

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!

stale[bot] avatar Feb 08 '18 08:02 stale[bot]

The above patch fixed my issue. It's still not in the latest code, however.

Alexithymia2014 avatar Mar 19 '18 20:03 Alexithymia2014

My concern would be that LDAP is working fine for many people, and implementing this change could break it for others.

snipe avatar Mar 19 '18 21:03 snipe

Thanks for the quick response! Will this at all be looked at in the future? I'll just keep the patched version myself and update whenever I update snipe-it.

Alexithymia2014 avatar Mar 19 '18 22:03 Alexithymia2014