Skip to content

Implement import allowlist in AutoPeftModel, limit access in megatron - #3090

Merged
githubnemo merged 4 commits into
huggingface:mainfrom
githubnemo:issue/arbitrary-module-import
Apr 16, 2026
Merged

githubnemo merged 4 commits into
huggingface:mainfrom
githubnemo:issue/arbitrary-module-import

Conversation

@githubnemo

Copy link
Copy Markdown
Collaborator

Resolves #3085. AutoPeftModel resolves the base model's class by importing the parent library mentioned in the adapter config which makes way for potentially executing malicious code on the adapter creator's behalf. While this is not a remote code execution vulnerability by itself (since the attacker still needs to install a malicious package on the system) it can be used for code execution in case the attacker has file system access, for example.

The same is happening for the megatron.core config key. I haven't found any evidence that megatron wants to load other modules than megatron.*, so we limit it to that.

There was a bit of missing documentation, typo, missing hub_online_once, so I took the opportunity to fix that along the way.

nemo added 3 commits March 11, 2026 12:30
Partially resolves huggingface#3085. AutoPeftModel resolves the base
model's class by importing the parent library mentioned in the
adapter config which makes way for potentially executing malicious
code on the adapter creator's behalf. While this is not a remote
code execution vulnerability by itself (since the attacker still
needs to install a malicious package on the system) it can be
used for code execution in case the attacker has file system
access, for example.
I haven't found any evidence that one wants to load other modules
than `megatron.*`, so we limit it to that.
@githubnemo

Copy link
Copy Markdown
Collaborator Author

cc @spartan8806

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@spartan8806

Copy link
Copy Markdown

Thanks for the quick turnaround.

@github-actions

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

@BenjaminBossan BenjaminBossan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can give it a try and roll back if it causes trouble.

Comment thread src/peft/tuners/lora/tp_layer.py Outdated
target_base_layer = target

if config.megatron_config:
if not config.megatron_core.startswith("megatron."):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember the specifics anymore and after checking the PR from back then couldn't find anything, but I vaguely remember that there were explicit cases where another lib might be needed. How about solving this similarly to below with a patch-able allow list?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@BenjaminBossan BenjaminBossan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, LGTM.

@githubnemo
githubnemo merged commit 73291a3 into huggingface:main Apr 16, 2026
10 checks passed
abdulfatir added a commit to amazon-science/chronos-forecasting that referenced this pull request Aug 14, 2026
## Fix

`peft` 0.20
([huggingface/peft#3090](huggingface/peft#3090))
enforces an import allowlist when resolving a LoRA adapter's
`auto_mapping.parent_library`. For Chronos-2 adapters this is
`chronos.chronos2.model`, which is not in the default allowlist, so
`Chronos2Pipeline.from_pretrained` on an adapter raises:

```
ValueError: The auto mapping wants to import 'chronos.chronos2.model' which is not in the import allowlist.
```

This broke `test_chronos2_lora_pipeline_loads_from_disk` in CI once
`peft` 0.20 was pulled in.

We now pass `import_allowlist=["chronos"]` (peft matches on the module
prefix, so this covers any submodule under our own package) when loading
an adapter. The call is guarded on `peft>=0.20.0` since the kwarg does
not exist in older versions within our supported range (`peft>=0.18.1`);
the guard can be dropped once the minimum is 0.20.

## Testing

`test/test_chronos2.py::test_chronos2_lora_pipeline_loads_from_disk`
passes with `peft` 0.20.0 installed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Abdul Fatir Ansari <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: Arbitrary Module Import via Malicious Adapter Config (CWE-94)

4 participants