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-275h-v5h9-vr82

Danielbdedf6d8952f
diff --git a/kernel/server/serve.go b/kernel/server/serve.go
index 78cfcad9f2..cd15a92f8b 100644
--- a/kernel/server/serve.go
+++ b/kernel/server/serve.go
@@ -418,6 +418,18 @@ func serveSnippets(ginServer *gin.Engine) {
// 没有在配置文件中命中时在文件系统上查找
filePath = filepath.Join(util.SnippetsPath, filePath)
+
+ // 限制只能访问 snippets 目录内的文件,并拦截敏感路径,避免通过路径穿越读取工作空间内的敏感文件
+ if !gulu.File.IsSubPath(util.SnippetsPath, filePath) {
+ c.Status(http.StatusUnauthorized)
+ return
+ }
+ if util.IsSensitivePath(filePath) {
+ logging.LogErrorf("refuse to serve sensitive snippet file [%s]", c.Request.URL.Path)
+ c.Status(http.StatusForbidden)
+ return
+ }
+
c.File(filePath)
})
}