简体   繁体   中英

How can we handle line feed in LDAP filters?

Whenever I use a filter as

(&(initials=abc)(title=manager)

)

this filter includes a line feed.

Executing this filter string reports an unbalanced parenthesis LDAP error.

Can any one please help out with this, how to handle line feeds? Are filters with line feeds supported in LDAP? Is this an invalid filter or can it be handled, maybe using some escaping techinique?

Are you accepting filters from user input and using that directly as input to LDAP queries? For security reasons, I would strongly advise against ever using unsanitized user input in this way, regardless of the target database. The correct approach would be to accept parameters from the user and then dynamically build filters using those parameters (note that you still need to take escaping rules into account to prevent possible injection attacks. This is why you should use a tool to build dynamnic filters, eg the filter support included in Spring LDAP).

That said, this particular problem should be pretty easy to solve: just do a String.replace for the characters you want to remove from the filter before using it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM