Executive brief
Hugging Face transformers is a widely-used Python library for building machine learning models, particularly for natural language processing tasks. The library uses an insecure method to create temporary files during model loading operations, which could allow local attackers to predict temporary file locations and potentially intercept or modify model data before it is processed.
Technical details
The vulnerability stems from the use of the deprecated `tempfile.mktemp()` function, which has a known insecure design (CWE-377). The function generates predictable temporary file names without actually creating the files, allowing race conditions where an attacker can create files at those locations before the legitimate code does. The vulnerability is present in model loading code and affects all versions prior to 4.30.0. The fix replaces `mktemp()` with the secure `mkstemp()` function, which atomically creates temporary files with restricted permissions. An attacker with local system access could exploit this during model loading operations.
Affected products
- Hugging Face transformers before 4.30.0
Timeline
- 2023-05-18: disclosed: Advisory published
- 2023-05-16: patched: Fix merged into main branch via commit 80ca92470938bbcc348e2d9cf4734c7c25cb1c43
- 2023-05-30: other: Version 4.30.0 released with fix