From 884357e6770f8e347f1c698484868c20a627f0e6 Mon Sep 17 00:00:00 2001 From: chenchun Date: Wed, 2 Sep 2026 23:58:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=BB=91=E5=9D=97=E8=A1=8C=E4=B8=BA?= =?UTF-8?q?=E9=98=88=E5=80=BC=E6=94=BE=E5=AE=BD=20=E2=80=94=20=E6=85=A2?= =?UTF-8?q?=E9=80=9F=E5=8C=80=E7=A8=B3=E7=9C=9F=E4=BA=BA=E6=8B=96=E5=8A=A8?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E8=AF=AF=E5=88=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实测日志显示真人 verify 400×4(拖太稳/太慢被拒)。调整: - 速度均匀度阈值 1.8 → 1.25:只拦截教科书式匀速直线(linear tween 均匀度=1.0),慢而稳的真人拖动(均匀度≈1.1-1.2)放行 - 最短时长 1200ms → 600ms(慢拖真人可能 0.8s);上限 10s → 15s - 末样本一致性容差 14px → 20px(掉帧/缓释) - 最少样本 6 → 4 脚本特征拦截不放松:完美匀速仍拒、无轨迹仍拒、限流/蜜罐/单次令牌不变。 --- lib/captcha.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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);