feat: 服务页双栏布局 + 滑块验证码 v2(图片化挑战/行为校验/限流/蜜罐)
服务页(/services): - lg+ 双栏:左列服务菜单(NO.01-07,点击选中)、右列表单 (sticky 跟随);移动端保持上下堆叠 滑块验证码 v2(防机械脚本): - 答案坐标不再下发:缺口位置由服务端烘进 PNG(lib/captchaImage 自绘点阵底图 + 拼块裁片,lib/pngEncoder 纯 TS PNG 编码器, node:zlib 零依赖),脚本必须做图像识别才能定位 - 行为轨迹校验:拖动采样提交服务端,样本数 ≥6、总时长 ≥1.2s、 单调时间戳、峰值速度 > 平均×1.8(匀速直线 = 拒)、末点 ≈ 答案 - 位置容差 ±10px;失败 5 次作废;挑战 10 分钟过期 - IP 指纹(哈希)限流:challenge 15/10min、verify 30/10min、 咨询提交 3/小时;蜜罐字段(website)命中静默丢弃 端到端:无轨迹/匀速直线/超短时长均拒;真人节奏通过;重放拦截; 蜜罐丢弃;第 14 次刷 challenge 起 429;SMTP 真发正常。
This commit is contained in:
@@ -1,10 +1,21 @@
|
||||
/** /api/captcha/new — 生成滑块挑战(公开)。 */
|
||||
/**
|
||||
* /api/captcha/new — 生成滑块挑战(公开)。
|
||||
* v2:返回烘好缺口的服务端 PNG(bg + piece),答案坐标不出服务端。
|
||||
* 限流:15 次 / 10 分钟 / IP。
|
||||
*/
|
||||
import { NextResponse } from "next/server";
|
||||
import { createCaptchaChallenge } from "@/lib/captcha";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function POST() {
|
||||
const challenge = createCaptchaChallenge();
|
||||
return NextResponse.json(challenge);
|
||||
export async function POST(req: Request) {
|
||||
const result = createCaptchaChallenge(req);
|
||||
if (!result.ok) {
|
||||
return NextResponse.json({ error: result.error }, { status: 429 });
|
||||
}
|
||||
return NextResponse.json({
|
||||
challengeId: result.challengeId,
|
||||
bg: result.bg,
|
||||
piece: result.piece,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
/** /api/captcha/verify — 校验滑块位置,通过则签发一次性提交令牌。 */
|
||||
/**
|
||||
* /api/captcha/verify — 校验滑块(v2:行为轨迹 + 位置 + 限流)。
|
||||
* 通过后签发一次性提交令牌(5 分钟、单次消费)。
|
||||
*/
|
||||
import { NextResponse } from "next/server";
|
||||
import { verifyCaptcha } from "@/lib/captcha";
|
||||
import { verifyCaptcha, type TrackSample } from "@/lib/captcha";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
let body: { token?: string; x?: number };
|
||||
let body: { challengeId?: number; x?: number; track?: TrackSample[] };
|
||||
try {
|
||||
body = await req.json();
|
||||
} catch {
|
||||
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
|
||||
}
|
||||
const token = String(body.token ?? "");
|
||||
const challengeId = Number(body.challengeId);
|
||||
const x = Number(body.x);
|
||||
if (!token || !Number.isFinite(x)) {
|
||||
const track = body.track;
|
||||
if (!Number.isInteger(challengeId) || !Number.isFinite(x) || !Array.isArray(track)) {
|
||||
return NextResponse.json({ error: "参数错误" }, { status: 400 });
|
||||
}
|
||||
const result = verifyCaptcha(token, Math.round(x));
|
||||
if (x < -10 || x > 500) {
|
||||
return NextResponse.json({ error: "参数错误" }, { status: 400 });
|
||||
}
|
||||
const result = verifyCaptcha(req, challengeId, Math.round(x), track);
|
||||
if (!result.ok) {
|
||||
return NextResponse.json({ error: result.error }, { status: 400 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user