Transformers save_pretrained path traversal allows arbitrary file writes through chat template names
The save_pretrained methods of PreTrainedTokenizerBase and ProcessorMixin used keys from the chat_template dictionary as filenames without validation. An attacker could publish a malicious Hub repository whose tokenizer_config.json contained crafted keys that escaped the save directory, allowing arbitrary file writes with attacker-controlled content when a victim downloaded and saved the tokenizer or processor.
huggingface/transformers
Originally disclosed on huntr
A vulnerability in huggingface/transformers versions < 5.10.0 allows an attacker to perform arbitrary file writes via path traversal. The issue resides in the save_pretrained() methods of PreTrainedTokenizerBase and ProcessorMixin, where keys from the chat_template dictionary are used directly as filenames without proper validation. An attacker can exploit this by publishing a malicious Hugging Face Hub repository with a crafted tokenizer_config.json file. When a victim downloads and saves the tokenizer or processor, the attacker-controlled keys can escape the intended save directory, enabling arbitrary file writes with attacker-controlled content. This vulnerability affects multiple processors inheriting from ProcessorMixin, including Idefics, Florence, Gemma, Phi, and Qwen-VL.
From the GitHub Advisory Database (GHSA-xrqw-3rrv-vx5w, 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 write arbitrary files with attacker-controlled content outside the intended save directory on a victim's machine.
What the attacker needed
Victim downloads a malicious Hub repository; victim saves the tokenizer or processor
The fix
The issue was fixed in version 5.10.0, which validates chat_template keys before using them as filenames.
How it was found
- Publish a malicious Hugging Face Hub repository containing a crafted tokenizer_config.json.
- Have the victim download the tokenizer or processor from that repository.
- The victim saves the tokenizer or processor, and the crafted keys cause files to be written outside the intended directory.
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 you download a model or tokenizer from a hub, the library saves some files to your disk. This report says the library trusted names inside a configuration file to decide where to write those files, so a malicious publisher could make it write outside the intended folder. That means a downloaded file could overwrite other files on your computer with content the attacker chose.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.