File dump from old repo

This commit is contained in:
Alexis
2021-07-18 15:48:01 +02:00
parent 1d0c7dab8b
commit c7c24a30a0
43 changed files with 7368 additions and 0 deletions

35
functions.js Normal file
View File

@@ -0,0 +1,35 @@
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
};