Skip to content

Commit 168fc75

Browse files
fix(leaderboard): UA 改回 InvolutionHell-SSR 让 CF Custom Rule 真正匹配
之前误判 昨天看到 build 拿 403 + "Just a moment..." 时,第一反应是"UA 含 build 关键词 触发 CF UA 启发式",于是把 UA 改成 Chrome 伪装。错了。 实际 CF 配置 api.involutionhell.com 上有一条 Custom Rule: (http.host eq "api.involutionhell.com" and http.user_agent contains "InvolutionHell-SSR") → Skip: Bot Fight Mode / Browser Integrity Check / Managed Rules 也就是说 CF **明确依赖 UA token "InvolutionHell-SSR"** 来识别"自己人"放行。 Chrome 伪装恰恰把这个 token 拿掉,规则不匹配,Vercel runner 仍然按 IP 信誉被 Bot Fight 拦下回 403。 本 PR 脚本 UA 改成 "InvolutionHell-SSR/1.0 (build; generate-leaderboard.mjs; +https://involutionhell.com)" 带上 CF 规则要求的 token。本机实测 200 + 21 条数据正常返回。 效果 合并后 prod build → CF 规则匹配 Skip → 拉到真实数据 → site-leaderboard.json 回到 21 条 → 首页 Top Rank / /rank contributors 恢复显示。
1 parent 1e8084b commit 168fc75

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

scripts/generate-leaderboard.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ async function fetchAggregatedFromBackend() {
103103
const res = await fetch(LEADERBOARD_API_URL, {
104104
headers: {
105105
accept: "application/json",
106-
// UA 用 Chrome 伪装:API 站点走 Cloudflare,CF 默认 Bot Fight Mode 会
107-
// 把任何含 "bot" / "build" / "script" 关键词的 UA 当机器人拦下,回
108-
// 403 + "Just a moment..." 挑战页(之前的 UA 就被这么拦了,导致 prod
109-
// build 拿到 403 走 fallback 写空 leaderboard,feed 卡片全空)。
110-
// 长期方案应是在 CF 给 /api/public/* 加 "Skip Bot Fight" 规则白名单,
111-
// 这里的 UA 伪装只是兜底
106+
// UA 必须包含 "InvolutionHell-SSR" —— 这是 CF Custom Rule 的匹配触发词:
107+
// (http.host eq "api.involutionhell.com" and http.user_agent contains "InvolutionHell-SSR")
108+
// → Skip Bot Fight / Browser Integrity / Managed Rules
109+
// 之前用 Chrome 伪装时 UA 不含这个 token,CF 规则不匹配,Vercel build runner
110+
// 仍然被 IP 信誉评分判定为 bot 回 403("Just a moment..." 挑战页)。
111+
// 改回带 token 的 UA 让 CF 规则真正放行
112112
"user-agent":
113-
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 " +
114-
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
113+
"InvolutionHell-SSR/1.0 (build; generate-leaderboard.mjs; " +
114+
"+https://involutionhell.com)",
115115
},
116116
signal: controller.signal,
117117
});

0 commit comments

Comments
 (0)