/

CVE-2026-44827

Severity:

HIGH RISK

(8.8)

Arbitrary Code Execution via Remote Code Loading

CVE-2026-44827

Analyzed

Vulnerability type

Category:

Arbitrary Code Execution via Remote Code Loading

CWE:

CWE-94

Impact:

Remote Code Execution

Severity:

HIGH RISK

(8.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

Diffusers versions prior to 0.38.0 contain an arbitrary code execution issue where remote model repositories on the Hugging Face Hub can execute code without requiring the usual trust_remote_code=True safeguard.

By abusing how the library resolves a default custom_pipeline value of None into a filename (None.py), an attacker can publish a malicious repository that runs arbitrary code when a victim calls DiffusionPipeline.from_pretrained() with default arguments.

Affected context

This vulnerability affects applications that:

  • Use the diffusers library prior to version 0.38.0
  • Load pipelines from Hugging Face Hub repositories using DiffusionPipeline.from_pretrained()
  • Do not explicitly set trust_remote_code=True or otherwise restrict which files are executed from remote repositories

The issue manifests specifically when a repository includes a None.py file and the code path in _resolve_custom_pipeline_and_cls treats a default custom_pipeline=None as a valid module filename.

Exploit preconditions

  • Attack surface: Any process that calls DiffusionPipeline.from_pretrained() on a remote Hugging Face Hub repository using a vulnerable diffusers version.
  • Required access: Ability for an attacker to publish or control a model repository on the Hub that a victim will load.
  • Trigger point: A victim application invokes DiffusionPipeline.from_pretrained(<attacker_repo>) with default parameters (no custom_pipeline, no trust_remote_code=True).
  • Why exploitation is possible: The trust_remote_code safeguard checks only whether a custom_pipeline argument was explicitly provided (custom_pipeline is not None), while later code unconditionally converts the default None value to the filename "None.py". If that file exists in the repository and contains a subclass of DiffusionPipeline, its module is downloaded and executed as part of normal pipeline loading.

Why this happens

The underlying bug stems from inconsistent handling of a default parameter that represents remote executable code, combined with an incomplete security gate.

At a high level:

  • A parameter (custom_pipeline) controls which remote Python module will be loaded.
  • The security check in DiffusionPipeline.download() relies on whether the caller explicitly supplies this parameter to decide if trust_remote_code should be enforced.
  • However, downstream logic in _resolve_custom_pipeline_and_cls treats the default value None as a valid pipeline identifier by interpolating it into a filename using f"{custom_pipeline}.py", producing "None.py".

This creates a gap where remote Python code can be fetched and executed even though trust_remote_code enforcement is skipped, mapping to CWE-94: Code Injection / Execution Through Improper Control of Code Generation or Loading. Conceptually, the library treats a partially untrusted, remotely controlled artifact (a Python file in a Hub repo) as safe by default and constructs import paths from it without consistently applying the intended trust boundary.

Potential impact

  • Silent execution of arbitrary Python code when loading a seemingly legitimate diffusion model from the Hub.
  • Compromise of the application environment, including theft of API keys, credentials, or sensitive configuration.
  • Modification or exfiltration of input data, generated outputs, or intermediate model artifacts.
  • Use of the victim system as a foothold for lateral movement inside the surrounding infrastructure.
  • Installation of persistent malware or backdoors within environments that regularly load or update models.

General mitigation guidance

Effective mitigation focuses on tightening trust boundaries around remote code loading and making code execution opt-in and explicit:

  • Treat all remote model repositories as untrusted by default and require explicit consent before executing any Python code they contain.
  • Enforce that security checks (such as trust_remote_code) are applied uniformly across all code paths that can load or import Python modules from remote repositories, including defaulted parameters.
  • Avoid inferring executable module names from sentinel values (like None) or from loosely validated metadata; use explicit, whitelisted pipeline identifiers instead.
  • Separate data-only model artifacts (weights, configuration, tokenizer files) from executable code and prefer formats that do not require importing arbitrary modules to use the model.
  • Run model-loading code in constrained environments (e.g., containers, sandboxes, or processes with minimal privileges) to limit the impact of any unexpected code execution.
  • Introduce configuration or policy controls that restrict which organizations, repositories, or files are allowed to be loaded in production systems.

How teams detect issues like this

Organizations can look for this class of issue and its exploitation using a combination of code-centric and operational techniques:

  • Static analysis and code review:
  • Flag patterns where default or sentinel values (e.g., None, "") are converted into filenames or module names without additional validation.
  • Review all call sites that import, eval, exec, or dynamically load Python modules originating from remote storage or model hubs.
  • Check that security flags like trust_remote_code are enforced consistently across all helper functions and branches involved in pipeline loading.
  • Policy and CI/CD enforcement:
  • Add checks in CI to prevent adding new code paths that dynamically construct module filenames from unchecked metadata or parameters.
  • Require explicit configuration and documentation any time remote code execution is allowed in a component.
  • Runtime and operational monitoring:
  • Monitor for unexpected imports or module loads from model cache directories or temporary paths used for Hugging Face model downloads.
  • Instrument logging around model loading APIs to capture which repositories, files (including None.py), and classes are being imported, and alert when new or unapproved sources appear.
  • Automated tooling:
  • Use code scanning tools that can track data flow from remote inputs (e.g., model repository metadata, filenames) into dynamic import mechanisms and highlight missing trust checks.

Sources

SourceLink
github.comgithub.com/huggingface/diffusers/security/advisories/GHSA-j7w6-vpvq-j3gm

Frequently asked

questions

Yes. If an application uses a vulnerable diffusers version and loads pipelines from a malicious Hugging Face Hub repository, an attacker can trigger arbitrary code execution when the application performs a standard from_pretrained() call.

The attacker must be able to control or publish a model repository that the victim will load. They do not need access to the victim environment itself; exploitation occurs when the victim's code fetches and initializes the malicious repository.

Ensure that all code paths that can load Python files from remote repositories consistently enforce an explicit trust mechanism (such as a required trust_remote_code flag), avoid deriving module names from sentinel default values, and treat remote model artifacts as data by default rather than executable code.

Design model-loading APIs so that executing remote code is opt-in and clearly separated from data loading, apply uniform trust checks regardless of which arguments are provided, restrict dynamic imports tied to remote content, and integrate security reviews for any feature that loads code from external sources such as model hubs or plugin systems.

Find out what's already
exploitable in your codebase.