mirror of
https://github.com/github/codeql.git
synced 2026-03-15 20:16:45 +01:00
21 lines
668 B
Java
21 lines
668 B
Java
import javax.naming.Context;
|
|
import javax.naming.InitialContext;
|
|
|
|
public void jndiLookup(HttpServletRequest request) throws NamingException {
|
|
String name = request.getParameter("name");
|
|
|
|
Hashtable<String, String> env = new Hashtable<String, String>();
|
|
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
|
|
env.put(Context.PROVIDER_URL, "rmi://trusted-server:1099");
|
|
InitialContext ctx = new InitialContext(env);
|
|
|
|
// BAD: User input used in lookup
|
|
ctx.lookup(name);
|
|
|
|
// GOOD: The name is validated before being used in lookup
|
|
if (isValid(name)) {
|
|
ctx.lookup(name);
|
|
} else {
|
|
// Reject the request
|
|
}
|
|
} |