An LDAP search filter is built by concatenating or interpolating values

tx0/csharp:ldap-filter-from-stringsrecommendedwarningsecurity/injectiondepth fastsecurity, cwe-90

What it finds

A directory filter assembled from input lets the input change the search: *)(uid=* matches every entry. Escaping the special characters of RFC 4515 in the inserted value keeps it data. The rule reports a DirectorySearcher created with such a filter, and assignments of such a filter to a Filter property.

From the rule's source, ldap_filter_from_strings.rs.

Example from the rule's tests
using System.DirectoryServices; class Directory{    void Find(DirectorySearcher searcher, string user)    {        searcher.Filter = "(uid=" + user + ")";tx0 reports: the LDAP filter is built from values        searcher.Filter = "(objectClass=user)";    }}
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/csharp:ldap-filter-from-strings" = "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/csharp:ldap-filter-from-strings] reason="..."

tx0 explain tx0/csharp:ldap-filter-from-strings shows the same in the terminal. Found a false positive? Report it.