Severity:

HIGH RISK

(7.8)

Unsafe Deserialization in Keras TFSMLayer Safe Mode Handling

CVE-2026-1462

Modified

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Arbitrary Code Execution during Model Loading/Inference

Severity:

HIGH RISK

(7.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

The TFSMLayer class in Keras 3.13.0 unsafely loads attacker-controlled TensorFlow SavedModels during deserialization of .keras models, even when safe_mode=True is enabled.

By embedding malicious SavedModel paths inside a serialized model, an attacker can achieve arbitrary code execution during model loading or inference under the victim's privileges.

Affected context

This vulnerability affects environments that use Keras 3.13.0 and the TFSMLayer class to load or run .keras models, especially when:

  • Models are loaded from external or semi-trusted sources (e.g., shared artifacts, public repositories, model hubs, or user uploads).
  • The application relies on safe_mode=True as a security boundary when calling Keras model deserialization APIs.
  • TensorFlow SavedModels referenced by TFSMLayer are fetched from file paths or locations that are not tightly controlled or validated.

In such contexts, the mere act of loading a .keras file that includes a TFSMLayer configuration can trigger loading of external SavedModels without proper safety checks.

Exploit preconditions

  • Attack surface: Keras model loading and inference pipeline that accepts .keras files.
  • Required access: Ability to supply or influence a serialized .keras model consumed by the victim environment (e.g., upload, file drop, CI artifact injection, or supply-chain compromise).
  • Trigger point: Deserialization of the .keras model that contains a TFSMLayer with attacker-controlled configuration, particularly file paths to external SavedModels.
  • Why exploitation is possible:
  • TFSMLayer.from_config() unconditionally loads referenced TensorFlow SavedModels.
  • Attacker-controlled file paths are serialized into the model configuration and later deserialized without robust validation.
  • The safe_mode=True flag does not prevent loading of these external SavedModels, effectively bypassing its intended security guarantees.

Why this happens

The core issue is an unsafe deserialization pattern where serialized configuration data is implicitly trusted and used to load executable model components.

Specifically, the TFSMLayer:

  • Persists file system paths to external TensorFlow SavedModels within the .keras model configuration.
  • During from_config(), reads and uses these paths without strong validation or restriction.
  • Invokes TensorFlow loading mechanisms that can execute attacker-controlled logic when a crafted SavedModel is loaded.

This behavior maps to CWE-502: Deserialization of Untrusted Data, where untrusted serialized content is used to reconstruct complex objects that can run code or execute side effects during or immediately after deserialization. The design incorrectly treats safe_mode=True as sufficient isolation while still allowing arbitrary external model loading governed solely by attacker-controlled configuration.

Potential impact

  • Arbitrary code execution during model loading or inference under the victim application's privileges.
  • Compromise of the ML serving process, including data access, API keys, or downstream systems.
  • Tampering with inference results, leading to data integrity issues or model misuse (e.g., adversarial predictions, fraud, or safety policy bypasses).
  • Use of the compromised environment as an entry point for lateral movement within the surrounding infrastructure.
  • Execution of additional payloads (e.g., cryptominers, data exfiltration tools) embedded within malicious SavedModels.

General mitigation guidance

Effective mitigation focuses on treating all serialized models and their configurations as untrusted input and minimizing what deserialization is allowed to do by default.

Recommended defensive patterns include:

  • Tightening trust boundaries for models:
  • Only load models from authenticated, integrity-checked channels (e.g., signed artifacts, controlled registries).
  • Avoid loading user-supplied .keras models directly into production environments.
  • Restricting external model loading:
  • Avoid or restrict use of features that dynamically load external SavedModels based on configuration values.
  • Introduce allowlist-based validation for any file paths or URIs used by TFSMLayer-like components before load-time.
  • Hardening deserialization behavior:
  • Treat safe_mode as a defense-in-depth feature, not a primary security control; apply additional checks around any deserialization entry points.
  • Prefer minimal, schema-driven configuration formats that do not implicitly trigger complex object construction.
  • Least privilege and sandboxing:
  • Run ML inference services with the least filesystem and network privileges necessary.
  • Use containerization or sandboxing to limit the blast radius of potential code execution arising from malicious models.
  • Operational controls:
  • Separate environments for model evaluation and production serving, so untrusted or experimental models are never directly loaded into high-value systems.

How teams detect issues like this

Detection should aim to identify unsafe deserialization paths and unexpected external model loading behaviors.

Possible strategies include:

  • Static analysis and code review:
  • Search for TFSMLayer usage and inspect any code paths that deserialize .keras models, especially where from_config() is indirectly invoked.
  • Flag patterns where file paths or URIs from model configuration are used without validation to load external resources.
  • Review reliance on safe_mode=True as a primary security control and document assumptions around model trust.
  • Configuration and policy enforcement:
  • Implement policies that disallow loading models from non-approved locations or from user-controllable directories.
  • Enforce checks that block or alert on models whose configuration contains unexpected file paths or references to external SavedModels.
  • Runtime monitoring:
  • Monitor ML serving processes for unusual filesystem access patterns when loading models (e.g., reading from unexpected directories).
  • Use behavioral logging and anomaly detection to identify abnormal model loading flows or sudden changes in inference service behavior.
  • Automated tooling:
  • Integrate SAST/IAST tools that recognize deserialization entry points and flag untrusted data flows into model loading APIs.

Sources

SourceLink
github.comgithub.com/keras-team/keras/commit/b6773d3decaef1b05d8e794458e148cb362f163f
huntr.comhuntr.com/bounties/7e78d6f1-6977-4300-b595-e81bdbda331c
access.redhat.comaccess.redhat.com/errata/RHSA-2026:24977
access.redhat.comaccess.redhat.com/errata/RHSA-2026:37275
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-1462
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2457856
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-1462.json

Frequently asked

questions

It can be, depending on how the application accepts models. If a remote user can upload or otherwise provide .keras models that are automatically loaded by the service, then the issue can be exploited remotely via that interface.

The attacker needs the ability to influence or provide the .keras file that the victim environment loads. This may occur through direct upload capabilities, integration with external model repositories, CI/CD pipelines that import third-party models, or compromise of model distribution channels.

The safest pattern is to treat model deserialization as a privileged operation, only loading models from tightly controlled, validated sources and avoiding automatic loading of external SavedModels based solely on configuration. Introduce strict validation or hard-coded rules for which paths and components can be loaded, and avoid relying on safe_mode as the sole protection.

Adopt a secure-by-design approach for all serialization and deserialization features: keep serialized formats simple, avoid embedding executable behavior or dynamic loading decisions in configuration, validate all external references before use, and enforce least-privilege and sandboxing for any process that consumes untrusted or semi-trusted models.

Find out what's already
exploitable in your codebase.