Tristan reports: pdb_ldap User Deletion LDAP Filter Injection via Unescaped Username =================================================================== CVSS 3.1: 6.5 (AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N) CWE: CWE-90 (LDAP Injection) Auth: Low-privilege user (poisoner) + admin routine trigger Version: Samba 4.24.3 and prior, master (2026-06-25) File: source3/passdb/pdb_ldap.c, lines 5596-5600 Root Cause: The pdb_ldap passdb backend constructs the LDAP filter for user deletion without escaping the username. Every other username-based filter in the same file uses escape_ldap_string(). A poisoned uid attribute containing LDAP metacharacters can cause the deletion filter to match a different entry. // pdb_ldap.c:5596-5600 - VULNERABLE (no escape) filter = talloc_asprintf(mem_ctx, "(&(uid=%s)(objectclass=%s))", username, // NOT escaped LDAP_OBJ_POSIXACCOUNT); // Same file, lines 321, 2193, 5377 - CORRECT pattern filter = talloc_asprintf(..., "(&(uid=%s)...)", escape_ldap_string(mem_ctx, username)); Data Flow: Attacker sets uid attribute to "victim)(|(uid=target_admin)" -> admin deletes the attacker's account -> filter becomes "(&(uid=victim)(|(uid=target_admin))(objectclass=...))" -> LDAP matches the target_admin entry instead -> wrong entry deleted Impact: A low-privilege user poisons their own uid attribute with LDAP metacharacters. When an administrator subsequently deletes that account (routine deprovisioning, automated cleanup, or HR-triggered offboarding), the injected filter causes a different LDAP entry to be deleted instead -- potentially a domain admin or service account. The attacker is the low-privilege poisoner (PR:L); the admin action is a normal workflow event, not user interaction. The fix pattern (escape_ldap_string) is already used 3 times in the same file, confirming this is an oversight. Lab verified: code trace confirmed missing escape_ldap_string() call.
The LLM appears to have hallucinated this code, because it doesn’t actually exist. It is true though that we don’t escape the username in ldapsam_delete_user(), and we may as well do so.
(In reply to Jennifer Sutton from comment #1) Hi Jennifer, Thanks for looking into this. The code does exist, it's at line 5604-5608 of source3/passdb/pdb_ldap.c (master HEAD): ```c filter = talloc_asprintf(tmp_ctx, "(&(uid=%s)" "(objectClass="LDAP_OBJ_POSIXACCOUNT")" "(objectClass="LDAP_OBJ_SAMBASAMACCOUNT"))", pdb_get_username(sam_acct)); ``` My report had slightly simplified line numbers and variable names, but the issue is the same: `pdb_get_username(sam_acct)` is passed to the filter without `escape_ldap_string()`, unlike every other uid-based filter in the file (lines 321, 2196, 5385, etc.). Thanks for confirming the fix is warranted. Best, Tristan
Created attachment 19098 [details] patch for master
Created attachment 19099 [details] patch for master
(In reply to Jennifer Sutton from comment #4) Both patches look correct. Patch 1/2: Good cleanup -- get_ldap_filter() had a latent bug of its own (escaped variable computed but never used in the substitution). The inline wildcard filter for ldapsam_search_users is simpler. Patch 2/2: escape_ldap_string() before filter construction, matching the pattern at lines 321, 2196, 5385. Minor cosmetic: missing space before == on the NULL check ("escape_username== NULL"), but not worth a respin. Reviewed-by: Tristan Madani <tristan@talencesecurity.com> Also if you don't mind adding: Reported-by: Tristan Madani <tristan@talencesecurity.com>
Lets just deal with this on in public. We trust the LDAP data store in pdb_ldap, it is considered to be administratively maintained. This is a unix username, the total chaos that could be inflicted if this is allowed to be modified unconstrained is already far to great, this is not going to be the worst of it. Moving to the un-embargoed non-security issues for comment and with a hope that after un-emberago we can get a fix into the codebase.
(In reply to Andrew Bartlett from comment #6) Hi Andrew, I understand the trust model perspective, but I still consider this a security issue worth tracking. A few points: - The LDAP injection occurs on the client side -- Samba constructs a malformed filter from unsanitized input and sends it to the LDAP server. The question is not whether the data store is trusted, but whether Samba properly constructs its queries. The same file already calls escape_ldap_string() in three other places for the same reason. - The ldapsam backend supports external LDAP servers (AD, OpenLDAP, FreeIPA), where users may have limited write access to their own attributes depending on directory ACLs. The assumption that uid is exclusively administratively maintained does not hold in all deployments. - At CVSS 6.5 (AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N), this is above the typical noise threshold. Jennifer's patch is ready and reviewed -- I have no objection to making it public, but I would appreciate it being treated as a security fix with CVE assignment. Thanks.
(In reply to TristanInSec from comment #7) > The assumption that uid is exclusively administratively maintained does not hold in all deployments. I'm sorry, this would break all the security assumptions of any unix. In any case, the fastest route to a patch for users is to remove the embargo, go patches already written can go out.
[Bulk message on a number of bugs being made public at once] The embargo is being removed from this bug. That is not to say that the issue is not a real bug, but some things are better dealt with in public, where the normal process is both more available to external contributors and much, much more efficient. If you have a patch for this issue, please do contribute it via our normal GitLab process: https://wiki.samba.org/index.php/Contribute#Submitting_Patches_via_GitLab All patches to Samba must follow our copyright policy: https://www.samba.org/samba/devel/copyright-policy.html Thanks to all who report issues to Samba, we value your patience as we, along with the rest of the Open Source and Free Software communities, work though the reported issues.
This bug was referenced in samba master: 5d4c6c94ecdd01262f1c5539f0c5084c9d88e7df