You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(1372): LDAP Authentication vs Filter Clarity (#1797)
* fix(1372): Add secure Java authentication example to LDAP Injection Prevention Cheat Sheet
* fix: Update RFC links
- Update RFC links for LDAP encoding functions in the LDAP Injection Prevention Cheat Sheet
* fix(1372): Revision for PR feedback
- LDAPS: Switched from ldap://example.com:389 to ldaps://example.com:636 for secure simple authentication.
- Anonymous Search: Opened a context with "none" authentication to look up the DN by uid.
- Flexible Filter: The search filter now only requires uid, no assumption about objectClass=person, which makes it work for service accounts or other directory objects.
- Resource Safety: Explicitly closing the anonymous context after the search.
* fix: Update Java escaping examples and remove insecure patterns
* Update LDAP_Injection_Prevention_Cheat_Sheet.md
Co-authored-by: Copilot <[email protected]>
---------
Co-authored-by: Copilot <[email protected]>
Copy file name to clipboardExpand all lines: cheatsheets/LDAP_Injection_Prevention_Cheat_Sheet.md
+5-6Lines changed: 5 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,24 +80,23 @@ For more information on search filter escaping visit [RFC4515](https://datatrack
80
80
#### Safe Java Escaping Example
81
81
82
82
The following solution uses an allowlist to sanitize user input so that the filter string contains only valid characters. In this code, userSN may contain
83
-
only letters and spaces, whereas a password may contain only alphanumeric characters:
83
+
only letters and spaces.
84
84
85
85
```java
86
86
// String userSN = "Sherlock Holmes"; // Valid
87
-
// String userPassword = "secret2"; // Valid
88
87
// ... beginning of LDAPInjection.searchRecord()...
89
88
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
90
89
String base ="dc=example,dc=com";
91
90
92
-
if (!userSN.matches("[\\w\\s]*")||!userPassword.matches("[\\w]*")) {
// ... remainder of LDAPInjection.searchRecord()...
98
97
```
99
98
100
-
When a database field such as a password must include special characters, it is critical to ensure that the authentic data is stored in sanitized form in the
99
+
When a database field must include special characters, it is critical to ensure that the authentic data is stored in sanitized form in the
101
100
database and also that any user input is normalized before the validation or comparison takes place. Using characters that have special meanings in JNDI
102
101
and LDAP in the absence of a comprehensive normalization and allowlisting-based routine is discouraged. Special characters must be transformed to
103
102
sanitized, safe values before they are added to the allowlist expression against which input will be validated. Likewise, normalization of user input should
[.NET AntiXSS](https://blogs.msdn.microsoft.com/securitytools/2010/09/30/antixss-4-0-released/) (now the Encoder class) has LDAP encoding functions including `Encoder.LdapFilterEncode(string)`, `Encoder.LdapDistinguishedNameEncode(string)` and `Encoder.LdapDistinguishedNameEncode(string, bool, bool)`.
130
129
131
-
`Encoder.LdapFilterEncode` encodes input according to [RFC4515](https://tools.ietf.org/search/rfc4515) where unsafe values are converted to `\XX` where `XX` is the representation of the unsafe character.
130
+
`Encoder.LdapFilterEncode` encodes input according to [RFC4515](https://datatracker.ietf.org/doc/html/rfc4515) where unsafe values are converted to `\XX` where `XX` is the representation of the unsafe character.
132
131
133
132
`Encoder.LdapDistinguishedNameEncode` encodes input according to [RFC2253](https://tools.ietf.org/html/rfc2253) where unsafe characters are converted to `#XX` where `XX` is the representation of the unsafe character and the comma, plus, quote, slash, less than and great than signs are escaped using slash notation (`\X`). In addition to this a space or octothorpe (`#`) at the beginning of the input string is `\` escaped as is a space at the end of a string.
0 commit comments