Regular Expression Denial of Service in Node.js ssri Module
Summary
CVE-2018-7651: index.js in the ssri module before 5.2.2 for Node.js is prone to a regular expression denial of service vulnerability in strict mode functionality via a long base64 hash string. Affects node-ssri across 3 version ranges.
< 0fb45e7e0eba615bf0080bf350c95e19412ff9a9
< 5.2.4-1
< d0ebcdc22cb5c8f47f89716d08b3518b2485d65d
Fixed in 5.2.4-1. How to fix ↓
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.
No signup required · Results in about 60 seconds
Background
The ssri module is a part of Node.js and is used for integrity checking of files using subresource integrity (SRI). It provides functions to generate and verify integrity hashes for files. The ssri module is widely used in various applications and packages to ensure the integrity and security of files. However, versions before 5.2.2 of the ssri module for Node.js are vulnerable to a regular expression denial of service (ReDoS) attack in strict mode functionality. This vulnerability can be exploited by providing a long base64 hash string, causing the application to consume excessive CPU resources and potentially leading to a denial of service condition.
Vulnerability Detail
The vulnerability (CVE-2018-7651) in the ssri module allows an attacker to perform a ReDoS attack by providing a long base64 hash string. When the module tries to parse the hash string in strict mode, the regular expression used for parsing becomes highly inefficient due to backtracking. This can cause the application to become unresponsive or crash, leading to a denial of service. The severity of this vulnerability is rated as moderate with a CVSS score of 5.9.
How To Fix
Minimum fixed version
5.2.4-1
This is the first release that contains the fix.
sudo apt-get install --only-upgrade node-ssri
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If updating the ssri module is not immediately possible, a temporary workaround can be implemented by validating the length of the base64 hash string before passing it to the ssri module. By enforcing a reasonable length limit for the hash string, the risk of triggering the vulnerability can be mitigated. Here is an example of how to implement this workaround in Node.js:
const ssri = require('ssri');
function validateHash(hash) {
if (hash.length > 1000) {
throw new Error('Invalid hash length');
}
}
const hash = '...'; // Base64 hash string
try {
validateHash(hash);
const integrity = ssri.parse(hash);
// Use the integrity object
} catch (error) {
// Handle validation error
}
Conclusion
The regular expression denial of service vulnerability in the ssri module for Node.js can be exploited by providing a long base64 hash string. This can lead to excessive CPU usage and potentially a denial of service condition. It is recommended to update the ssri module to version 5.2.2 or later to fix this vulnerability. If immediate update is not possible, implementing a length validation check for the hash string can provide a temporary workaround. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for node-ssri →
FAQ
The ssri module is a part of Node.js and is used for integrity checking of files using subresource integrity (SRI). It provides functions to generate and verify integrity hashes for files.
Subresource integrity (SRI) is a security feature that allows websites to ensure that the resources (such as scripts or stylesheets) they include in their pages have not been tampered with. SRI uses cryptographic hashes to verify the integrity of the resources.
The vulnerability in the ssri module can be exploited by an attacker to perform a regular expression denial of service (ReDoS) attack. By providing a long base64 hash string, the attacker can cause the application to consume excessive CPU resources and potentially lead to a denial of service condition.
A regular expression denial of service (ReDoS) attack is a type of denial of service attack that exploits the backtracking behavior of certain regular expressions. By providing a specially crafted input, an attacker can cause the regular expression matching algorithm to enter a state of exponential time complexity, leading to excessive CPU usage and potential denial of service.
The vulnerability in the ssri module can be mitigated by updating to version 5.2.2 or later, which includes a fix for the regular expression denial of service vulnerability. Additionally, implementing a length validation check for the base64 hash string before passing it to the ssri module can provide a temporary workaround to mitigate the risk.
Related vulnerabilities
Recent vulnerabilities recorded for node-ssri.