Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vulnerability in communication with LDAP connector #2635

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -70,7 +70,7 @@ public List<Map<String,String>> findSubjectsLogins(String searchString, int maxR
if (query == null) {
throw new InternalErrorException("query attributes is required");
}
query = query.replaceAll("\\?", searchString);
query = query.replace("?", Utils.escapeStringForLDAP(searchString));

String base = getAttributes().get("base");
if (base == null) {
Expand All @@ -87,7 +87,7 @@ public Map<String, String> getSubjectByLogin(String login) throws InternalErrorE
if (query == null) {
throw new InternalErrorException("loginQuery attributes is required");
}
query = query.replaceAll("\\?", login);
query = query.replace("?", Utils.escapeStringForLDAP(login));

String base = getAttributes().get("base");
if (base == null) {
Expand Down
12 changes: 12 additions & 0 deletions perun-core/src/main/java/cz/metacentrum/perun/core/impl/Utils.java
Expand Up @@ -1585,4 +1585,16 @@ public static Pair<Integer, TemporalUnit> prepareGracePeriodDate(Matcher matcher

return new Pair<>(amount, field);
}

/**
* We need to escape some special characters for LDAP filtering.
* We need to escape these characters: '\\', '*', '(', ')', '\000'
*
* @param searchString search string which need to be escaped properly
* @return properly escaped search string
*/
public static String escapeStringForLDAP(String searchString) {
if(searchString == null) return "";
return searchString.replace("\\", "\\5C").replace("*", "\\2A").replace("(", "\\28").replace(")", "\\29").replace("\000", "\\00");
}
}