File tree Expand file tree Collapse file tree
rt/rs/extensions/search/src
main/java/org/apache/cxf/jaxrs/ext/search/ldap
test/java/org/apache/cxf/jaxrs/ext/search/ldap Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,8 +60,9 @@ public void visit(SearchCondition<T> sc) {
6060 }
6161
6262 String ldapOperator = conditionTypeToLdapOperator (sc .getConditionType ());
63+ String encodedName = encodeQueryValues ? Util .doRFC2254Encoding (name ) : name ;
6364 String encodedRValStr = encodeQueryValues ? Util .doRFC2254Encoding (rvalStr ) : rvalStr ;
64- sb .append (name ).append (ldapOperator ).append (encodedRValStr );
65+ sb .append (encodedName ).append (ldapOperator ).append (encodedRValStr );
6566
6667 sb .append (')' );
6768 }
Original file line number Diff line number Diff line change 2020
2121import java .util .Date ;
2222
23+ import org .apache .cxf .jaxrs .ext .search .ConditionType ;
24+ import org .apache .cxf .jaxrs .ext .search .SearchBean ;
2325import org .apache .cxf .jaxrs .ext .search .SearchCondition ;
2426import org .apache .cxf .jaxrs .ext .search .SearchParseException ;
27+ import org .apache .cxf .jaxrs .ext .search .SimpleSearchCondition ;
2528import org .apache .cxf .jaxrs .ext .search .fiql .FiqlParser ;
2629
2730import org .junit .Ignore ;
@@ -86,6 +89,18 @@ public void testComplexQuery() throws SearchParseException {
8689 assertEquals ("(&(|(name=test)(level=18))(|(name=test1)(!level=19)))" , ldap );
8790 }
8891
92+ @ Test
93+ public void testLdapFilterInjectionViaUnencodedPropertyName () throws SearchParseException {
94+ SearchBean bean = new SearchBean ();
95+ bean .set ("cn)(|(sn" , "admin" );
96+
97+ SearchCondition <SearchBean > filter =
98+ new SimpleSearchCondition <>(ConditionType .EQUALS , bean );
99+ LdapQueryVisitor <SearchBean > visitor = new LdapQueryVisitor <>();
100+ filter .accept (visitor .visitor ());
101+
102+ assertEquals ("(cn\\ 29\\ 28|\\ 28sn=admin)" , visitor .getQuery ());
103+ }
89104
90105 @ Ignore
91106 public static class Condition {
You can’t perform that action at this time.
0 commit comments