NewApp Monitoring is liveSign up free
AgentbeamBeta
AI agent vulnerability · Transformers

CVE-2023-7018: transformers has a Deserialization of Untrusted Data vulnerability

highCVSS 3.1 7.8GHSA-v68g-wm8c-6x7j

Hugging Face transformers before 4.36.0 called pickle.load on files it fetched, in the Transformer-XL tokenizer and the legacy RAG retriever. Loading a crafted vocabulary, corpus or index file runs attacker code on your machine. Upgrade to transformers 4.36.0.

Published Dec 20, 2023 · Updated Nov 22, 2024 · Analysis Nov 2, 2026

What an attacker can do

Python pickle files can run code when loaded. The fix commit names four loaders that used pickle.load directly. In tokenization_transfo_xl.py, one reads a pretrained vocabulary file and get_lm_corpus reads a cached corpus. In retrieval_rag.py, _load_passages reads the passages file and _deserialize_index reads the index metadata file (.index_meta.dpr).

An attacker publishes a model, dataset or index repository that holds a malicious pickle in one of those files. A user who loads it with transformers runs the attacker's code. That matches the CVSS vector: local, user interaction required, high impact on all three areas. The code runs as the user, so it can reach their files, tokens and cloud credentials. In a pipeline or notebook that pulls models by name, a single poisoned repository is enough.

The fix gates each loader. It raises a ValueError unless the TRUST_REMOTE_CODE environment variable is set to True.

Who is affected

transformers on PyPI below 4.36.0. The affected code paths are the Transformer-XL tokenizer loaders and the legacy RAG retriever loaders. Other model types are not named in the commit.

Check the installed version:

pip show transformers

transformers

Ecosystem
PyPI
Affected
< 4.36.0
Fixed in
4.36.0
Check
pip show transformers

How to fix it

Upgrade to transformers 4.36.0:

pip install --upgrade "transformers>=4.36.0"

After the upgrade, the four loaders refuse to run unless TRUST_REMOTE_CODE is True. Do not set that variable globally. Set it only for a repository you trust, and when you must use these files. The Transformer-XL documentation now describes this step. Avoid Transformer-XL and legacy RAG index files from unknown sources altogether.

How to tell if you were hit

Check which models and datasets your code loads, and whether any Transformer-XL or legacy RAG retriever files came from repositories you do not control. After a suspicious load on an old version, look for unexpected child processes, new files and outbound connections from the Python process, and rotate tokens in that environment. On a patched version, a ValueError mentioning TRUST_REMOTE_CODE signals a blocked pickle load.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Deserialization of Untrusted Data in GitHub repository huggingface/transformers prior to 4.36.

Questions

Does this affect all models in transformers?

The fix commit gates only the Transformer-XL tokenizer loaders and the two legacy RAG retriever loaders. The sources do not list other models.

Is transformers 4.36.0 safe from CVE-2023-7018?

4.36.0 is the patched version. Its loaders for these files raise an error unless TRUST_REMOTE_CODE is set to True. Setting it brings the risk back for those files.

Does it need user interaction?

Yes. The CVSS vector is local with user interaction required. A user must load the malicious file.

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 entries