From 515051dabf9f2a145ae2d090f829df7188e9fd28 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Sat, 26 Oct 2024 03:28:45 -0400 Subject: [PATCH] fix: continue work on blocked_email_domains --- src/backend/src/routers/save_account.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/backend/src/routers/save_account.js b/src/backend/src/routers/save_account.js index bb33b5fd..929b0e10 100644 --- a/src/backend/src/routers/save_account.js +++ b/src/backend/src/routers/save_account.js @@ -24,6 +24,7 @@ const auth = require('../middleware/auth.js'); const config = require('../config'); const { Context } = require('../util/context'); const { DB_WRITE } = require('../services/database/consts'); +const { can } = require('../util/langutil.js'); // -----------------------------------------------------------------------// // POST /save_account @@ -70,6 +71,17 @@ router.post('/save_account', auth, express.json(), async (req, res, next)=>{ else if(req.body.password.length < config.min_pass_length) return res.status(400).send(`Password must be at least ${config.min_pass_length} characters long.`) + const svc_cleanEmail = req.services.get('clean-email') + const clean_email = svc_cleanEmail.clean(req.body.email); + + if ( can(config.blocked_email_domains, 'iterate') ) { + for ( const suffix of config.blocked_email_domains ) { + if ( clean_email.endsWith(suffix) ) { + return res.status(400).send('This email domain is not allowed.'); + } + } + } + const svc_edgeRateLimit = req.services.get('edge-rate-limit'); if ( ! svc_edgeRateLimit.check('save-account') ) { return res.status(429).send('Too many requests.');