Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Date: Thu, 6 Jul 2023 18:28:07 -0400
From: Jan Schaumann <>
Subject: CVE-2023-28853: mastodon: Blind LDAP injection in login

(I have no affiliation with the project, but posting
this here because it seems to me that increasingly
non-packaged / GitHub distributed projects tend not to
send out announcements here.)

Mastodon allows configuration of LDAP for
authentication. The LDAP query made during login is
insecure and the attacker can perform LDAP injection
attack to leak arbitrary attributes from LDAP


Severity: 7.7/10


Affected versions: >= 2.5.0
Patched versions:  4.1.3, 4.0.5, 3.5.9


These are the default variables initiated if LDAP is

Lines 398 to 414 in 94cbd80

 if ENV['LDAP_ENABLED'] == 'true'
   config.ldap_authentication = true
   config.check_at_sign       = true
   config.ldap_host           = ENV.fetch('LDAP_HOST', 'localhost')
   config.ldap_port           = ENV.fetch('LDAP_PORT', 389).to_i
   config.ldap_method         = ENV.fetch('LDAP_METHOD', :simple_tls).to_sym
   config.ldap_base           = ENV.fetch('LDAP_BASE')
   config.ldap_bind_dn        = ENV.fetch('LDAP_BIND_DN')
   config.ldap_password       = ENV.fetch('LDAP_PASSWORD')
   config.ldap_uid            = ENV.fetch('LDAP_UID', 'cn')
   config.ldap_mail           = ENV.fetch('LDAP_MAIL', 'mail')
   config.ldap_tls_no_verify  = ENV['LDAP_TLS_NO_VERIFY'] == 'true'
   config.ldap_search_filter  = ENV.fetch('LDAP_SEARCH_FILTER', '(|(%{uid}=%{email})(%{mail}=%{email}))')
   config.ldap_uid_conversion_enabled  = ENV['LDAP_UID_CONVERSION_ENABLED'] == 'true'
   config.ldap_uid_conversion_search   = ENV.fetch('LDAP_UID_CONVERSION_SEARCH', '.,- ')
   config.ldap_uid_conversion_replace  = ENV.fetch('LDAP_UID_CONVERSION_REPLACE', '_')

Then, during the authentication, this line is

def authenticate_with_ldap(params = {})
   ldap   =
   filter = format(Devise.ldap_search_filter, uid: Devise.ldap_uid, mail: Devise.ldap_mail, email: params[:email])

   if (user_info = ldap.bind_as(base: Devise.ldap_base, filter: filter, password: params[:password]))

So this query is filled with untrusted input, namely
user's login:

User can inject LDAP query here. I didn't find a way
to login as arbitrary user because there are two
queries - one for fetching the user object and the
second one for authentication and the injection exists
in the first one.

However, the attacker can use blind injection
technique to exfiltrate one bit of information at a

1. Set up Mastodon and LDAP authentication
2. Create a user admin with any password. The information
   that we want to leak is the description=LDAP
   Administrator attribute but it can be any (I'm not yet
   able to leak password hash but I'm working on it).
3. Now, as the attacker, create a new account. In my case
   it's adminmalicious and password test.
4. Now when we try to log in with the login
   adminmalicious)(&(cn=admin)(description=A*) and
   password test. The full query will look like this:
   In plain english this query means "If the description
   of the user admin starts with A, the query will return
   both admin and adminmalicious". In my example, the
   admin description does not start with A so only
   adminmalicious will be returned from the LDAP query
   and we'll be logged in as adminmalicious.
5. When we try to log in with
   adminmalicious)(&(cn=admin)(description=L*), the query
   will return both admin and adminmalicious but admin
   will be first and the app will try to login to user
   admin with the password test which will fail and we
   will see Invalid E-mail address or password..

This way we've leaked one bit of information of other
user from the database. Of course, this is easy to
script and leak whole attribute values.

Powered by blists - more mailing lists

Please check out the Open Source Software Security Wiki, which is counterpart to this mailing list.

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.