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: Validate workspace path with Abs/IsWorkspaceDir/ReadWorkspacePaths before RemoveAll in removeWorkspaceDirPhysically, reject current workspace and unregistered paths https://github.com/siyuan-note/siyuan/issues/18034
Danield72dc15a3d67
diff --git a/kernel/api/workspace.go b/kernel/api/workspace.goindex a3dc8a24f3..f17b8374a5 100644--- a/kernel/api/workspace.go+++ b/kernel/api/workspace.go@@ -171,14 +171,48 @@ func removeWorkspaceDirPhysically(c *gin.Context) {}path := arg["path"].(string)- if gulu.File.IsDir(path) {- err := os.RemoveAll(path)- if err != nil {- ret.Code = -1- ret.Msg = err.Error()- return++ // 硬边界:只允许删除已登记的工作空间目录,禁止删除当前工作空间和任意路径+ cleanPath, absErr := filepath.Abs(path)+ if absErr != nil {+ ret.Code = -1+ ret.Msg = absErr.Error()+ return+ }+ if cleanPath == util.WorkspaceDir {+ ret.Code = -1+ ret.Msg = "cannot remove current workspace"+ return+ }+ if !util.IsWorkspaceDir(cleanPath) {+ ret.Code = -1+ ret.Msg = "path is not a workspace directory"+ return+ }+ knownPaths, err := util.ReadWorkspacePaths()+ if err != nil {+ ret.Code = -1+ ret.Msg = err.Error()+ return+ }+ isKnown := false+ for _, known := range knownPaths {+ if known == cleanPath {+ isKnown = true+ break}}+ if !isKnown {+ ret.Code = -1+ ret.Msg = "path is not a registered workspace"+ return+ }++ if err := os.RemoveAll(cleanPath); err != nil {+ ret.Code = -1+ ret.Msg = err.Error()+ return+ }logging.LogInfof("removed workspace [%s] physically", path)if util.WorkspaceDir == path {