CVE-2025-3264: Hugging Face Transformers Vulnerable to ReDoS Attack via get_imports() Function

transformers Updated 02 Oct 2025

Summary

07/07/2025
Yes i
Moderate
5.3

CVE-2025-3264: Transformers vulnerable to ReDoS attack through its get_imports() function. Affects transformers versions < 4.51.0. Fixed in 4.51.0. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

Background

The Hugging Face Transformers library is a widely-used open-source framework designed for natural language processing tasks. It provides pre-trained models and tools for building and deploying machine learning applications. However, a vulnerability has been identified in version 4.49.0 that exposes the library to Regular Expression Denial of Service (ReDoS) attacks, which can severely impact performance and availability.

Vulnerability Detail

A Regular Expression Denial of Service (ReDoS) vulnerability exists in the Hugging Face Transformers library, specifically within the get_imports() function in dynamic_module_utils.py. The vulnerability is caused by a regex pattern '\stry\s:.?except.?:' that is used to filter try/except blocks from Python code. This pattern can be exploited through crafted input strings, leading to catastrophic backtracking and excessive CPU consumption. The potential consequences include disruption of remote code loading, resource exhaustion during model serving, and possible supply chain attack vectors.

How To Fix

Latest published version: 5.20.2 as of 22 Oct 2026

pip install --upgrade "transformers==5.20.2"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

4.51.0

This is the first release that contains the fix.

pip install --upgrade "transformers==4.51.0"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If you cannot immediately upgrade the library, consider implementing input validation to restrict the types of strings that can be processed by the get_imports() function. This may help mitigate the risk of triggering the ReDoS vulnerability.

Conclusion

The Hugging Face Transformers library has a vulnerability that exposes it to ReDoS attacks through its get_imports() function. Users are advised to upgrade to version 4.51.0 or later to mitigate this risk. Implementing input validation can also serve as a temporary workaround. For ongoing monitoring, consider using Vulert to stay informed about vulnerabilities in your software.

See every vulnerability recorded for transformers →

Share this vulnerability

FAQ

A ReDoS (Regular Expression Denial of Service) attack exploits the performance issues of regular expressions, causing excessive CPU usage and potentially crashing the application.

Versions prior to 4.51.0 are affected by this vulnerability. It is recommended to upgrade to version 4.51.0 or later.

The vulnerability can lead to remote code loading disruption, resource exhaustion in model serving, and possible supply chain attacks.

You can use Vulert, which monitors and alerts for open-source vulnerabilities in real-time. You can check your application against this vulnerability using the Vulert playground without any signup.

The CVSS score for this vulnerability is 5.3, indicating a moderate severity level.

Related vulnerabilities

Recent vulnerabilities recorded for transformers.

How To Fix

Latest published version: 5.20.2 as of 22 Oct 2026

pip install --upgrade "transformers==5.20.2"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

4.51.0

This is the first release that contains the fix.

pip install --upgrade "transformers==4.51.0"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback