From 1d7f4db6ca37d6ab1d8ce02b1186ed6c6c8da98b Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 21 Sep 2026 00:19:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(security):=20=E9=98=B2=E6=AD=A2=E9=80=9A?= =?UTF-8?q?=E8=BF=87setServerConfig=E6=8E=A5=E5=8F=A3=E7=BB=95=E8=BF=87?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=9D=83=E9=99=90=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 8b1ecced..1fe26594 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -912,7 +912,8 @@ void installWebApi() { continue; #endif } - if (pr.first == FFmpeg::kBin || pr.first == FFmpeg::kSnap) { + if (pr.first == FFmpeg::kBin || pr.first == FFmpeg::kSnap || pr.first == API::kDownloadRoot) { + // downloadRoot 决定 downloadFile 接口的可下载边界,禁止通过 setServerConfig 动态放宽,防止越权读取任意文件 WarnL << "Configuration named " << pr.first << " is not allowed to be set by setServerConfig api."; continue; } @@ -2430,6 +2431,10 @@ void installWebApi() { auto vec = toolkit::split(str, ";"); for (auto &item : vec) { auto root = File::absolutePath("", item, true); + // 统一规范为以 '/' 结尾的目录边界,避免 www_secret 之类同级目录被 www 前缀误匹配(路径边界混淆) + if (root.empty() || root.back() != '/') { + root.push_back('/'); + } ret.emplace(std::move(root)); } return ret; @@ -2445,6 +2450,7 @@ void installWebApi() { } bool safe = false; for (auto &root : download_roots) { + // download_roots 中的 root 均以 '/' 结尾,此处按目录边界匹配,杜绝前缀混淆 if (start_with(file_path, root)) { safe = true; break;