fix bug in blockybpass when incorrect length

merge-requests/208/head
fatchan 5 years ago
parent 644d76700f
commit da570c3fe6
  1. 16
      helpers/checks/blockbypass.js

@ -14,7 +14,7 @@ module.exports = async (req, res, next) => {
//check if blockbypass exists and right length //check if blockbypass exists and right length
const bypassId = req.cookies.bypassid; 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', { return dynamicResponse(req, res, 403, 'message', {
'title': 'Forbidden', 'title': 'Forbidden',
'message': 'Missing or invalid block bypass', '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 //try to get bypass from db and make sure uses < maxUses
let bypass; let bypass;
try { if (bypassId && bypassId.length === 24) {
const bypassMongoId = ObjectId(bypassId); try {
bypass = await Bypass.checkBypass(bypassMongoId); const bypassMongoId = ObjectId(bypassId);
res.locals.blockBypass = bypass; bypass = await Bypass.checkBypass(bypassMongoId);
} catch (err) { res.locals.blockBypass = bypass;
return next(err); } catch (err) {
return next(err);
}
} }
if (bypass && bypass.uses < blockBypass.expireAfterUses) { if (bypass && bypass.uses < blockBypass.expireAfterUses) {

Loading…
Cancel
Save