HuggingFace Transformers allows for arbitrary code execution in the `Trainer` class
The Trainer class in HuggingFace Transformers loads a checkpoint file using torch.load without the weights_only=True parameter, allowing arbitrary code execution. An attacker can supply a malicious checkpoint file that executes code when loaded.
huggingface/transformers
Originally disclosed on huntr
A vulnerability in the HuggingFace Transformers library, specifically in the Trainer class, allows for arbitrary code execution. The _load_rng_state() method in src/transformers/trainer.py at line 3059 calls torch.load() without the weights_only=True parameter. This issue affects all versions of the library supporting torch>=2.2 when used with PyTorch versions below 2.6, as the safe_globals() context manager provides no protection in these versions. An attacker can exploit this vulnerability by supplying a malicious checkpoint file, such as rng_state.pth, which can execute arbitrary code when loaded. The issue is resolved in version v5.0.0rc3.
From the GitHub Advisory Database (GHSA-69w3-r845-3855, CC BY 4.0).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could execute arbitrary code on the machine running the Trainer if they can supply a malicious checkpoint file.
What the attacker needed
Ability to supply a malicious checkpoint file
The fix
The issue was fixed in version v5.0.0rc3.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program loads a file, it should treat the file as data, not as instructions. Here, the library used a loading function that can also run code embedded in the file. So a malicious file could run commands on the victim's machine.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.