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: Use IsSubPath to validate content template paths https://github.com/siyuan-note/siyuan/security/advisories/GHSA-w938-w7m4-qrj8
Daniel88c74d9ae57c
diff --git a/kernel/model/template.go b/kernel/model/template.goindex 0a30d91501..c335ce49a9 100644--- a/kernel/model/template.go+++ b/kernel/model/template.go@@ -704,8 +704,7 @@ func resolveDocContentTemplatePath(templatePath string) (string, error) {}templateRoot := filepath.Join(util.DataDir, "templates")absPath := filepath.Join(templateRoot, cleanPath)- rel, err := filepath.Rel(templateRoot, absPath)- if nil != err || ".." == rel || strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {+ if !gulu.File.IsSubPath(templateRoot, absPath) {return "", errors.New("content template path is outside templates directory")}if !filelock.IsExist(absPath) {@@ -723,8 +722,7 @@ func resolveDocContentTemplatePath(templatePath string) (string, error) {if nil != err || !info.Mode().IsRegular() {return "", fmt.Errorf("content template [%s] is not a regular file", templatePath)}- realRel, err := filepath.Rel(realRoot, realPath)- if nil != err || ".." == realRel || strings.HasPrefix(realRel, ".."+string(os.PathSeparator)) {+ if !gulu.File.IsSubPath(realRoot, realPath) {return "", errors.New("content template path is outside templates directory")}return realPath, nil