Summary
mchange-commons-java's JavaBeanObjectFactory can instantiate arbitrary classes and set their properties based on JNDI data, enabling JNDI injection and deserialization gadget abuse.
When untrusted JNDI references or serialized objects are processed, attackers may provoke unexpected network calls or other side effects from within a trusted JVM context.
Affected context
This vulnerability appears in Java applications that use mchange-commons-java (commonly via c3p0 or other mchange projects) and rely on its JavaBeanObjectFactory and ReferenceIndirector when resolving JNDI lookups or reading serialized objects.
It becomes relevant in setups where JNDI references, resource descriptors, or serialized data may be influenced by external sources, application configuration, or infrastructure components without strict validation.
Exploit preconditions
- Attack surface: JNDI lookups and Java deserialization paths that use mchange-commons-java's JavaBeanObjectFactory or ReferenceIndirector.
- Required access: Ability to supply or influence JNDI Reference objects, resource configuration, or serialized objects consumed by the application.
- Trigger point: Resolution of a JNDI reference or dereferencing of an indirect reference / serialized object that is processed by JavaBeanObjectFactory.
- Why exploitation is possible: The factory can construct arbitrary classes and set "JavaBean"-style properties from attacker-controlled data, which for certain classes act as deserialization gadgets or cause network activity and other side effects.
Why this happens
The underlying issue is a combination of CWE-470: Use of Externally-Controlled Input to Select Classes or Code and CWE-502: Deserialization of Untrusted Data.
JavaBeanObjectFactory trusts JNDI-provided class names and property values, instantiating arbitrary types and initializing their fields without restricting which classes may be constructed or what properties may be set.
This generic "bean construction" pattern interacts dangerously with classes whose setters or initialization logic trigger external calls or gadget behavior, allowing attackers to chain property assignments into meaningful exploits.
ReferenceIndirector further extends the attack surface by enabling indirect references to be dereferenced wherever Java-serialized objects are read, amplifying the reach of unsafe object instantiation.
Potential impact
- Attackers may provoke HTTP GET or other network requests to arbitrary URLs from inside the JVM.
- Applications could inadvertently access external or internal services from a trusted network zone.
- Deserialization gadgets may be leveraged to escalate impact, potentially leading to arbitrary code execution depending on available gadget chains.
- Misuse of JNDI and gadget classes can result in data exfiltration or interaction with sensitive internal endpoints.
General mitigation guidance
Effective mitigation patterns focus on reducing trust in externally controlled class selection and limiting which types can be instantiated via configuration or JNDI.
Common defensive approaches include:
- Restricting JNDI ObjectFactory behavior to a small, vetted set of safe classes, instead of allowing arbitrary type names from references.
- Avoiding generic "JavaBean" instantiation mechanisms for data coming from JNDI, serialized objects, or other untrusted channels.
- Designing configuration and resource resolution paths so that class names and critical properties are fixed at deploy-time and not influenced by runtime input.
- Minimizing or eliminating use of Java deserialization for untrusted or semi-trusted data and preferring structured formats with strict schema validation.
- Applying least-privilege at the application level to limit the consequences of any unexpected network or resource access triggered by gadget behavior.
How teams detect issues like this
Detection commonly starts with code and configuration review focused on JNDI usage and deserialization flows.
Useful strategies include:
- Static analysis rules that flag use of generic ObjectFactory implementations capable of constructing arbitrary classes based on external input.
- Auditing JNDI resource definitions, environment properties, and serialized object handling for patterns where class names, factory types, or properties derive from externally influenced data.
- Establishing secure coding policies that prohibit unconstrained bean instantiation from JNDI references or serialized data and requiring explicit whitelists for ObjectFactories.
- Leveraging automated security review tools to identify deserialization entry points, JNDI lookups, and indirect reference dereferencing, then validating these locations against organizational policies.

