Dataset Viewer

The dataset viewer is not available because its heuristics could not detect any supported data files. You can try uploading some data files, or configuring the data files location manually.

YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

DL4J ModelSerializer Unsafe Deserialization — CWE-502

Vulnerability

Eclipse Deeplearning4j's ModelSerializer uses unfiltered ObjectInputStream.readObject() on preprocessor.bin entries from model ZIP archives. The deserialization is automatic — if a preprocessor.bin entry exists in the ZIP, it is deserialized unconditionally with zero security controls.

4 vulnerable call sites in ModelSerializer.java, all with identical pattern:

ObjectInputStream ois = new ObjectInputStream(stream);
preProcessor = (DataSetPreProcessor) ois.readObject();  // NO ObjectInputFilter

The type cast to DataSetPreProcessor occurs after readObject() completes. Java deserialization gadget chains execute during readObject(), before any cast — making the cast purely cosmetic from a security perspective.

Affected Code

Repository: deeplearning4j/deeplearning4j (14.2k stars, actively maintained)

File: deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/util/ModelSerializer.java

# Method ZIP Entry Trigger
1 restoreMultiLayerNetworkHelper() preprocessor.bin Entry exists in ZIP
2 restoreComputationGraphHelper() preprocessor.bin Entry exists in ZIP
3 getObjectFromFile() objects/<key> Caller requests key
4 restoreNormalizerFromInputStreamDeprecated() normalizer data Fallback path

Impact

An attacker creates a malicious DL4J model file (ZIP) containing a preprocessor.bin with a serialized Java gadget chain. When a victim loads this model via any restoreMultiLayerNetwork() or restoreComputationGraph() call, arbitrary code execution occurs during deserialization.

DL4J's transitive dependencies include Guava (shaded in nd4j-shade), commons-io, and other libraries that provide usable gadget chains.

Reproduction

Generate the malicious model

python3 create_poc.py
# Creates malicious_dl4j_model.zip with crafted preprocessor.bin

Load the model (triggers vulnerability)

# Using Maven project with DL4J dependency
mvn compile exec:java -Dexec.mainClass="LoadModel" -Dexec.args="malicious_dl4j_model.zip"

Expected output

Loading model from: malicious_dl4j_model.zip
Exception: java.lang.ClassCastException: java.util.HashMap cannot be cast to DataSetPreProcessor

The ClassCastException proves readObject() was called on attacker-controlled data. The HashMap was fully instantiated before the cast failed.

For full RCE

Replace the HashMap payload with a ysoserial gadget chain:

java -jar ysoserial.jar CommonsCollections6 'touch /tmp/pwned' > preprocessor.bin
# Repackage into model ZIP

Missing Mitigation

Java provides ObjectInputFilter (since Java 9, backported to 8u121) specifically for this purpose. DL4J uses none of:

  • ObjectInputFilter (per-stream filter)
  • ObjectInputFilter.Config.setSerialFilter() (global filter)
  • Apache Commons IO ValidatingObjectInputStream
  • Class allowlisting of any kind

The fix is to add an ObjectInputFilter restricting deserialized classes to DataSetPreProcessor implementations.

Files

  • malicious_dl4j_model.zip — Crafted DL4J model with malicious preprocessor.bin
  • create_poc.py — Python script to generate the malicious model
  • LoadModel.java — Java harness to trigger the vulnerability
Downloads last month
32