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:
2026-09-02 19:12:54 +08:00
parent 7744a6b420
commit bededec29c
12 changed files with 867 additions and 390 deletions
+33 -1
View File
@@ -5,7 +5,7 @@
* 状态记录在 inquiries.email_sent / email_error,后台留言箱可见)。
*/
import { NextResponse } from "next/server";
import { consumeSubmitToken } from "@/lib/captcha";
import { consumeSubmitToken, clientFingerprint } from "@/lib/captcha";
import { createInquiry, markInquiryEmail } from "@/lib/siteConfig";
import { sendInquiryNotification } from "@/lib/mailer";
@@ -15,6 +15,21 @@ const NAME_MAX = 40;
const CONTACT_MAX = 80;
const MESSAGE_MAX = 2000;
// 提交限流桶(单实例内存实现,重启清零可接受)。
const submitBuckets = new Map<string, number[]>();
function submitRateLimit(fp: string): boolean {
const now = Date.now();
const windowMs = 60 * 60_000;
const arr = (submitBuckets.get(fp) ?? []).filter((t) => now - t < windowMs);
if (arr.length >= 3) {
submitBuckets.set(fp, arr);
return false;
}
arr.push(now);
submitBuckets.set(fp, arr);
return true;
}
export async function POST(req: Request) {
let body: {
submitToken?: string;
@@ -23,6 +38,8 @@ export async function POST(req: Request) {
serviceSlug?: string;
serviceTitle?: string;
message?: string;
/** 蜜罐:人类不可见不填写;机器人会全字段填充 */
website?: string;
};
try {
body = await req.json();
@@ -30,6 +47,21 @@ export async function POST(req: Request) {
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
}
// 蜜罐命中:静默丢弃(不告诉机器人被识别)
if (typeof body.website === "string" && body.website.trim() !== "") {
return NextResponse.json({ ok: true, id: 0 });
}
// 提交限流:3 次 / 小时 / IP(与验证码限流独立)
const fp = clientFingerprint(req);
const rl = submitRateLimit(fp);
if (!rl) {
return NextResponse.json(
{ error: "提交过于频繁,请稍后再试" },
{ status: 429 }
);
}
const name = String(body.name ?? "").trim();
const contact = String(body.contact ?? "").trim();
const message = String(body.message ?? "").trim();