This repository has been archived on 2026-06-29. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
auracle-api/functions.js
2021-07-18 15:48:01 +02:00

35 lines
813 B
JavaScript

const regexInt = RegExp(/^[1-9]\d*$/);
const regexXSS = RegExp(/<[^>]*script/);
// Check if int for param validation
const paramIntCheck = (req, res, next, input) => {
try {
if (regexInt.test(input)) {
next();
} else {
throw new Error;
}
} catch (err) {
res.status(err.code).send(JSON.stringify({
"message": "Le paramètre doit être un entier non-nul.",
"code": 403,
})
);
}
};
// Check if script injection attempt
const isXSSAttempt = (string) => {
return regexXSS.test(string);
};
// Check if object is null
const isEmptyObject = (obj) => {
return (Object.keys(obj).length === 0 && obj.constructor === Object);
};
module.exports = {
paramIntCheck,
isXSSAttempt,
isEmptyObject
};