11
11
import javax .naming .InitialContext ;
12
12
import javax .naming .Name ;
13
13
import javax .naming .NamingException ;
14
+ import javax .naming .directory .DirContext ;
14
15
import javax .naming .directory .InitialDirContext ;
15
16
import javax .naming .directory .SearchControls ;
16
17
import javax .naming .ldap .InitialLdapContext ;
17
18
18
19
import org .springframework .jndi .JndiTemplate ;
19
20
import org .springframework .ldap .core .AttributesMapper ;
20
21
import org .springframework .ldap .core .ContextMapper ;
22
+ import org .springframework .ldap .core .DirContextProcessor ;
21
23
import org .springframework .ldap .core .LdapTemplate ;
22
24
import org .springframework .ldap .core .NameClassPairCallbackHandler ;
23
25
import org .springframework .stereotype .Controller ;
@@ -47,9 +49,9 @@ public void testInitialContextBad1(@RequestParam String nameStr) throws NamingEx
47
49
}
48
50
49
51
@ RequestMapping
50
- public void testInitialDirContextBad1 (@ RequestParam String nameStr ) throws NamingException {
52
+ public void testDirContextBad1 (@ RequestParam String nameStr ) throws NamingException {
51
53
Name name = new CompoundName (nameStr , new Properties ());
52
- InitialDirContext ctx = new InitialDirContext ();
54
+ DirContext ctx = new InitialDirContext ();
53
55
54
56
ctx .lookup (nameStr ); // $hasJndiInjection
55
57
ctx .lookupLink (nameStr ); // $hasJndiInjection
@@ -62,6 +64,19 @@ public void testInitialDirContextBad1(@RequestParam String nameStr) throws Namin
62
64
ctx .rename (name , null ); // $hasJndiInjection
63
65
ctx .list (name ); // $hasJndiInjection
64
66
ctx .listBindings (name ); // $hasJndiInjection
67
+
68
+ SearchControls searchControls = new SearchControls ();
69
+ searchControls .setReturningObjFlag (true );
70
+ ctx .search (nameStr , "" , searchControls ); // $hasJndiInjection
71
+ ctx .search (nameStr , "" , new Object [] {}, searchControls ); // $hasJndiInjection
72
+
73
+ SearchControls searchControls2 = new SearchControls (1 , 0 , 0 , null , true , false );
74
+ ctx .search (nameStr , "" , searchControls2 ); // $hasJndiInjection
75
+ ctx .search (nameStr , "" , new Object [] {}, searchControls2 ); // $hasJndiInjection
76
+
77
+ SearchControls searchControls3 = new SearchControls (1 , 0 , 0 , null , false , false );
78
+ ctx .search (nameStr , "" , searchControls3 ); // Safe
79
+ ctx .search (nameStr , "" , new Object [] {}, searchControls3 ); // Safe
65
80
}
66
81
67
82
@ RequestMapping
@@ -93,7 +108,7 @@ public void testSpringJndiTemplateBad1(@RequestParam String nameStr) throws Nami
93
108
@ RequestMapping
94
109
public void testSpringLdapTemplateBad1 (@ RequestParam String nameStr ) throws NamingException {
95
110
LdapTemplate ctx = new LdapTemplate ();
96
- Name name = new CompositeName (nameStr );
111
+ Name name = new CompositeName (). add ( nameStr );
97
112
98
113
ctx .lookup (nameStr ); // $hasJndiInjection
99
114
ctx .lookupContext (nameStr ); // $hasJndiInjection
@@ -104,11 +119,45 @@ public void testSpringLdapTemplateBad1(@RequestParam String nameStr) throws Nami
104
119
ctx .unbind (nameStr , true ); // $hasJndiInjection
105
120
106
121
ctx .search (nameStr , "" , 0 , true , null ); // $hasJndiInjection
107
- ctx .search (nameStr , "" , 0 , new String [] {}, (ContextMapper <Object >) new Object ()); // $hasJndiInjection
108
- ctx .search (nameStr , "" , 0 , (ContextMapper <Object >) new Object ()); // $hasJndiInjection
109
- ctx .search (nameStr , "" , (ContextMapper ) new Object ()); // $hasJndiInjection
110
-
111
- ctx .searchForObject (nameStr , "" , (ContextMapper ) new Object ()); // $hasJndiInjection
122
+ ctx .search (nameStr , "" , 0 , new String [] {}, (ContextMapper <Object >) null ); // $hasJndiInjection
123
+ ctx .search (nameStr , "" , 0 , (ContextMapper <Object >) null ); // $hasJndiInjection
124
+ ctx .search (nameStr , "" , (ContextMapper <Object >) null ); // $hasJndiInjection
125
+
126
+ SearchControls searchControls = new SearchControls ();
127
+ searchControls .setReturningObjFlag (true );
128
+ ctx .search (nameStr , "" , searchControls , (AttributesMapper <Object >) null ); // $hasJndiInjection
129
+ ctx .search (nameStr , "" , searchControls , (AttributesMapper <Object >) null , // $hasJndiInjection
130
+ (DirContextProcessor ) null );
131
+ ctx .search (nameStr , "" , searchControls , (ContextMapper <Object >) null ); // $hasJndiInjection
132
+ ctx .search (nameStr , "" , searchControls , (ContextMapper <Object >) null , // $hasJndiInjection
133
+ (DirContextProcessor ) null );
134
+ ctx .search (nameStr , "" , searchControls , (NameClassPairCallbackHandler ) null ); // $hasJndiInjection
135
+ ctx .search (nameStr , "" , searchControls , (NameClassPairCallbackHandler ) null , // $hasJndiInjection
136
+ (DirContextProcessor ) null );
137
+
138
+ SearchControls searchControls2 = new SearchControls (1 , 0 , 0 , null , true , false );
139
+ ctx .search (nameStr , "" , searchControls2 , (AttributesMapper <Object >) null ); // $hasJndiInjection
140
+ ctx .search (nameStr , "" , searchControls2 , (AttributesMapper <Object >) null , // $hasJndiInjection
141
+ (DirContextProcessor ) null );
142
+ ctx .search (nameStr , "" , searchControls2 , (ContextMapper <Object >) null ); // $hasJndiInjection
143
+ ctx .search (nameStr , "" , searchControls2 , (ContextMapper <Object >) null , // $hasJndiInjection
144
+ (DirContextProcessor ) null );
145
+ ctx .search (nameStr , "" , searchControls2 , (NameClassPairCallbackHandler ) null ); // $hasJndiInjection
146
+ ctx .search (nameStr , "" , searchControls2 , (NameClassPairCallbackHandler ) null , // $hasJndiInjection
147
+ (DirContextProcessor ) null );
148
+
149
+ SearchControls searchControls3 = new SearchControls (1 , 0 , 0 , null , false , false );
150
+ ctx .search (nameStr , "" , searchControls3 , (AttributesMapper <Object >) null ); // Safe
151
+ ctx .search (nameStr , "" , searchControls3 , (AttributesMapper <Object >) null , // Safe
152
+ (DirContextProcessor ) null );
153
+ ctx .search (nameStr , "" , searchControls3 , (ContextMapper <Object >) null ); // Safe
154
+ ctx .search (nameStr , "" , searchControls3 , (ContextMapper <Object >) null , // Safe
155
+ (DirContextProcessor ) null );
156
+ ctx .search (nameStr , "" , searchControls3 , (NameClassPairCallbackHandler ) null ); // Safe
157
+ ctx .search (nameStr , "" , searchControls3 , (NameClassPairCallbackHandler ) null , // Safe
158
+ (DirContextProcessor ) null );
159
+
160
+ ctx .searchForObject (nameStr , "" , (ContextMapper <Object >) null ); // $hasJndiInjection
112
161
}
113
162
114
163
@ RequestMapping
0 commit comments