Skip to content

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

:lock: Reject temp/ paths in WebDAV to prevent accessing decrypted temp files, check actual boxID encryption in docIAL before moveCorruptedData to prevent encrypted file deletion via path traversal https://github.com/siyuan-note/siyuan/issues/18034

Danield132ed7039ad
diff --git a/kernel/model/file.go b/kernel/model/file.go
index 2426212385..2d95bcd8eb 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -124,8 +124,10 @@ func (box *Box) docIAL(p string) (ret map[string]string) {
ret = filesys.DocIAL(filePath)
if 1 > len(ret) {
// 加密笔记本的 .sy 解密失败(DEK 未缓存或 box 未解锁)时不应视为损坏,
- // 否则文件会被 moveCorruptedData 移走导致数据丢失
- if IsEncryptedBox(box.ID) {
+ // 否则文件会被 moveCorruptedData 移走导致数据丢失。
+ // 使用解析后的文件路径反查实际 boxID(可能因 symlink 或路径穿越指向加密 box)
+ actualBoxID := ExtractBoxIDFromAssetsPath(filePath)
+ if (actualBoxID != "" && IsEncryptedBox(actualBoxID)) || IsEncryptedBox(box.ID) {
logging.LogWarnf("properties not found in encrypted file [%s], skip moveCorruptedData", filePath)
return nil
}
diff --git a/kernel/server/serve.go b/kernel/server/serve.go
index 97ec35301f..c70a852e4c 100644
--- a/kernel/server/serve.go
+++ b/kernel/server/serve.go
@@ -1141,6 +1141,10 @@ type encryptedBoxAwareWebdavFS struct {
func (fs *encryptedBoxAwareWebdavFS) isEncryptedBoxPath(name string) bool {
rel := filepath.ToSlash(name)
+ // 阻止访问 temp/ 目录(包含已解密的导出、repo 快照等)
+ if strings.HasPrefix(rel, "temp/") || strings.Contains(rel, "/temp/") {
+ return true
+ }
if idx := strings.Index(rel, "/data/"); idx >= 0 {
candidate := rel[idx+len("/data/"):]
if slashIdx := strings.Index(candidate, "/"); slashIdx > 0 {