Compare commits

...

1 Commits

Author SHA1 Message Date
Kayne Ruse db03373892 Spam attack throttling added 2023-05-15 09:13:09 +10:00
3 changed files with 29 additions and 3 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "auth-server",
"version": "1.7.4",
"version": "1.7.5",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "auth-server",
"version": "1.7.4",
"version": "1.7.5",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "auth-server",
"version": "1.7.4",
"version": "1.7.5",
"description": "An API centric auth server. Uses Sequelize and mariaDB by default.",
"main": "server/server.js",
"scripts": {
+26
View File
@@ -19,6 +19,13 @@ const route = async (req, res) => {
return res.status(401).send(validateErr);
}
//script throttle
const throttle = await checkThrottle(req.body.email);
if (throttle) {
console.warn(`Spam attack detected: ${req.body.email} (${req.body.username})`);
return res.status(401).send(throttle);
}
//generate the password hash
const hash = await bcrypt.hash(req.body.password, await bcrypt.genSalt(11));
@@ -94,6 +101,25 @@ const validateDetails = async (body) => {
return null;
};
const checkThrottle = async (email) => {
//check email delay
const prev = await pendingSignups.findOne({
where: {
email: email,
}
});
const DateOffset = ( offset ) => { //Thanks, SO!
return new Date( +new Date + offset );
}
if (!!prev && prev.updatedAt > DateOffset( -5000 )) {
return "An unknown error occurred";
}
return null;
}
const registerPendingSignup = async (body, hash, token) => {
const record = await pendingSignups.upsert({
email: body.email,