TECHNOLOGY

LDAP filter values and distinguished names need different escaping

In this article
THE QUICK TAKE

Select the encoder for the exact LDAP grammar position, keep the query structure application-controlled and reject ambiguous directory matches before granting access.

Keep a display name from becoming a query

An enterprise assistant resolves a requested person against the corporate directory before assigning a document-review task. A helper described as LDAP escaping is reused both for a distinguished name and for a search filter. Those positions have different grammars. A value passing through several representations needs encoding at each relevant boundary, not a single label declaring it safe forever. A name containing punctuation can change which entries match instead of being treated literally. This is an identity-resolution defect even when the directory connection itself is authenticated and encrypted.

Identify the filter value position

The filter representation standard distinguishes assertion values from operators and describes escaping for special octets. An asterisk inside a value can otherwise participate in substring or presence syntax. Prefer a directory library that builds a filter from separately supplied values. If string construction is unavoidable, use the library’s assertion-value encoder for that exact position, not general URL encoding and not the encoder intended for a directory entry name.

Handle distinguished names as another type

The DN representation standard defines its own string grammar and handling of characters such as commas, plus signs and boundary spaces. A DN value correctly encoded for that grammar is not automatically an escaped filter value. The standard also does not define a canonical string form for deciding DN equality. Avoid ad hoc lowercase-and-trim comparisons when identity decisions require directory semantics; retain the validated directory entry identity returned through the supported interface.

Control more than the inserted value

Keep attribute names, search base, scope and filter operators under application control. Encoding an assertion value cannot protect a caller-selected search base or an unrestricted attribute selector. Bind the authorized tenant or organization to the intended directory boundary before searching. If several entries match a display name, require a supported disambiguation step rather than selecting the first result. A larger result set is not permission to choose a convenient identity for an external action.

Test literal names and ambiguous matches

Build harmless directory fixtures with punctuation, leading or trailing spaces and a literal wildcard character. Compare the intended value with the server-observed filter and returned entry identity. Also include duplicate display names and an attempted search-base substitution. Acceptance requires literal matching under the chosen filter semantics and explicit handling of ambiguity. No production directory was queried or modified here. Test fixture strings must remain distinct from operational credentials and real employee data.

Stop the claim at identity resolution

Caller-history trust explains why application structure should not come from untrusted input. Reproducible stacks help preserve the directory library and parsing behavior used for the check. Correctly resolving an entry does not prove that the person remains employed or may access the document. Apply current authorization after resolution. Record the entry identity and decision evidence without retaining unnecessary private directory attributes in the assistant’s conversation history.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles