Skip to content

Commit

Permalink
fix: ReDos regex vulnerability, reported by @dayshift (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 authored Feb 15, 2025
1 parent 5b84386 commit e1e4489
Show file tree
Hide file tree
Showing 2 changed files with 39 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
38 changes: 38 additions & 0 deletions test/paginate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ 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 () => {
const maliciousLinkHeader = "" + "<".repeat(100000) + ">";
return {
data: [],
headers: {
link: maliciousLinkHeader,
},
status: 200,
url: "",
};
});
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 },
)) {
normalizedResponse;
}
} 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
.sandbox()
Expand Down

0 comments on commit e1e4489

Please sign in to comment.