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

CVE-2025-5197: Hugging Face Transformers Regular Expression Denial of Service (ReDoS) vulnerability

mediumCVSS 3.0 5.3GHSA-9356-575x-2w9m

The Hugging Face Transformers function `convert_tf_weight_name_to_pt_weight_name()` uses the regex `/[^/]*___([^/]*)/`, which backtracks catastrophically on crafted names. A long weight name can pin a CPU during TensorFlow-to-PyTorch conversion. Versions before 4.53.0 are affected, and 4.53.0 fixes it. Impact is limited to availability.

Published Aug 6, 2025 · Analysis Nov 1, 2026

What an attacker can do

The function converts TensorFlow weight names to PyTorch names in modeling_tf_pytorch_utils.py. It applies the regular expression /[^/]*___([^/]*)/ with re.sub. On a long name with many ___ separators the regex engine backtracks, so CPU time grows far faster than input length. One crafted name can hold a core for a very long time.

The attacker must be able to supply the weight names, for example through a TensorFlow checkpoint or model file that a service converts, or an API that exposes model conversion. No authentication or user action is needed in that setup (CVSS PR:N/UI:N). The result is service disruption and resource exhaustion, scored as low availability impact. The sources describe no data exposure or code execution. Services that never convert TensorFlow checkpoints do not reach the function.

Who is affected

The transformers pip package before 4.53.0, in code paths that load TensorFlow weights into PyTorch models (for example from_pretrained(..., from_tf=True)) or call the conversion helper directly. The advisory says versions up to 4.51.3 are affected. Check:

pip show transformers

Search your code for from_tf=True and convert_tf_weight_name_to_pt_weight_name, and note whether untrusted checkpoints reach them.

transformers

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

How to fix it

Upgrade to transformers 4.53.0:

pip install --upgrade "transformers>=4.53.0"

The fix adds a guard before the re.sub call, labelled "ReDOS check". It raises a ValueError with the message "TF variable name is too long or contains too many ___ separators" for names that are over 2048 characters and contain ___, or that contain ___ more than 10 times. The sources list no workaround. Until you upgrade, avoid converting TensorFlow checkpoints from untrusted sources.

How to tell if you were hit

Look for conversion jobs or workers that sit at 100% CPU for a long time during TensorFlow-to-PyTorch loading, and for timeouts in services that expose model conversion. In patched versions, a rejected name logs the ValueError text "TF variable name is too long or contains too many ___ separators". Inspect the checkpoint in question for variable names with very long strings or many triple underscores.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

A Regular Expression Denial of Service (ReDoS) vulnerability exists in the Hugging Face Transformers library, specifically in the convert_tf_weight_name_to_pt_weight_name() function. This function, responsible for converting TensorFlow weight names to PyTorch format, uses a regex pattern /[^/]*___([^/]*)/ that can be exploited to cause excessive CPU consumption through crafted input strings due to catastrophic backtracking. The vulnerability affects versions up to 4.51.3 and is fixed in version 4.53.0. This issue can lead to service disruption, resource exhaustion, and potential API service vulnerabilities, impacting model conversion processes between TensorFlow and PyTorch formats.

Questions

Which Transformers version fixes CVE-2025-5197?

4.53.0. The advisory text says versions up to 4.51.3 are affected, and the package data lists everything before 4.53.0.

Am I affected if I only use PyTorch weights?

The flawed function converts TensorFlow weight names, so code that only loads PyTorch or safetensors weights does not normally call it. Check for from_tf=True in your code.

Can this lead to code execution?

No. The sources describe only excessive CPU use from regex backtracking, with low availability impact in the CVSS vector.

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