security: validate Hydra _target_ before instantiate() to prevent ACE (CWE-913)#40
Open
Allen930311 wants to merge 1 commit into
Open
Conversation
`hydra.utils.instantiate()` is called with config loaded directly from HuggingFace Hub (config.yaml supplied by the model author). A malicious model can set `_target_` to any Python callable (e.g. `os.system`, `torch.hub.load` with an attacker-controlled hubconf.py), achieving arbitrary code execution on the loading machine. Add `_validate_hydra_target()` in `relik/inference/utils.py` which rejects any `_target_` that does not start with the `relik.` prefix. Apply the guard before every `hydra.utils.instantiate()` call in: - `_instantiate_retriever()` (utils.py) - `_instantiate_index()` (utils.py) - `load_reader()` (utils.py) - `Relik.from_pretrained()` (annotator.py) - `BaseDocumentIndex.from_pretrained()` (retriever/indexers/base.py) Same vulnerability class as CVE-2025-23304 (NeMo) and CVE-2026-22584 (Uni2TS).
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.
Summary
hydra.utils.instantiate()is called in multiple places with config loaded directly from HuggingFace Hub (aconfig.yamlfully controlled by the model author). A malicious model can set_target_to any Python callable — e.g.os.system,builtins.exec, ortorch.hub.loadpointing to an attacker-controlled GitHub repo — achieving arbitrary code execution on the machine that loads the model.Affected call sites (all reachable via
Relik.from_pretrained("attacker/model")):relik/inference/utils.py_instantiate_index()relik/inference/utils.py_instantiate_retriever()relik/inference/utils.pyload_reader()relik/inference/annotator.pyRelik.from_pretrained()relik/retriever/indexers/base.pyBaseDocumentIndex.from_pretrained()Same vulnerability class as CVE-2025-23304 (NeMo) and CVE-2026-22584 (Uni2TS).
Fix
Added
_validate_hydra_target(config)inrelik/inference/utils.pythat rejects any_target_not prefixed withrelik., and called it before everyhydra.utils.instantiate()invocation in all affected files.Test plan
Relik.from_pretrained("legit/model")with a validrelik.*target continues to work_target_: os.systemraisesValueErrorbeforehydra.utils.instantiateis called_target_: torch.hub.loadraisesValueError(blocks thetorch.hub.loadACE bypass)Security Impact
CVSS 3.1: AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H = 8.8 HIGH
A user who runs
Relik.from_pretrained("attacker/model")with a malicious model executes attacker code with the privileges of the Python process.