Skip to content

Commit

Permalink
Merge commit from fork
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiyuBanzhou authored Feb 13, 2025
1 parent a0e96b3 commit 34ff07e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fetch-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default async function fetchWrapper(
if ("deprecation" in responseHeaders) {
const matches =
responseHeaders.link &&
responseHeaders.link.match(/<([^>]+)>; rel="deprecation"/);
responseHeaders.link.match(/<([^<>]+)>; rel="deprecation"/);
const deprecationLink = matches && matches.pop();
log.warn(
`[@octokit/request] "${requestOptions.method} ${
Expand Down
24 changes: 24 additions & 0 deletions test/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ function stringToArrayBuffer(str: string) {
}

describe("request()", () => {
it("Test ReDoS - attack string", () => {
const originalFetch = globalThis.fetch;
globalThis.fetch = async (url, options) => {
const response = await originalFetch(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");
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 34ff07e

Please sign in to comment.