diff --git a/lib/captcha.ts b/lib/captcha.ts index 6ab9226..5e99bf0 100644 --- a/lib/captcha.ts +++ b/lib/captcha.ts @@ -99,16 +99,17 @@ export function verifyCaptcha( } // 轨迹基础校验 - if (!Array.isArray(track) || track.length < 6) { + if (!Array.isArray(track) || track.length < 4) { return { ok: false, error: "验证失败,请重试" }; } const t0 = track[0].t; const tN = track[track.length - 1].t; const duration = tN - t0; - if (duration < 1200) { + // 真人慢拖可能 0.8s 左右;低于 600ms 基本只有脚本做得到 + if (duration < 600) { return { ok: false, error: "验证失败,请重试" }; } - if (duration > 10_000) { + if (duration > 15_000) { return { ok: false, error: "验证已过期,请刷新重试" }; } // 时间戳必须单调递增且合理(防止伪造负值/乱序) @@ -117,7 +118,9 @@ export function verifyCaptcha( return { ok: false, error: "验证失败,请重试" }; } } - // 速度波动:真人拖动有加减速,匀速直线 = 脚本特征 + // 速度波动:真人拖动有加减速。均匀度 = max(speed)/avg(speed), + // 完美匀速(脚本 linear tween)= 1.0;真人通常 > 2。阈值 1.25: + // 只拦截教科书式匀速直线,不再误伤慢而稳的真人拖动。 let maxSpeed = 0; let totalDist = 0; for (let i = 1; i < track.length; i++) { @@ -129,7 +132,8 @@ export function verifyCaptcha( if (speed > maxSpeed) maxSpeed = speed; } if (totalDist <= 0) return { ok: false, error: "验证失败,请重试" }; - if (maxSpeed < (totalDist / duration) * 1.8) { + const avgSpeed = totalDist / duration; + if (maxSpeed < avgSpeed * 1.25) { return { ok: false, error: "验证失败,请重试" }; } @@ -159,9 +163,9 @@ export function verifyCaptcha( return { ok: false, error: "位置不对,再试一次" }; } - // 末样本应接近提交的 x(轨迹与答案一致性) + // 末样本应接近提交的 x(轨迹与答案一致性;客户端缓释/掉帧留 20px) const lastSample = track[track.length - 1].x; - if (Math.abs(lastSample - x) > 14) { + if (Math.abs(lastSample - x) > 20) { db.prepare( "UPDATE captcha_challenges SET attempts = attempts + 1 WHERE id = ?" ).run(row.id);