Skip to content

Commit

Permalink
Merge commit from fork
Browse files Browse the repository at this point in the history
* regular expression term vulnerability

* regular expression term vulnerability
  • Loading branch information
ShiyuBanzhou authored Feb 13, 2025
1 parent d9c1e8f commit bb6c4f9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function iterator(
// '<https://api.github.com/users/aseemk/followers?page=2>; rel="next", <https://api.github.com/users/aseemk/followers?page=2>; rel="last"'
// sets `url` to undefined if "next" URL is not present or `link` header is not set
url = ((normalizedResponse.headers.link || "").match(
/<([^>]+)>;\s*rel="next"/,
/<([^<>]+)>;\s*rel="next"/,
) || [])[1];

return { value: normalizedResponse };
Expand Down
32 changes: 32 additions & 0 deletions test/paginate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,38 @@ const ORG2 = { id: 2 };

const TestOctokit = Octokit.plugin(paginateRest, restEndpointMethods);
describe("pagination", () => {
it("Test ReDoS - attack string", async () => {
const ReDosOctokit = Octokit.plugin(paginateRest);
const octokit = new ReDosOctokit({
auth: "your-github-token",
});
octokit.hook.wrap("request", async (request, options) => {
const maliciousLinkHeader = "" + "<".repeat(100000) + ">";
return {
data: [],
headers: {
link: maliciousLinkHeader,
},
};
});
const startTime = performance.now();
try {
for await (const normalizedResponse of octokit.paginate.iterator(
"GET /repos/{owner}/{repo}/issues", { owner: "DayShift", repo: "ReDos", per_page: 100 }
)) {}
} catch (error) {
// pass
}
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(".paginate()", async () => {
const mock = fetchMock
.createInstance()
Expand Down

0 comments on commit bb6c4f9

Please sign in to comment.