mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-30 17:27:44 +03:00
Fuzz testing using Jazzer.js
This commit is contained in:
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}`);
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user