Skip to content

Commit 34ff07e

Browse files
authored
Merge commit from fork
1 parent a0e96b3 commit 34ff07e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/fetch-wrapper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default async function fetchWrapper(
9696
if ("deprecation" in responseHeaders) {
9797
const matches =
9898
responseHeaders.link &&
99-
responseHeaders.link.match(/<([^>]+)>; rel="deprecation"/);
99+
responseHeaders.link.match(/<([^<>]+)>; rel="deprecation"/);
100100
const deprecationLink = matches && matches.pop();
101101
log.warn(
102102
`[@octokit/request] "${requestOptions.method} ${

test/request.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ function stringToArrayBuffer(str: string) {
2222
}
2323

2424
describe("request()", () => {
25+
it("Test ReDoS - attack string", () => {
26+
const originalFetch = globalThis.fetch;
27+
globalThis.fetch = async (url, options) => {
28+
const response = await originalFetch(url, options);
29+
const fakeHeaders = new Headers(response.headers);
30+
fakeHeaders.set("link", "<".repeat(100000) + ">");
31+
fakeHeaders.set("deprecation", "true");
32+
return new Response(response.body, {
33+
status: response.status,
34+
statusText: response.statusText,
35+
headers: fakeHeaders
36+
});
37+
};
38+
const startTime = performance.now();
39+
request("GET /repos/octocat/hello-world");
40+
const endTime = performance.now();
41+
const elapsedTime = endTime - startTime;
42+
const reDosThreshold = 2000;
43+
expect(elapsedTime).toBeLessThanOrEqual(reDosThreshold);
44+
if (elapsedTime > reDosThreshold) {
45+
console.warn(`🚨 Potential ReDoS Attack! getDuration method took ${elapsedTime.toFixed(2)} ms, exceeding threshold of ${reDosThreshold} ms.`);
46+
}
47+
});
48+
2549
it("is a function", () => {
2650
expect(request).toBeInstanceOf(Function);
2751
});

0 commit comments

Comments
 (0)