diff --git a/package-lock.json b/package-lock.json index 7f0d7c5..ba70830 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index ea8d128..b7d9e16 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/server/auth/signup.js b/server/auth/signup.js index a873a64..ea65ca6 100644 --- a/server/auth/signup.js +++ b/server/auth/signup.js @@ -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,