Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion g11n-ws/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ subprojects{
hibernateJpa21Api = "1.0.2.Final"
log4j2Version="2.25.5"
slf4jVersion="2.0.18"
esapiVersion="2.6.2.0"
nimbusJoseJwtVersion="10.1"

postgresqlVersion = "42.1.4"
Expand Down
8 changes: 0 additions & 8 deletions g11n-ws/modules/md-service-authen/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ dependencies {
compileOnly("commons-codec:commons-codec:$commonsCodecVersion")
api("com.auth0:java-jwt:3.18.2")

implementation("org.owasp.esapi:esapi:$esapiVersion"){
exclude group: "org.apache.httpcomponents.client5"
exclude group: "org.apache.httpcomponents.core5"
exclude group: "commons-fileupload"
exclude group: "org.apache.xmlgraphics"
exclude group: "org.owasp.antisamy"
exclude group: "commons-lang"
}
implementation("com.nimbusds:nimbus-jose-jwt:$nimbusJoseJwtVersion")

compileOnly("commons-fileupload:commons-fileupload:1.5")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 VMware, Inc.
* Copyright 2019-2026 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.vip.core.login;
Expand All @@ -19,8 +19,6 @@
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;

import org.owasp.esapi.Encoder;
import org.owasp.esapi.reference.DefaultEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -32,7 +30,25 @@ public class LdapAuthenticator {

@Autowired
private VipAuthConfig authConfig;


/**
* Escape a value for safe inclusion in an LDAP search filter per RFC 4515,
* to prevent LDAP filter injection.
*/
private static String escapeForLdapFilter(String input) {
StringBuilder sb = new StringBuilder();
for (char c : input.toCharArray()) {
switch (c) {
case '\\': sb.append("\\5c"); break;
case '*': sb.append("\\2a"); break;
case '(': sb.append("\\28"); break;
case ')': sb.append("\\29"); break;
case '\0': sb.append("\\00"); break;
default: sb.append(c);
}
}
return sb.toString();
}

private Map<String, Object> authenticate(String user, String pass){

Expand All @@ -56,8 +72,7 @@ private Map<String, Object> authenticate(String user, String pass){
LdapContext ctxGC = null;
try{
ctxGC = new InitialLdapContext(env, null);
Encoder encoder = DefaultEncoder.getInstance();
String safeNme = encoder.encodeForLDAP(user);
String safeNme = escapeForLdapFilter(user);
String safeFilter = String.format(searchFilter, safeNme);
NamingEnumeration<SearchResult> answer = ctxGC.search(authConfig.getSearchbase(), safeFilter, searchCtls);

Expand Down
Loading
Loading