From ebebf45d7b6181a2cac965d6d636f536b1f239c3 Mon Sep 17 00:00:00 2001 From: HF Date: Thu, 18 Mar 2021 00:03:19 +0100 Subject: [PATCH] make captcha case inensitive and l = i and 0 = 0 --- src/utils/captcha.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/utils/captcha.js b/src/utils/captcha.js index bd7e97a..96fdc32 100644 --- a/src/utils/captcha.js +++ b/src/utils/captcha.js @@ -14,6 +14,14 @@ import { const TTL_CACHE = CAPTCHA_TIME * 60; // seconds +function captchaTextFilter(text: string) { + let ret = text.toString('utf8'); + ret = ret.split('l').join('i'); + ret = ret.split('0').join('O'); + ret = ret.toLowerCase(); + return ret; +} + /* * set captcha solution * @@ -26,7 +34,7 @@ export function setCaptchaSolution( ip: string, ) { const key = `capt:${ip}`; - return redis.setAsync(key, text, 'EX', CAPTCHA_TIMEOUT); + return redis.setAsync(key, captchaTextFilter(text), 'EX', CAPTCHA_TIMEOUT); } /* @@ -44,9 +52,9 @@ export async function checkCaptchaSolution( ) { const ipn = getIPv6Subnet(ip); const key = `capt:${ip}`; - const solution = await redis.getAsync(key); + let solution = await redis.getAsync(key); if (solution) { - if (solution.toString('utf8') === text) { + if (solution.toString('utf8') === captchaTextFilter(text)) { const solvkey = `human:${ipn}`; await redis.setAsync(solvkey, '', 'EX', TTL_CACHE); logger.info(`CAPTCHA ${ip} successfully solved captcha`);