A critical security vulnerability has been identified in the Hugging Face Transformers library, a cornerstone in the machine learning community. This flaw, designated as CVE-2026-4372, enables remote code execution (RCE) through the manipulation of model configuration files, posing a significant threat to developers, enterprises, and AI systems worldwide.
Understanding the Vulnerability
The root of this vulnerability lies in the library’s handling of untrusted data within model configuration files, particularly the `_attn_implementation_internal` attribute. By injecting this field into a model’s `config.json`, attackers can compel the library to load and execute arbitrary Python code during the standard model loading process. Alarmingly, this execution occurs even when the security parameter `trust_remote_code=False` is set, effectively circumventing a primary safeguard.
Scope and Impact
This issue affects Transformers versions 4.56.0 through 5.2.x when used in conjunction with the optional `kernels` package. Introduced in August 2025, the vulnerability remained exploitable until its patch in March 2026, leaving a six-month window during which users loading malicious models from the Hugging Face Hub via the `from_pretrained()` function were at risk.
In a typical attack scenario, a malicious actor uploads a seemingly legitimate model to the Hugging Face Hub, embedding a crafted `config.json` file containing the malicious `_attn_implementation_internal` field. This field references an attacker-controlled repository. When an unsuspecting user loads the model, the Transformers library automatically downloads and imports the referenced code without proper validation or sandboxing, leading to immediate code execution on the victim’s system.
The consequences of such exploitation are severe. Attackers can gain access to sensitive data, including AWS credentials, SSH keys, API tokens, and environment variables. They can establish persistence mechanisms, facilitate lateral movement across infrastructure, and potentially compromise CI/CD pipelines. Given that the attack occurs during the normal model loading process without any warnings or visible indicators, detection becomes exceedingly challenging.
Scale of Exposure
The Hugging Face Transformers library boasts over 2.2 billion installations and processes approximately 146 million downloads monthly. With more than one million models hosted on the Hugging Face Hub, the potential attack surface is vast. During the vulnerability’s exposure period, an estimated 232 million installations were susceptible, significantly increasing the likelihood of real-world exploitation.
Broader Implications
This vulnerability underscores a pervasive issue within machine learning ecosystems: the implicit trust placed in model files and configurations. Similar patterns have been observed in other frameworks, where safe modes fail to prevent code execution due to unaccounted internal pathways. This incident serves as a stark reminder of the necessity for rigorous validation and sandboxing mechanisms when handling external model files.
Mitigation and Recommendations
In response to the discovery, Hugging Face released version 5.3.0 of the Transformers library, addressing the vulnerability by blocking unsafe internal attributes during configuration parsing and enforcing stricter controls on kernel loading. The update also ensures that external code execution requires explicit user consent.
Users are strongly advised to upgrade to the latest version of the Transformers library immediately. Additionally, organizations should implement the following measures to mitigate potential risks:
1. Review and Audit Models: Conduct thorough reviews of all models, especially those sourced from external repositories, to identify and remove any malicious configurations.
2. Enhance Security Controls: Implement robust security controls, including sandboxing and strict validation mechanisms, to prevent unauthorized code execution.
3. Monitor and Log Activities: Establish comprehensive monitoring and logging practices to detect unusual activities during model loading and execution processes.
4. Educate and Train Personnel: Provide training for developers and data scientists on secure coding practices and the importance of scrutinizing external models and configurations.
Conclusion
The CVE-2026-4372 vulnerability in the Hugging Face Transformers library highlights the critical need for vigilance and proactive security measures in the rapidly evolving field of machine learning. By promptly updating to the latest library version and implementing stringent security protocols, organizations can safeguard their AI systems against potential exploitation and maintain the integrity of their machine learning operations.