File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
main/java/org/apache/cxf/transport/jms/util
test/java/org/apache/cxf/transport/jms Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,13 @@ public class JndiHelper {
34
34
*/
35
35
public JndiHelper (Properties environment ) {
36
36
this .environment = environment ;
37
+
38
+ // Avoid unsafe protocols if they are somehow misconfigured
39
+ String providerUrl = environment .getProperty (Context .PROVIDER_URL );
40
+ if (providerUrl != null && (providerUrl .startsWith ("ldap://" )
41
+ || providerUrl .startsWith ("rmi://" ))) {
42
+ throw new IllegalArgumentException ("Unsafe protocol in JNDI URL: " + providerUrl );
43
+ }
37
44
}
38
45
39
46
@ SuppressWarnings ("unchecked" )
Original file line number Diff line number Diff line change 19
19
20
20
package org .apache .cxf .transport .jms ;
21
21
22
+ import java .util .Properties ;
23
+
24
+ import javax .naming .Context ;
22
25
import javax .naming .NamingException ;
23
26
import javax .transaction .xa .XAException ;
24
27
35
38
36
39
public class JMSConfigFactoryTest extends AbstractJMSTester {
37
40
41
+ @ Test
42
+ public void testJndiForbiddenProtocol () throws Exception {
43
+ Properties env = new Properties ();
44
+ env .put (Context .INITIAL_CONTEXT_FACTORY , "com.sun.jndi.ldap.LdapCtxFactory" );
45
+ env .put (Context .PROVIDER_URL , "ldap://127.0.0.1:12345" );
46
+ // Allow following referrals (important for LDAP injection)
47
+ env .put (Context .REFERRAL , "follow" );
48
+
49
+ JMSConfiguration jmsConfig = new JMSConfiguration ();
50
+ jmsConfig .setJndiEnvironment (env );
51
+ jmsConfig .setConnectionFactoryName ("objectName" );
52
+
53
+ try {
54
+ jmsConfig .getConnectionFactory ();
55
+ Assert .fail ("JNDI lookup should have failed" );
56
+ } catch (Exception e ) {
57
+ Assert .assertTrue (e .getMessage ().contains ("Unsafe protocol in JNDI URL" ));
58
+ }
59
+ }
60
+
38
61
@ Test
39
62
public void testUsernameAndPassword () throws Exception {
40
63
EndpointInfo ei = setupServiceInfo ("HelloWorldService" , "HelloWorldPort" );
You can’t perform that action at this time.
0 commit comments