← Java / Spring · Contents

JAVA-082 / Advanced

Using external input for JNDI lookups

A03:2021 Injection · CWE-917 · CWE-74 · CWE-502 related

Why is this a problem?

Remote object loading (LDAP/RMI) leads to RCE.

How to fix it

java
// Use only fixed resource names; no external input
new InitialContext().lookup("java:comp/env/jdbc/AppDS");

Further reading