fix(dynamic_modules): enforce trust_remote_code for community pipeline branch#13742
Open
xodn348 wants to merge 1 commit into
Open
fix(dynamic_modules): enforce trust_remote_code for community pipeline branch#13742xodn348 wants to merge 1 commit into
xodn348 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The
is_community_pipelinebranch inget_cached_module_file()downloaded and executed Python code fromdiffusers/community-pipelines-mirrorwithout checkingtrust_remote_code, while both the local-file branch and the HF Hub branch correctly gated on that flag. This made it possible for a user who settrust_remote_code=False(or relied on the default) to unknowingly load and execute remote community pipeline code.The fix adds the same
trust_remote_codeguard to the community-pipeline branch that already exists for the other two branches. I also updatedtest_load_custom_githubto (a) add a negative test confirming that loading withouttrust_remote_code=Truenow raisesValueError, and (b) passtrust_remote_code=Trueto the two existing positive-test calls.Fixes #13691
Before submitting
documentation guidelines, and
here are tips on formatting docstrings.
Summary
The
get_cached_module_file()function has three code paths — local file, community pipeline (short name, no/), and HF Hub repo. Both the local-file path and the HF Hub path guard ontrust_remote_codeand raiseValueErrorif it isFalse. The community-pipeline path skipped this check entirely, downloading and loading arbitrary Python from thediffusers/community-pipelines-mirrordataset regardless of what the user specified.Root cause: the community-pipeline branch was added without carrying over the
trust_remote_codeguard that the other two branches already had. The mitigating factor (only loads from the officialdiffusers/community-pipelines-mirrordataset, not arbitrary user repos) does not remove the need for the flag: the whole point oftrust_remote_code=Falseis to give users an opt-in gate for remote code execution, and community pipelines are remote code.The fix adds a six-line
if not trust_remote_code: raise ValueError(...)block at the top of theelif is_community_pipeline:branch, symmetric with the guards in the other two branches. The existingDIFFUSERS_DISABLE_REMOTE_CODEcheck at the start of the function already fires before all three branches, so that code path is unaffected.Issue
Fixes #13691
Local verification
Risk
The only behavior change is that
DiffusionPipeline.from_pretrained(..., custom_pipeline="<short-name>")now raisesValueErroriftrust_remote_codeis notTrue. Users who relied on community pipelines without opting in must addtrust_remote_code=True— this is the same opt-in required for HF Hub custom pipelines. Existing users who already passtrust_remote_code=Trueare unaffected.Who can review?
@DN6 @yiyixuxu (pipelines / dynamic-modules)