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
2 changes: 1 addition & 1 deletion expectedresults-1.2.csv
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BenchmarkTest00040,pathtraver,true,22
BenchmarkTest00041,xss,true,79
BenchmarkTest00042,weakrand,false,330
BenchmarkTest00043,sqli,true,89
BenchmarkTest00044,ldapi,true,90
BenchmarkTest00044,ldapi,false,90
BenchmarkTest00045,pathtraver,true,22
BenchmarkTest00046,hash,true,328
BenchmarkTest00047,xss,true,79
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/owasp/benchmark/helpers/LDAPManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public boolean insert(LDAPPerson person) {
return true;
}

public static String createPersonUidFilter(String uid) {
return "(&(objectclass=person)(uid=" + ESAPI_Encoder.encodeForLDAP(uid) + "))";
}

/**
* Search LDAPPerson by name
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
String base = "ou=users,ou=system";
javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls();
sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE);
String filter = "(&(objectclass=person)(uid=" + param + "))";
String filter = org.owasp.benchmark.helpers.LDAPManager.createPersonUidFilter(param);
boolean found = false;
javax.naming.NamingEnumeration<javax.naming.directory.SearchResult> results =
ctx.search(base, filter, sc);
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/org/owasp/benchmark/helpers/LDAPManagerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* OWASP Benchmark Project
*
* <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project.
*
* <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, version 2.
*
* <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*/
package org.owasp.benchmark.helpers;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

class LDAPManagerTest {

@Test
void personUidFilterPreservesOrdinaryUid() {
assertEquals(
"(&(objectclass=person)(uid=alice))",
LDAPManager.createPersonUidFilter("alice"));
}

@Test
void personUidFilterEscapesFilterMetacharactersInUid() {
assertEquals(
"(&(objectclass=person)(uid=\\2a\\29\\28uid=\\2a\\29))",
LDAPManager.createPersonUidFilter("*)(uid=*)"));
}
}
Loading