上传文件至「Scripts」
This commit is contained in:
@@ -36,6 +36,15 @@ const CONFIG = {
|
|||||||
// 安全:域名白名单(仅允许这些 host 的 HTTPS 请求)
|
// 安全:域名白名单(仅允许这些 host 的 HTTPS 请求)
|
||||||
allowedHosts: ["www.nodeseek.com"],
|
allowedHosts: ["www.nodeseek.com"],
|
||||||
|
|
||||||
|
// 安全:路径白名单(仅允许这些路径,防止域名白名单万一被绕过后被滥用)
|
||||||
|
// /api/attendance → 签到
|
||||||
|
// /api/account/getInfo/<id> → 查询账号信息
|
||||||
|
// 任何指向发帖、私信、修改资料等其他 API 的请求都会被拒绝
|
||||||
|
allowedPaths: [
|
||||||
|
/^\/api\/attendance(\?|$)/,
|
||||||
|
/^\/api\/account\/getInfo\/[^/]+(\?|$)/,
|
||||||
|
],
|
||||||
|
|
||||||
baseUrl: "https://www.nodeseek.com",
|
baseUrl: "https://www.nodeseek.com",
|
||||||
|
|
||||||
// 网络
|
// 网络
|
||||||
@@ -96,12 +105,16 @@ function maskSecret(s) {
|
|||||||
return `${s.slice(0, 6)}***${s.slice(-4)}`;
|
return `${s.slice(0, 6)}***${s.slice(-4)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 安全 URL 校验:必须 HTTPS 且 host 在白名单 */
|
/** 安全 URL 校验:必须 HTTPS、host 在白名单、path 在白名单 */
|
||||||
function isAllowedUrl(url) {
|
function isAllowedUrl(url) {
|
||||||
try {
|
try {
|
||||||
const u = new URL(url);
|
const u = new URL(url);
|
||||||
if (u.protocol !== "https:") return false;
|
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 {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -141,9 +154,12 @@ async function safeRequest(opts) {
|
|||||||
// 相对路径拼接
|
// 相对路径拼接
|
||||||
if (opts.url.startsWith("/")) opts.url = CONFIG.baseUrl + opts.url;
|
if (opts.url.startsWith("/")) opts.url = CONFIG.baseUrl + opts.url;
|
||||||
|
|
||||||
// 白名单校验
|
// 白名单校验(host + path 双重)
|
||||||
if (!isAllowedUrl(opts.url)) {
|
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();
|
const method = (opts.type || (opts.body ? "post" : "get")).toLowerCase();
|
||||||
|
|||||||
Reference in New Issue
Block a user