是novell.directory.ldap c#库已经准备好防止ldap注入,还是我必须自己编码潜在的用户输入?

时间:2019-07-09 09:28:33

标签: c# ldap code-injection

im目前正在开发用于管理用户和资料的用户界面。作为数据存储,我必须使用ldap。我正在使用novell.directory.ldap library处理与ldap有关的事情。

我现在想知道这个库是否已经对其接收的参数进行了编码,例如在执行搜索时,或者如果我必须对潜在的用户输入进行编码,例如我自己将在以后的搜索查询中使用的用户名。

我已经尝试使用AntiXSSLibrary进行编码(我正在使用nuget包sicne,ldap编码不像库的其他部分一样包含在.net Framework本身中)及其{ {1}}和Encoder.LdapFilterEncode()方法。

这是我尝试编码时的代码:

Encoder.LdapDistinguishedNameEncode()
  • 如果我直接传递参数(=未编码),那么一切都会按预期进行。
  • 如果我通过了编码过滤器,我将在 public static LdapSearchResults PerformSearch(LdapConnection connection, string filter, string basedn) { string encodedFilter = Encoder.LdapFilterEncode(filter); string encodedBasedn = Encoder.LdapDistinguishedNameEncode(basedn); LdapSearchConstraints searchConstraints = new LdapSearchConstraints { BatchSize = 0 }; return connection.Search(encodedBasedn, LdapConnection.SCOPE_SUB, encodedFilter, null, false, searchConstraints); } 实例的LdapLocalException方法处收到一个Search()消息“ Filter Error”。
  • 如果我通过未编码的过滤器并通过了基于编码的过滤器,那么当我尝试访问搜索结果时,我会收到一条LdapConnection,消息为“无效的DN语法”。
  • 如果我通过未编码的过滤器并通过ecoded basedn(在这种情况下使用LdapException方法编码),一切都会正常运行。

因此,核心问题是:我是否需要担心ldap注入,还是图书馆已经在考虑这一威胁?不幸的是,我无法在文档中或通过搜索网络找到答案。

如果AntiXSSLibrary对我不起作用,如果我必须进行编码(我现在期望做些什么),在C#/。Net中为ldap的输入进行编码的最简单,最安全的方法是什么?

0 个答案:

没有答案