CVE-2026-9856: Transformers save_pretrained path traversal allows arbitrary file writes through chat template names
Hugging Face transformers before 5.10.0 can write files outside the target directory when you call save_pretrained() on a tokenizer or processor loaded from a malicious Hub repo. Chat template names from tokenizer_config.json become filenames unchecked, so a name like a parent-directory path escapes the save folder. Upgrade to transformers 5.10.0.
Published Aug 2, 2026 · Updated Sep 1, 2026 · Analysis Nov 23, 2026
What an attacker can do
The legacy chat_template format in tokenizer_config.json is a list of dicts, and each entry's name becomes a dictionary key. save_pretrained() in PreTrainedTokenizerBase and ProcessorMixin joined that key with a .jinja extension and wrote the file into the chat template directory. A name such as ../../foo escaped the directory, and the file content was the attacker's template text.
The attacker publishes a Hub repository with a crafted tokenizer_config.json and waits for someone to load it and save a copy. That is a routine step when fine-tuning, converting, caching or re-publishing a model. The victim must run the save, so user interaction is required. The attacker controls the file path and content, but the filename ends in .jinja, so reach is bounded by that suffix. Writing into a startup, plugin or template location the process can touch is the risk. It also affects processors built on ProcessorMixin, including Idefics, Florence, Gemma, Phi and Qwen-VL. Pipelines that pull community models automatically, such as CI jobs and model-conversion services, are most exposed.
Who is affected
pip package transformers before 5.10.0. The flaw is reached only when code calls save_pretrained() on a tokenizer or processor whose configuration came from an untrusted source. Loading alone does not write the file. Check the installed version:
pip show transformersAlso check lock files and container images that pin an older release.
transformers
- Ecosystem
- PyPI
- Affected
- < 5.10.0
- Fixed in
- 5.10.0
- Check
pip show transformers
How to fix it
Upgrade to transformers 5.10.0:
pip install --upgrade transformers==5.10.0The fix (pull request 46191) rejects chat template names whose resolved path escapes chat_template_dir. The check runs before the file is opened, in both PreTrainedTokenizerBase.save_pretrained and ProcessorMixin.save_pretrained. The sources give no other workaround. Until you upgrade, avoid saving tokenizers or processors from untrusted repositories, or save into a sandboxed, disposable directory.
How to tell if you were hit
Inspect the tokenizer_config.json of models you saved or republished for chat_template entries whose name contains path separators or parent-directory sequences. Search the file system for unexpected .jinja files outside your model directories, created around the time of a save. File-write auditing on conversion and CI hosts shows writes that escape the output folder. The sources report no exploitation in the wild.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
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.
Questions
- Does loading a model from the Hub trigger CVE-2026-9856?
No. The write happens when you call save_pretrained() on the tokenizer or processor. Loading alone only reads the crafted configuration. Saving it is the step that writes the file.
- What can an attacker write?
Files with attacker-controlled content at a path they choose relative to the save directory. Names get a .jinja suffix, which limits what the file can be used for.
- Which transformers version fixes it?
5.10.0. It rejects template names that resolve outside chat_template_dir, in both the tokenizer and the processor save methods.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
More Transformers vulnerabilities
All Transformers entriesCVE-2026-80047
Hugging Face Transformers downloads custom generation code before trust consent
high7.8No fixSep 1, 2026CVE-2026-5241
huggingface/transformers: Arbitrary Code Execution During Model Initialization in the LightGlue Model Loading Path
high8.0Jun 3, 2026CVE-2026-4372
HuggingFace transformers vulnerable to remote code execution
high7.8May 26, 2026CVE-2026-1839
HuggingFace Transformers allows for arbitrary code execution in the `Trainer` class
medium6.5Apr 7, 2026CVE-2025-6921
Hugging Face Transformers vulnerable to Regular Expression Denial of Service (ReDoS) in the AdamWeightDecay optimizer
medium5.3Sep 23, 2025CVE-2025-6051
Hugging Face Transformers library has Regular Expression Denial of Service
medium5.3Sep 14, 2025
