diff --git a/backend/src/controllers/v2/authController.ts b/backend/src/controllers/v2/authController.ts index 01ebcdfa07..ce2fae34fc 100644 --- a/backend/src/controllers/v2/authController.ts +++ b/backend/src/controllers/v2/authController.ts @@ -204,20 +204,16 @@ export const login2 = async (req: Request, res: Response) => { * @param res */ export const sendMfaToken = async (req: Request, res: Response) => { - const { - body: { email } - } = await validateRequest(reqValidator.SendMfaTokenV2, req); - const code = await TokenService.createToken({ type: TOKEN_EMAIL_MFA, - email + email: req.user.email }); // send MFA code [code] to [email] await sendMail({ template: "emailMfa.handlebars", subjectLine: "Infisical MFA code", - recipients: [email], + recipients: [req.user.email], substitutions: { code } @@ -236,17 +232,17 @@ export const sendMfaToken = async (req: Request, res: Response) => { */ export const verifyMfaToken = async (req: Request, res: Response) => { const { - body: { email, mfaToken } + body: { mfaToken } } = await validateRequest(reqValidator.VerifyMfaTokenV2, req); await TokenService.validateToken({ type: TOKEN_EMAIL_MFA, - email, + email: req.user.email, token: mfaToken }); const user = await User.findOne({ - email + email: req.user.email }).select( "+salt +verifier +encryptionVersion +protectedKey +protectedKeyIV +protectedKeyTag +publicKey +encryptedPrivateKey +iv +tag +devices" ); diff --git a/backend/src/routes/v2/auth.ts b/backend/src/routes/v2/auth.ts index c7aa6b066e..c24324e3fa 100644 --- a/backend/src/routes/v2/auth.ts +++ b/backend/src/routes/v2/auth.ts @@ -26,7 +26,7 @@ router.post( ); //remove above ones after depreciation -router.post("/mfa/send", authLimiter, authController.sendMfaToken); +router.post("/mfa/send", authLimiter, requireMfaAuth, authController.sendMfaToken); router.post("/mfa/verify", authLimiter, requireMfaAuth, authController.verifyMfaToken); diff --git a/backend/src/validation/auth.ts b/backend/src/validation/auth.ts index f32fc11972..071ad5e49b 100644 --- a/backend/src/validation/auth.ts +++ b/backend/src/validation/auth.ts @@ -84,15 +84,8 @@ export const ResetPasswordV1 = z.object({ }) }); -export const SendMfaTokenV2 = z.object({ - body: z.object({ - email: z.string().email().trim() - }) -}); - export const VerifyMfaTokenV2 = z.object({ body: z.object({ - email: z.string().email().trim(), mfaToken: z.string().trim() }) });