From da570c3fe6f3c613187ba0956daceaed26fcb2a1 Mon Sep 17 00:00:00 2001 From: fatchan Date: Wed, 12 Feb 2020 21:21:48 +1100 Subject: [PATCH] fix bug in blockybpass when incorrect length --- helpers/checks/blockbypass.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/helpers/checks/blockbypass.js b/helpers/checks/blockbypass.js index fed0cce9..b6722428 100644 --- a/helpers/checks/blockbypass.js +++ b/helpers/checks/blockbypass.js @@ -14,7 +14,7 @@ module.exports = async (req, res, next) => { //check if blockbypass exists and right length const bypassId = req.cookies.bypassid; - if ((!bypassId || bypassId.length !== 24) && !res.locals.solvedCaptcha) { + if (!res.locals.solvedCaptcha && (!bypassId || bypassId.length !== 24)) { return dynamicResponse(req, res, 403, 'message', { 'title': 'Forbidden', 'message': 'Missing or invalid block bypass', @@ -25,12 +25,14 @@ module.exports = async (req, res, next) => { //try to get bypass from db and make sure uses < maxUses let bypass; - try { - const bypassMongoId = ObjectId(bypassId); - bypass = await Bypass.checkBypass(bypassMongoId); - res.locals.blockBypass = bypass; - } catch (err) { - return next(err); + if (bypassId && bypassId.length === 24) { + try { + const bypassMongoId = ObjectId(bypassId); + bypass = await Bypass.checkBypass(bypassMongoId); + res.locals.blockBypass = bypass; + } catch (err) { + return next(err); + } } if (bypass && bypass.uses < blockBypass.expireAfterUses) {