An LDAP connection binds anonymously or with an empty password, so the directory is used without authentication

tx0/python:ldap-anonymous-bindrecommendedwarningsecurity/authn-authzdepth fastsecurity, cwe-287

What it finds

A simple bind without credentials, or with a user but an empty password, is treated by many servers as an anonymous bind that succeeds, so code that thinks it authenticated a user did not. Checked are simple_bind, simple_bind_s and bind_s of python-ldap, and ldap3.Connection without a user or with authentication=ANONYMOUS.

From the rule's source, ldap_anonymous_bind.rs.

Example from the rule's tests
import ldapimport ldap3 def login(user, password):    conn = ldap.initialize("ldap://example.com")    conn.simple_bind_s()tx0 reports: this bind sends no password    conn.simple_bind_s(user, "")tx0 reports: this bind sends no password    conn.simple_bind_s(user, password)    c = ldap3.Connection(server)tx0 reports: this connection binds without a user    d = ldap3.Connection(server, user, password)    return c, d
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:ldap-anonymous-bind" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:ldap-anonymous-bind] reason="..."

tx0 explain tx0/python:ldap-anonymous-bind shows the same in the terminal. Found a false positive? Report it.