-
-

Understanding Model Threats

This resource is designed to provide detailed information on various threat categories, helping you understand and mitigate potential risks in AI and machine learning systems.

Deserialization Threats

Deserialization threats occur when untrusted data or code is used to reconstruct objects, leading to potential exploitation. In AI and machine learning systems, this can result in malicious actors injecting harmful code during the deserialization process, exploiting vulnerabilities to gain unauthorized access or manipulate your systems behavior. Understanding deserialization threats is crucial for securing data integrity and preventing unauthorized code execution in your AI models.

Overview

Deserialization threats in AI and machine learning systems pose significant security risks, particularly when using Keras models with Lambda Layers. This article outlines the specific threat, its potential impact, and provides actionable steps to mitigate these risks.

Models flagged for this threat meet the following criteria:

  1. Built using Keras
  2. Incorporate Lambda Layers
  3. Contain potentially malicious code within Lambda Layers that executes upon model loading

Keras is an open-source deep learning library for developing machine learning models. It provides a high-level API that integrates with other machine learning libraries like TensorFlow, JAX, and PyTorch.

Lambda Layers in Keras allow custom operations or transformations on data within a neural network. While standard Keras layers (e.g., Dense, Conv2D) offer predefined functionality, Lambda Layers enable unique transformations when standard layers are insufficient.

The security threat arises from the flexibility Lambda Layers provide for customizing operations. This flexibility extends to allowing arbitrary code execution. As with all forms of code, users should only load and execute models from trusted sources.

Key Points

  • Deserialization threats can lead to unauthorized code execution in AI models
  • Keras models using Lambda Layers are particularly vulnerable
  • Attacks can result in data theft, system compromise, and broader security breaches
  • Mitigation strategies include using safe formats and thorough vetting processes

Impact

An attacker could exploit a compromised model to:

  1. Access sensitive information (e.g., SSH keys, cloud credentials)
  2. Execute malicious code on your system
  3. Use the compromised system as a vector for broader attacks

The code within Lambda Layers executes at model load time, potentially compromising your system before the model is even used.

How The Attack Works:

Best Practices

You should:

  1. Only load and execute models from trusted sources
  2. Implement a vetting process for third-party models before use
  3. Use sandboxing techniques when loading untrusted models
  4. Regularly update Keras and related libraries to benefit from security patches
  5. Use model formats that don't allow arbitrary code execution, such as SafeTensors, which provides a safe alternative to traditional serialization formats

Remediation

If possible, use a different model format like SafeTensors in order to remove this type of code injection attack from impacting your work entirely.

If not possible, reach out to the model creator and alert them that the model has failed our scan. You can even link to the specific page on our Insights Database to provide our most up to date findings.

The model provider should also report what they did to correct this issue as part of their release notes.

Protect AI's security scanner detects threats in model files
With Protect AI's Guardian you can scan models for threats before ML developers download them for use, and apply policies based on your risk tolerance.
Learn more