-
Notifications
You must be signed in to change notification settings - Fork 13.5k
fix: the ldap manager passes a username variable lab... in Manager.ts #40400
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
Open
orbisai0security
wants to merge
1
commit into
RocketChat:develop
Choose a base branch
from
orbisai0security:fix-ldap-filter-escape-v001
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix only patches
testSearch; the actual login paths (findUser,findAuthenticatedUser) remain unmodified.The additional
.replace()escaping is applied exclusively at line 118 (testSearch), which is a diagnostic utility method. The two production-critical paths —findUser(line 220) andfindAuthenticatedUser(line 254) — still use onlyldapEscape.filter${username}`` with no additional escaping. If the intention is to harden against LDAP injection via the username field, both of those methods must receive the same treatment; otherwise the fix provides zero protection on any actual authentication flow.🔧 Apply the same escaping to all three call sites
private static async findUser(ldap: LDAPConnection, username: string, password: string): Promise<ILDAPEntry | undefined> { - const escapedUsername = ldapEscape.filter`${username}`; + const escapedUsername = ldapEscape.filter`${username}`.replace(/[/+<>;=]/g, (c) => `\\${c.charCodeAt(0).toString(16).padStart(2, '0')}`);private static async findAuthenticatedUser(ldap: LDAPConnection, username: string): Promise<ILDAPEntry | undefined> { - const escapedUsername = ldapEscape.filter`${username}`; + const escapedUsername = ldapEscape.filter`${username}`.replace(/[/+<>;=]/g, (c) => `\\${c.charCodeAt(0).toString(16).padStart(2, '0')}`);Alternatively, extract to a shared helper to avoid triplicated logic:
🤖 Prompt for AI Agents
🧩 Analysis chain
🌐 Web query:
What characters does the npm package ldap-escape version 2.0.6 escape when using the filter tagged template function?💡 Result:
The npm package ldap-escape version 2.0.6, when using the filter tagged template function (ldapEscape.filter), escapes the following characters for LDAP search filters:
*(to\2A),((to\28),)(to\29),\(to\5C), and NUL (null byte, to\00) [1][2][3][4]. This is explicitly stated in the package's README and npm registry documentation, which apply to version 2.0.6 (published April 13, 2022) [2]. These follow Active Directory LDAP filter escaping rules per RFC 4515 standards [5].Citations:
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 151
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 110
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 48
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 1524
🏁 Script executed:
# Get the full Manager.ts file and see line 118 and surrounding context wc -l ./apps/meteor/server/lib/ldap/Manager.tsRepository: RocketChat/Rocket.Chat
Length of output: 111
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 2056
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 1488
Remove the extra
.replace()call or apply consistent escaping across all methods.The additional escaping in
testSearchtargets RFC 4514 DN special characters (/,+,<,>,;,=), not RFC 4515 filter special characters.ldapEscape.filteralready handles all RFC 4515 mandatory escapes (*,(,),\, NUL); the extra.replace()provides no security benefit in the filter assertion value context where the username is embedded as(userField=${username}).More critically, this creates an inconsistency:
testSearchapplies double-encoding whilefindUserandfindAuthenticatedUseruse only the standardldapEscape.filter. A username containing any of these characters (common in some AD environments) will fail intestSearchwith "User not found" but succeed in the unpatched methods, causing confusing behavior.Either remove the extra
.replace()to align withfindUserandfindAuthenticatedUser, or apply the same escaping consistently across all three methods.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orbisai0security can you address code review comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.