Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Fix document tree locate/rename broken by path format inconsistency from encrypted notebook path validation #18034

Daniel62700bb80bf8
diff --git a/kernel/filesys/tree.go b/kernel/filesys/tree.go
index f13e66aec4..a5eb8c2755 100644
--- a/kernel/filesys/tree.go
+++ b/kernel/filesys/tree.go
@@ -147,12 +147,17 @@ func batchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) (ret []*parse
// ValidateBoxRelativePath 校验 box 内相对路径是否安全。
// 拒绝 ..、绝对路径,确保最终路径位于 <DataDir>/<boxID> 内。
// 允许路径以 / 开头(如 /20230101/xxx.sy),会自动标准化再去掉前导斜杠。
+// 根路径("/" 或 "")合法,返回空字符串。
func ValidateBoxRelativePath(boxID, p string) (string, error) {
p = filepath.ToSlash(p)
// 记录原始路径用于 IsSubPath 校验
origP := p
// 标准化:去掉前导 /
p = strings.TrimPrefix(p, "/")
+ // 根路径直接放行(box 根目录本身是合法路径)
+ if p == "" {
+ return p, nil
+ }
if strings.HasPrefix(p, "..") || strings.Contains(p, "/../") || strings.HasSuffix(p, "/..") || p == ".." || p == "." {
return "", fmt.Errorf("path [%s] must not contain '..'", origP)
}
diff --git a/kernel/model/box.go b/kernel/model/box.go
index b6d1e284de..d8e3ec1f77 100644
--- a/kernel/model/box.go
+++ b/kernel/model/box.go
@@ -275,13 +275,8 @@ func (box *Box) validateBoxPath(p string) (string, error) {
}
func (box *Box) Ls(p string) (ret []*FileInfo, totals int, err error) {
- if "/" == p {
- p = ""
- }
- if p != "" {
- if _, err = box.validateBoxPath(p); err != nil {
- return
- }
+ if _, err = box.validateBoxPath(p); err != nil {
+ return
}
boxLocalPath := filepath.Join(util.DataDir, box.ID)
if strings.HasSuffix(p, ".sy") {