Skip to content

Commit

Permalink
fix: mitigate ReDos vulnerabilities & lint (#738)
Browse files Browse the repository at this point in the history
Releases 34ff07e
* Linting issues
* update `@octokit/endpoint` and `@octokit/request-error`
  • Loading branch information
nickfloyd authored Feb 13, 2025
1 parent 34ff07e commit 6bb29ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
27 changes: 10 additions & 17 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 @@ -25,8 +25,8 @@
"author": "Gregor Martynus (https://github.com/gr2m)",
"license": "MIT",
"dependencies": {
"@octokit/endpoint": "^10.0.0",
"@octokit/request-error": "^6.0.1",
"@octokit/endpoint": "^10.1.3",
"@octokit/request-error": "^6.1.6",
"@octokit/types": "^13.6.2",
"fast-content-type-parse": "^2.0.0",
"universal-user-agent": "^7.0.2"
Expand Down
17 changes: 10 additions & 7 deletions test/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,29 @@ 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 fakeFetch = async (url, options) => {
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
headers: fakeHeaders,
});
};
const startTime = performance.now();
request("GET /repos/octocat/hello-world");
request("GET /repos/octocat/hello-world", {
request: { fetch: fakeFetch },
});
const endTime = performance.now();
const elapsedTime = endTime - startTime;
const reDosThreshold = 2000;
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.`);
console.warn(
`🚨 Potential ReDoS Attack! getDuration method took ${elapsedTime.toFixed(2)} ms, exceeding threshold of ${reDosThreshold} ms.`,
);
}
});

Expand Down

0 comments on commit 6bb29ba

Please sign in to comment.