JFrog Security Research
< Back

XRAY-532656 - MLeap Path Traversal RCE

CVE-2023-5245 | CVSS 7.5

JFrog Severity:medium

Discovered ByDavid Fadidaof the JFrog Security Research Team

Published 15 Nov, 2023 | Last updated 15 Nov, 2023

Using MLeap for loading a saved model (zip archive) can lead to path traversal/arbitrary file creation and possibly remote code execution.

ml.combust.mleap.mleap-tensorflow

[0.18.0,0.23.0], Fixed in 0.23.1

FileUtil.extract() enumerates all zip file entries and extracts each file without validating whether file paths in the archive are outside the intended directory.

When creating an instance of TensorflowModel using the saved_model format and an exported TensorFlow model, the apply() function invokes the vulnerable implementation of FileUtil.extract().

Arbitrary file creation can directly lead to code execution

Example of a vulnerable usage of MLeap -

package example

import ml.combust.mleap.core.types._
import ml.combust.mleap.tensor.Tensor
import ml.combust.mleap.tensorflow.TensorflowModel
import org.tensorflow

import java.nio.file.{Files, Paths}

object LoadModelFromZip extends App {
  // Read zip file
  def readZipFileAsByteArray(filePath: String): Array[Byte] = {
    val fileBytes = Files.readAllBytes(Paths.get(filePath))
    fileBytes
  }
  // Stub 
  val _file = "/models/malicious.zip"
  val modelAsBytes = readZipFileAsByteArray(_file)
  // Create a model from zip file
  val model = TensorflowModel(
        inputs = Seq(
          ("InputA", TensorType.Float()), ("InputB", TensorType.Float())
        ),
        outputs = Seq(("MyResult", TensorType.Float())),
        format = Option("saved_model"),
        modelBytes = modelAsBytes
      )
  // Invoke FileUtil.extract()
  model.apply(Tensor.create(Array(2.0, 1.0, 34.0), Seq(-1)))
}

No mitigations are supplied for this issue

Fixing PR

< Back