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.

