Fuzz testing using Jazzer.js

This commit is contained in:
Faisal Salman 2023-04-27 07:04:51 +07:00
parent a74ebeb82e
commit 3d5c70457e
3 changed files with 1992 additions and 0 deletions

1975
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -165,11 +165,13 @@
],
"scripts": {
"build": "./script/build-dist.sh && ./script/build-module.js",
"fuzz": "npx jazzer ./test/jazzer-fuzz-test.js --sync",
"test": "npm run build && ./script/test-all.sh"
},
"devDependencies": {
"@babel/parser": "7.15.8",
"@babel/traverse": "7.15.4",
"@jazzer.js/core": "^1.4.0",
"@playwright/test": "~1.32.2",
"jshint": "~2.13.6",
"mocha": "~8.2.0",

View File

@ -0,0 +1,15 @@
const UAParser = require('ua-parser-js');
module.exports.fuzz = function (buffer) {
const userAgent = buffer.toString();
const start = process.hrtime();
UAParser(userAgent);
const elapsed = process.hrtime(start);
const milisec = (elapsed[0]*1e3+elapsed[1]*1e-6).toFixed(3);
if (milisec > 1000) {
throw new Error(
`Potential ReDoS\n` +
`Time taken: ${milisec} ms.\n` +
`User agent: ${userAgent}`);
}
};