From 3552232e995be7b0b9361e2e420150e53075d00a Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Thu, 19 Jan 2023 13:42:51 +0100 Subject: [PATCH] Support 2fa for proxy auth --- src/proxyauth.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/proxyauth.js b/src/proxyauth.js index 0ce1ad95a..e9c5bb69e 100644 --- a/src/proxyauth.js +++ b/src/proxyauth.js @@ -15,6 +15,7 @@ const apps = require('./apps.js'), debug = require('debug')('box:proxyAuth'), ejs = require('ejs'), express = require('express'), + externalLdap = require('./externalLdap.js'), hat = require('./hat.js'), http = require('http'), HttpError = require('connect-lastmile').HttpError, @@ -170,8 +171,13 @@ async function passwordAuth(req, res, next) { if (!user.ghost && !user.appPassword && user.twoFactorAuthenticationEnabled) { if (!totpToken) return next(new HttpError(403, 'A totpToken must be provided')); - let verified = speakeasy.totp.verify({ secret: user.twoFactorAuthenticationSecret, encoding: 'base32', token: req.body.totpToken, window: 2 }); - if (!verified) return next(new HttpError(403, 'Invalid totpToken')); + if (user.source === 'ldap') { + const [error] = await safe(externalLdap.verifyPasswordAndTotpToken(user, password, totpToken)); + if (error) return next(new HttpError(401, 'Invalid totpToken')); + } else { + const verified = speakeasy.totp.verify({ secret: user.twoFactorAuthenticationSecret, encoding: 'base32', token: req.body.totpToken, window: 2 }); + if (!verified) return next(new HttpError(401, 'Invalid totpToken')); + } } req.user = user;