JRaman655537 (Community Member) asked a question.

CWE 502 flaw in Java code for LDAP User authentication

Hi,

 

We use JNDI LDAP Authentication for user authentication, in the below code

 

public static boolean authorizeLDAP(String UserLoginID , String Userpassword){

try {

Hashtable<String, String> env = new Hashtable<String, String>();

 

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.STATE_FACTORIES, "UserStateFactory");

env.put(Context.OBJECT_FACTORIES, "UserObjectFactory");

env.put(Context.PROVIDER_URL, "LDAP Server");

env.put(Context.SECURITY_PRINCIPAL, UserLoginID + "@LDAPDOMAIN");

env.put(Context.SECURITY_CREDENTIALS, Userpassword);

env.put(LdapContext.CONTROL_FACTORIES, "com.sun.jndi.ldap.ControlFactory");

@SuppressWarnings("unused")

DirContext ctx = new InitialDirContext(env); // causing CWE 502 flaw

}catch(Exception e){

e.printStackTrace();

return false;

}

return true;

}

 

Is there a way to avoid the CWE 502 flaw? What do I need to do?


BBoddu600722 likes this.

Topics (4)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.