mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
Fuzz testing using Jazzer.js
This commit is contained in:
parent
a74ebeb82e
commit
3d5c70457e
1975
package-lock.json
generated
1975
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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",
|
||||
|
15
test/jazzer-test-fuzzing.js
Normal file
15
test/jazzer-test-fuzzing.js
Normal 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}`);
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user