add messages of failed captchas to chat

This commit is contained in:
HF 2022-07-21 03:58:14 +02:00
parent cc49c7d4dd
commit c5cbe94d50
4 changed files with 23 additions and 13 deletions

View File

@ -380,7 +380,7 @@ export class ChatProvider {
return null; return null;
} }
if (!user.userlvl && await cheapDetector(user.ip)) { if (await cheapDetector(user.ip)) {
logger.info( logger.info(
`${name} / ${user.ip} tried to send chat message with proxy`, `${name} / ${user.ip} tried to send chat message with proxy`,
); );

View File

@ -193,14 +193,6 @@ class MailProvider {
return reguser.name; return reguser.name;
} }
static createCode() {
const part1 = Math.random().toString(36).substring(2, 15)
+ Math.random().toString(36).substring(2, 15);
const part2 = Math.random().toString(36).substring(2, 15)
+ Math.random().toString(36).substring(2, 15);
return `${part1}-${part2}`;
}
static createCode() { static createCode() {
return randomUUID(); return randomUUID();
} }

View File

@ -59,9 +59,6 @@ function evaluateResult(captchaText, userText) {
return false; return false;
} }
} }
if (Math.random() < 0.1) {
return false;
}
return true; return true;
} }
@ -97,6 +94,7 @@ export async function setCaptchaSolution(
* @param text Solution of captcha * @param text Solution of captcha
* @param ip * @param ip
* @param onetime If the captcha is just one time or should be remembered * @param onetime If the captcha is just one time or should be remembered
* @param wrongCallback function that gets called when captcha got solved wrong
* for this ip * for this ip
* @return 0 if solution right * @return 0 if solution right
* 1 if timed out * 1 if timed out
@ -107,6 +105,7 @@ export async function checkCaptchaSolution(
ip, ip,
onetime = false, onetime = false,
captchaid = null, captchaid = null,
wrongCallback = null,
) { ) {
const ipn = getIPv6Subnet(ip); const ipn = getIPv6Subnet(ip);
let key = `capt:${ip}`; let key = `capt:${ip}`;
@ -116,6 +115,9 @@ export async function checkCaptchaSolution(
const solution = await redis.get(key); const solution = await redis.get(key);
if (solution) { if (solution) {
if (evaluateResult(solution, text)) { if (evaluateResult(solution, text)) {
if (Math.random() < 0.1) {
return 2;
}
if (!onetime) { if (!onetime) {
const solvkey = `human:${ipn}`; const solvkey = `human:${ipn}`;
await redis.set(solvkey, '', { await redis.set(solvkey, '', {
@ -128,6 +130,7 @@ export async function checkCaptchaSolution(
logger.info( logger.info(
`CAPTCHA ${ip} got captcha wrong (${text} instead of ${solution})`, `CAPTCHA ${ip} got captcha wrong (${text} instead of ${solution})`,
); );
wrongCallback(text, solution);
return 2; return 2;
} }
logger.info(`CAPTCHA ${ip}:${captchaid} timed out`); logger.info(`CAPTCHA ${ip}:${captchaid} timed out`);

View File

@ -8,6 +8,7 @@
import logger from '../../core/logger'; import logger from '../../core/logger';
import { checkCaptchaSolution } from '../../data/redis/captcha'; import { checkCaptchaSolution } from '../../data/redis/captcha';
import { getIPFromRequest } from '../../utils/ip'; import { getIPFromRequest } from '../../utils/ip';
import chatProvider from '../../core/ChatProvider';
export default async (req, res) => { export default async (req, res) => {
const ip = getIPFromRequest(req); const ip = getIPFromRequest(req);
@ -26,7 +27,21 @@ export default async (req, res) => {
return; return;
} }
const ret = await checkCaptchaSolution(text, ip, false, id); const ret = await checkCaptchaSolution(
text,
ip,
false,
id,
(inpt, solution) => {
chatProvider.broadcastChatMessage(
'info',
// eslint-disable-next-line max-len
`Someone got his captcha wrong and entered ${inpt} instead of ${solution}`,
chatProvider.enChannelId,
chatProvider.infoUserId,
);
},
);
switch (ret) { switch (ret) {
case 0: case 0: