Diffusers TOCTOU Vulnerability Leads to Remote Code Execution
A Time-of-Check Time-of-Use (TOCTOU) vulnerability in the `diffusers` package allows arbitrary code execution via a race condition when loading pipelines from the Hugging Face Hub, bypassing trust checks.
What's new
- 1. added CVE-2026-44513 +2 Aug 3, 07:59 via the-hacker-news
A TOCTOU vulnerability exists in the diffusers package (versions prior to 0.38.0), a library used for diffusion models. The vulnerability resides within the DiffusionPipeline.from_pretrained function, which is responsible for loading pipelines from the Hugging Face Hub. This function has a trust_remote_code guard intended to prevent the execution of untrusted code from custom pipelines. However, a race condition between two HTTP calls (hf_hub_download and snapshot_download) allows an attacker to introduce malicious code into the repository between the calls, effectively bypassing the trust check and enabling remote code execution. This occurs because the vulnerability allows arbitrary code to be loaded through the custom pipeline flow from a Hub repo, even without explicitly passing custom_pipeline or trust_remote_code arguments.
Attack Chain
- An attacker creates a Hugging Face Hub repository with a
model_index.jsonfile containing a plain string_class_namevalue, indicating no custom pipeline code. - A user attempts to load the pipeline using
DiffusionPipeline.from_pretrained("attacker/repo"). - The
hf_hub_downloadfunction fetches themodel_index.jsonfile (commit A) and the trust check passes because no custom pipeline is detected. - Before the
snapshot_downloadfunction is called, the attacker pushes a new commit (commit B) to the repository, modifying themodel_index.jsonfile to use a list_class_nameand adding a maliciouspipeline.pyfile. - The
snapshot_downloadfunction fetches commit B, including the maliciouspipeline.pyfile. - The
_resolve_custom_pipeline_and_clsfunction reads the updatedmodel_index.jsonand resolves the custom pipeline to the local path of thepipeline.pyfile. - The
_get_pipeline_classfunction imports the maliciouspipeline.pyfile without any further trust checks. - The malicious code within
pipeline.pyis executed, resulting in arbitrary code execution on the user's machine.
Impact
Successful exploitation of this vulnerability allows an attacker to execute arbitrary code on the victim's machine. The vulnerability is a silent RCE meaning that the from_pretrained call succeeds and returns a fully functional pipeline even when malicious code has been injected. This could lead to data exfiltration, system compromise, or other malicious activities. The impact is significant as it undermines the trust mechanisms designed to protect users from running untrusted code.
Recommendation
- Upgrade to
diffusersversion 0.38.0 or later to patch the vulnerability. - When using
DiffusionPipeline.from_pretrained, pin therevisionargument to a specific commit hash to avoid race conditions, as described in the overview. - Deploy the Sigma rule "Detect Diffusers from_pretrained with trust_remote_code" to detect potential exploitation attempts by identifying calls to
DiffusionPipeline.from_pretrainedwithout explicit trust settings. - Monitor network connections for unexpected outbound traffic originating from processes associated with the
diffuserslibrary, using the network connection Sigma rule in this brief to identify potential command and control activity.
Detection coverage 2
Detect Diffusers from_pretrained without trust_remote_code
mediumDetects calls to DiffusionPipeline.from_pretrained without explicit trust_remote_code, which may indicate a potential TOCTOU exploit attempt targeting CVE-2026-45804.
Detect Suspicious Network Connection from Diffusers Process
lowDetects network connections initiated by processes related to the diffusers library, potentially indicating command and control activity after CVE-2026-45804 exploitation.
Detection queries are available on the platform. Get full rules →