Skip to content

Commit

Permalink
fix: ReDos regex vulnerability, reported by @dayshift (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 authored Feb 15, 2025
1 parent abc4955 commit 356411e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
18 changes: 10 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"author": "Gregor Martynus (https://github.com/gr2m)",
"license": "MIT",
"dependencies": {
"@octokit/endpoint": "^9.0.1",
"@octokit/request-error": "^5.1.0",
"@octokit/endpoint": "^9.0.6",
"@octokit/request-error": "^5.1.1",
"@octokit/types": "^13.1.0",
"universal-user-agent": "^6.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/fetch-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function fetchWrapper(

if ("deprecation" in headers) {
const matches =
headers.link && headers.link.match(/<([^>]+)>; rel="deprecation"/);
headers.link && headers.link.match(/<([^<>]+)>; rel="deprecation"/);
const deprecationLink = matches && matches.pop();
log.warn(
`[@octokit/request] "${requestOptions.method} ${
Expand Down
27 changes: 27 additions & 0 deletions test/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ const userAgent = `octokit-request.js/0.0.0-development ${getUserAgent()}`;
const stringToArrayBuffer = require("string-to-arraybuffer");

describe("request()", () => {
it("Test ReDoS - attack string", () => {
const fakeFetch = async (url: string, options?: RequestInit) => {
const response = await fetch(url, options);
const fakeHeaders = new Headers(response.headers);
fakeHeaders.set("link", "<".repeat(100000) + ">");
fakeHeaders.set("deprecation", "true");
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: fakeHeaders,
});
};
const startTime = performance.now();
request("GET /repos/octocat/hello-world", {
request: { fetch: fakeFetch },
});
const endTime = performance.now();
const elapsedTime = endTime - startTime;
const reDosThreshold = 2000;
expect(elapsedTime).toBeLessThanOrEqual(reDosThreshold);
if (elapsedTime > reDosThreshold) {
console.warn(
`🚨 Potential ReDoS Attack! getDuration method took ${elapsedTime.toFixed(2)} ms, exceeding threshold of ${reDosThreshold} ms.`,
);
}
});

it("is a function", () => {
expect(request).toBeInstanceOf(Function);
});
Expand Down

0 comments on commit 356411e

Please sign in to comment.