CVE-2020-7753: Regular Expression Denial of Service in trim

trim Updated 02 Oct 2025

Summary

10/05/2021
Yes i
High
7.5

CVE-2020-7753: Regular Expression Denial of Service in trim. Affects trim versions < 0.0.3. Fixed in 0.0.3. 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 MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

Background

The 'trim' package is an npm package that provides a utility function for trimming whitespace from strings. It is commonly used in JavaScript applications to remove leading and trailing spaces from user input or other string values. The package is vulnerable to a Regular Expression Denial of Service (ReDoS) attack in its 'trim()' function. This vulnerability affects all versions of the package prior to version 0.0.3.

Vulnerability Detail

The Regular Expression Denial of Service (ReDoS) vulnerability in the 'trim' package allows an attacker to exploit the regular expression used in the 'trim()' function to cause a denial of service (DoS) condition. By providing a specially crafted input string, an attacker can trigger excessive backtracking in the regular expression engine, leading to a significant increase in CPU usage and potentially causing the application to become unresponsive. This vulnerability has a CVSS score of 7.5, indicating a high severity.

How To Fix

Latest published version: 1.0.1 as of 23 Oct 2026

npm install trim@1.0.1

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

If you need the minimum change

0.0.3

This is the first release that contains the fix.

npm install trim@0.0.3

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

Workaround

If upgrading to the fixed version is not immediately possible, developers can implement a workaround by manually modifying the 'trim()' function in their code. One possible workaround is to replace the regular expression used in the 'trim()' function with a simpler and more efficient implementation that does not suffer from the ReDoS vulnerability. Here is an example of a modified 'trim()' function:

function trim(str) {
  return str.replace(/^\s+|\s+$/g, '');
}

Conclusion

The 'trim' package is vulnerable to a Regular Expression Denial of Service (ReDoS) attack in its 'trim()' function. This vulnerability can be mitigated by upgrading to version 0.0.3 or later of the package. If immediate upgrade is not possible, developers can implement a workaround by modifying the 'trim()' function in their code. It is important to promptly address this vulnerability to prevent potential denial of service attacks. For further support or assistance, please contact DevNack.com.

See every vulnerability recorded for trim →

Share this vulnerability

FAQ

This vulnerability allows an attacker to cause a denial of service (DoS) condition in applications that use the 'trim' package. By exploiting the ReDoS vulnerability, an attacker can consume excessive CPU resources, potentially leading to application slowdown or unresponsiveness.

To determine if your application is affected by this vulnerability, you can use the Vulert Playground at Vulert Scanner. Simply upload your package-lock.json file to the playground, and it will check if your application is vulnerable to this specific issue.

At the time of this report, there are no known public exploits specifically targeting this vulnerability in the 'trim' package. However, it is important to promptly address this vulnerability to mitigate the risk of potential future exploits.

While upgrading to the fixed version of the 'trim' package is the recommended solution, developers can implement a workaround by modifying the 'trim()' function in their code. The provided workaround replaces the vulnerable regular expression with a simpler implementation that avoids the ReDoS vulnerability.

For further support or assistance in addressing this vulnerability, you can contact info@devnack.com. The DevNack team can provide guidance on vulnerability remediation and answer any additional questions you may have.

How To Fix

Latest published version: 1.0.1 as of 23 Oct 2026

npm install trim@1.0.1

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

If you need the minimum change

0.0.3

This is the first release that contains the fix.

npm install trim@0.0.3

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