From 7d0b82ddddcad40097b65e4a3fdc55dcd4c9e4f5 Mon Sep 17 00:00:00 2001 From: XXhaos Date: Thu, 30 Apr 2026 13:31:59 +0900 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=E3=80=8CScripts=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/nodeseek.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Scripts/nodeseek.js b/Scripts/nodeseek.js index fcd69d0..57b87d3 100644 --- a/Scripts/nodeseek.js +++ b/Scripts/nodeseek.js @@ -36,6 +36,15 @@ const CONFIG = { // 安全:域名白名单(仅允许这些 host 的 HTTPS 请求) allowedHosts: ["www.nodeseek.com"], + // 安全:路径白名单(仅允许这些路径,防止域名白名单万一被绕过后被滥用) + // /api/attendance → 签到 + // /api/account/getInfo/ → 查询账号信息 + // 任何指向发帖、私信、修改资料等其他 API 的请求都会被拒绝 + allowedPaths: [ + /^\/api\/attendance(\?|$)/, + /^\/api\/account\/getInfo\/[^/]+(\?|$)/, + ], + baseUrl: "https://www.nodeseek.com", // 网络 @@ -96,12 +105,16 @@ function maskSecret(s) { return `${s.slice(0, 6)}***${s.slice(-4)}`; } -/** 安全 URL 校验:必须 HTTPS 且 host 在白名单 */ +/** 安全 URL 校验:必须 HTTPS、host 在白名单、path 在白名单 */ function isAllowedUrl(url) { try { const u = new URL(url); if (u.protocol !== "https:") return false; - return CONFIG.allowedHosts.includes(u.hostname); + if (!CONFIG.allowedHosts.includes(u.hostname)) return false; + // 路径白名单:只允许签到和查账号信息这两个 API + const fullPath = u.pathname + u.search; + if (!CONFIG.allowedPaths.some((re) => re.test(fullPath))) return false; + return true; } catch { return false; } @@ -141,9 +154,12 @@ async function safeRequest(opts) { // 相对路径拼接 if (opts.url.startsWith("/")) opts.url = CONFIG.baseUrl + opts.url; - // 白名单校验 + // 白名单校验(host + path 双重) if (!isAllowedUrl(opts.url)) { - throw new Error(`拒绝请求非白名单地址: ${new URL(opts.url).hostname}`); + const u = new URL(opts.url); + throw new Error( + `拒绝请求非白名单地址: ${u.hostname}${u.pathname}` + ); } const method = (opts.type || (opts.body ? "post" : "get")).toLowerCase();