An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:lock: Fix path traversal vulnerability in /repo/diff/ endpoint (#17657)
Qiaochu Hu890d2c5a67f8
diff --git a/kernel/server/serve.go b/kernel/server/serve.goindex 477110d6af..ba5b4f3601 100644--- a/kernel/server/serve.go+++ b/kernel/server/serve.go@@ -698,9 +698,18 @@ func serveThumbnail(context *gin.Context, assetAbsPath, requestPath string) bool}func serveRepoDiff(ginServer *gin.Engine) {+ repoDiffBaseDir := filepath.Join(util.TempDir, "repo", "diff")ginServer.GET("/repo/diff/*path", model.CheckAuth, model.CheckAdminRole, func(context *gin.Context) {- requestPath := context.Param("path")- p := filepath.Join(util.TempDir, "repo", "diff", requestPath)+ requestPath := filepath.Clean(context.Param("path"))+ if strings.Contains(requestPath, "..") {+ context.Status(http.StatusUnauthorized)+ return+ }+ p := filepath.Join(repoDiffBaseDir, requestPath)+ if !gulu.File.IsSubPath(repoDiffBaseDir, p) {+ context.Status(http.StatusUnauthorized)+ return+ }http.ServeFile(context.Writer, context.Request, p)})}