An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: File system exception when exporting docs containing `../` hyperlinks to Markdown Fix https://github.com/siyuan-note/siyuan/issues/9779
Danielc9f90c606e33
diff --git a/kernel/model/assets.go b/kernel/model/assets.goindex 7e19a826a9..da0817852e 100644--- a/kernel/model/assets.go+++ b/kernel/model/assets.go@@ -432,7 +432,7 @@ func SearchAssetsByName(keyword string, exts []string) (ret []*cache.Asset) {return}-func GetAssetAbsPath(relativePath string) (absPath string, err error) {+func GetAssetAbsPath(relativePath string) (ret string, err error) {relativePath = strings.TrimSpace(relativePath)if strings.Contains(relativePath, "?") {relativePath = relativePath[:strings.Index(relativePath, "?")]@@ -455,13 +455,18 @@ func GetAssetAbsPath(relativePath string) (absPath string, err error) {}if p := filepath.ToSlash(path); strings.HasSuffix(p, relativePath) {if gulu.File.IsExist(path) {- absPath = path+ ret = pathreturn io.EOF}}return nil})- if "" != absPath {++ if "" != ret {+ if !util.IsSubPath(util.WorkspaceDir, ret) {+ err = fmt.Errorf("[%s] is not sub path of workspace", ret)+ return+ }return}}@@ -469,7 +474,11 @@ func GetAssetAbsPath(relativePath string) (absPath string, err error) {// 在全局 assets 路径下搜索p := filepath.Join(util.DataDir, relativePath)if gulu.File.IsExist(p) {- absPath = p+ ret = p+ if !util.IsSubPath(util.WorkspaceDir, ret) {+ err = fmt.Errorf("[%s] is not sub path of workspace", ret)+ return+ }return}return "", errors.New(fmt.Sprintf(Conf.Language(12), relativePath))diff --git a/kernel/util/file.go b/kernel/util/file.goindex 5f717553bb..690fb96285 100644--- a/kernel/util/file.go+++ b/kernel/util/file.go@@ -190,6 +190,10 @@ func IsSubPath(absPath, toCheckPath string) bool {if 1 > len(absPath) || 1 > len(toCheckPath) {return false}+ if absPath == toCheckPath { // 相同路径时不认为是子路径+ return false+ }+if gulu.OS.IsWindows() {if filepath.IsAbs(absPath) && filepath.IsAbs(toCheckPath) {if strings.ToLower(absPath)[0] != strings.ToLower(toCheckPath)[0] {diff --git a/kernel/util/path.go b/kernel/util/path.goindex 8c653a31fe..7c44ed9bbf 100644--- a/kernel/util/path.go+++ b/kernel/util/path.go@@ -268,9 +268,12 @@ func IsDisplayableAsset(p string) bool {func GetAbsPathInWorkspace(relPath string) (string, error) {absPath := filepath.Join(WorkspaceDir, relPath)+ if WorkspaceDir == absPath {+ return absPath, nil+ }+if IsSubPath(WorkspaceDir, absPath) {return absPath, nil- } else {- return "", os.ErrPermission}+ return "", os.ErrPermission}