Import the endpoint module: First, import the endpoint module from the npm package @octokit/endpoint, which is used for handling GitHub API requests.
Construct the options object that triggers a ReDoS attack: The following member variables are critical in constructing the options object:
url: Set to "/graphql", ensuring the URL ends with /graphql to match the format for GitHub's GraphQL API.headers:
accept: A long attack string is crafted with"A".repeat(100000) + "-", which will be passed to the regular expression and cause a backtracking attack (ReDoS).
mediaType:
previews: Set to["test-preview"], ensuringmediaType.previewsexists and has values.
format: Set to"raw", indicating raw data format.
Call the endpoint.parse(options) function and record the time: Call the endpoint.parse(options) function and use performance.now() to record the start and end times, measuring the execution duration.
Calculate the time difference and output it: Compute the difference between the start and end times and output it using console.log. When the attack string length reaches 100000, the response time typically exceeds 10000 milliseconds, satisfying the characteristic condition for a ReDoS attack, where response times dramatically increase.
This is a Regular Expression Denial of Service (ReDoS) vulnerability. It arises from inefficient regular expressions that can cause excessive backtracking when processing certain inputs. Specifically, the regular expression /[\w-]+(?=-preview)/g is vulnerable because it attempts to match long strings of characters followed by a hyphen (-), which leads to inefficient backtracking when provided with specially crafted attack strings. This backtracking results in high CPU utilization, causing the application to become unresponsive and denying service to legitimate users.
This vulnerability impacts any application that uses the affected regular expression in conjunction with user-controlled inputs, particularly where large or maliciously crafted strings can trigger excessive backtracking.
In addition to directly affecting applications using the @octokit/endpoint package, the impact is more widespread because @octokit/endpoint is a library used to wrap REST APIs, including GitHub's API. This means that any system or service built on top of this library that interacts with GitHub or other REST APIs could be vulnerable. Given the extensive use of this package in API communication, the potential for exploitation is broad and serious. The vulnerability could affect a wide range of applications, from small integrations to large enterprise-level systems, especially those relying on the package to handle API requests.
Attackers can exploit this vulnerability to cause performance degradation, downtime, and service disruption, making it a critical issue for anyone using the affected version of @octokit/endpoint.
To resolve the ReDoS vulnerability, the regular expression should be updated to avoid excessive backtracking. By modifying the regular expression to (?<![\w-])[\w-]+(?=-preview), we prevent the issue.
Here is how this change solves the problem:
Here is how this change solves the problem:
/[\w-]+(?=-preview)/g\w) and hyphens (-) followed by -preview.-, causing excessive backtracking and high CPU usage.(?<![\w-])[\w-]+(?=-preview)(?<![\w-]), ensuring that the matched string is not preceded by any word characters or hyphens (\w or -).The specific code is located at the following link: https://github.com/octokit/endpoint.js/blob/main/src/parse.ts, at line 62:
parse.ts file (or wherever the original regex is defined), replace the existing regular expression:const previewsFromAcceptHeader =
headers.accept.match(/[\w-]+(?=-preview)/g) || ([] as string[]);
With the updated one:
const previewsFromAcceptHeader =
headers.accept.match(/(?<![\w-])[\w-]+(?=-preview)/g) || ([] as string[]);
| Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
|---|---|---|---|
| @octokit/endpoint | npm | >= 9.0.5, < 9.0.6 | 9.0.6 |
| @octokit/endpoint | npm | >= 10.0.0, < 10.1.3 | 10.1.3 |
KEV Misses 88% of Exploited CVEs- Get the report