This commit is contained in:
DayShift 2025-01-20 20:02:39 +08:00
parent c957f917c1
commit a104a6eb80

View file

@ -11,16 +11,16 @@ const apicacheModule = require("../../server/modules/apicache/apicache.js");
const assert = require("node:assert");
test("Test ReDos - attack string", async (t) => {
const getDuration = apicacheModule.getDuration;
const str = "" + "00".repeat(100000) + "\u0000";
const startTime = performance.now();
try {
getDuration(str);
} catch (error) {
const getDuration = apicacheModule.getDuration;
const str = "" + "00".repeat(100000) + "\u0000";
const startTime = performance.now();
try {
getDuration(str);
} catch (error) {
// pass
}
const endTime = performance.now();
const elapsedTime = endTime - startTime;
const reDosThreshold = 9000;
assert(elapsedTime <= reDosThreshold, `🚨 Potential ReDoS Attack! getDuration method took ${elapsedTime.toFixed(2)} ms, exceeding threshold of ${reDosThreshold} ms.`);
}
const endTime = performance.now();
const elapsedTime = endTime - startTime;
const reDosThreshold = 9000;
assert(elapsedTime <= reDosThreshold, `🚨 Potential ReDoS Attack! getDuration method took ${elapsedTime.toFixed(2)} ms, exceeding threshold of ${reDosThreshold} ms.`);
});