Skip to content

Commit

Permalink
fix: linting issues breaking ci (#514)
Browse files Browse the repository at this point in the history
fixes linting issues
  • Loading branch information
nickfloyd authored Feb 13, 2025
1 parent 6c9c5be commit d6cf1ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export function parse(options: EndpointDefaults): RequestOptions {
if (url.endsWith("/graphql")) {
if (options.mediaType.previews?.length) {
const previewsFromAcceptHeader =
headers.accept.match(/(?<![\w-])[\w-]+(?=-preview)/g) || ([] as string[]);
headers.accept.match(/(?<![\w-])[\w-]+(?=-preview)/g) ||
([] as string[]);
headers.accept = previewsFromAcceptHeader
.concat(options.mediaType.previews!)
.map((preview) => {
Expand Down
20 changes: 13 additions & 7 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ describe("endpoint.parse()", () => {
}
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 All @@ -105,11 +107,13 @@ describe("endpoint.parse()", () => {
}
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 All @@ -118,7 +122,7 @@ describe("endpoint.parse()", () => {
try {
endpoint.parse({
method: "POST",
url: "{"+"00"+"\u0000".repeat(100000)+"a!a"+"}", // Pass in the attack string
url: "{" + "00" + "\u0000".repeat(100000) + "a!a" + "}", // Pass in the attack string
headers: {
accept: "application/vnd.github.v3+json",
"content-type": "text/plain",
Expand All @@ -135,11 +139,13 @@ describe("endpoint.parse()", () => {
}
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.`,
);
}
});
});

0 comments on commit d6cf1ad

Please sign in to comment.