Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:lock: https://github.com/siyuan-note/siyuan/security/advisories/GHSA-vmm8-3ccv-ppvw

Daniel914c5180a88d
diff --git a/kernel/util/path.go b/kernel/util/path.go
index 0707495d6f..1f90a947c6 100644
--- a/kernel/util/path.go
+++ b/kernel/util/path.go
@@ -399,8 +399,12 @@ func IsPartitionRootPath(path string) bool {
}
// IsSensitivePath 对传入路径做统一的敏感性检测。
-// 为防止通过符号链接绕过黑名单,会先尝试解析路径上的符号链接,再对原始路径与解析后的真实路径
-// 分别检查,任一命中即判定为敏感。解析失败(如路径不存在)时回退到仅检查原始路径。
+//
+// 为防止通过符号链接绕过黑名单,对工作空间外的路径会额外解析符号链接后再检查一次:这是
+// globalCopyFiles 等接受工作空间外绝对路径的接口的攻击面。工作空间内的路径不解析符号链接,
+// 一是因为工作空间内文件(如 assets 中指向外部目录的符号链接)可能合法地指向工作空间外,
+// 对其解析后执行系统目录前缀检查会误伤;二是避免在高 QPS 的伺服热路径上引入额外的 stat 开销。
+// 解析失败(如路径不存在)时回退到仅检查原始路径。
func IsSensitivePath(p string) bool {
if p == "" {
return false
@@ -408,7 +412,10 @@ func IsSensitivePath(p string) bool {
if isSensitivePath(p) {
return true
}
- // 解析符号链接后再次检查,防止在允许的目录内放置指向敏感目标的符号链接来绕过黑名单。
+ // 仅对工作空间外的路径解析符号链接,防止用符号链接绕过黑名单指向敏感目标。
+ if gulu.File.IsSubPath(WorkspaceDir, p) {
+ return false
+ }
resolved, err := filepath.EvalSymlinks(p)
if err == nil && resolved != p {
if isSensitivePath(resolved) {