# Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection') (CWE-90) The product constructs all or part of an LDAP query using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended LDAP query. **Stack:** Go - Prevalence: 高 频繁被利用 - Impact: 高 3 条严重级别为高的规则 - Prevention: 已记录 3 个修复示例 **OWASP:** Injection (A03:2021-Injection) - #3 ## Description If user input is incorporated into an LDAP query without proper sanitization, an attacker can inject LDAP commands that could read or modify sensitive directory information. ## Prevention 基于 1 条 Shoulder 检测规则的 LDAP Injection 预防策略。 ### Go Use ldap.EscapeFilter to sanitize user input in LDAP queries ## Warning Signs - [HIGH] user input flowing to LDAP queries without proper escaping ## Consequences - 读取应用程序数据 - 修改应用程序数据 - 绕过保护机制 ## Mitigations - 尽可能使用参数化的 LDAP 查询 - 对 LDAP 查询中使用的所有用户输入进行转义或编码 - 根据可接受字符的允许列表对输入进行验证 ## Detection - Total rules: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Go (1 rules) - **LDAP Injection** [HIGH]: Detects user input flowing to LDAP queries without proper escaping. - Remediation: Use ldap.EscapeFilter to sanitize user input before including in LDAP filters. ```go escaped := ldap.EscapeFilter(username) filter := fmt.Sprintf("(uid=%s)", escaped) ``` Learn more: https://shoulder.dev/learn/go/cwe-90/ldap-injection