Skip to content

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

:bug: Encrypted notebook: skip ciphertext AV on global history paths instead of failing JSON parse

Daniel28212b6e3c2b
diff --git a/kernel/av/av.go b/kernel/av/av.go
index d3a0ab15d1..549117cc8e 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -580,6 +580,10 @@ func parseAttributeViewByPathInBox(avJSONPath, boxID string) (ret *AttributeView
logging.LogErrorf("decrypt attribute view [%s] failed: %s", avID, readErr)
return
}
+ } else if util.IsCiphertext(data) {
+ // 历史等无法取得 boxID/DEK 的全局路径上读到密文:无法解密,返回空内容而非按 JSON 解析报错。
+ // 这会在加密笔记本的 AV 因路径迁移(同步、导入、历史布局)落到全局位置时发生。
+ return
}
cache.SetAVDataInBox(avID, boxID, data)
}
diff --git a/kernel/util/kdf.go b/kernel/util/kdf.go
index b085051fdf..994f5d6dd2 100644
--- a/kernel/util/kdf.go
+++ b/kernel/util/kdf.go
@@ -225,6 +225,13 @@ func hasEncryptionMagic(ciphertext []byte) bool {
return len(ciphertext) >= len(encryptionMagic) && bytes.Equal(ciphertext[:len(encryptionMagic)], encryptionMagic[:])
}
+// IsCiphertext 判断给定字节是否以加密信封魔数开头(即是否为密文)。
+// 供历史索引等无法取得 boxID/DEK 的路径做防御性检测:读到密文时跳过解析而非按 JSON 报错,
+// 避免加密笔记本的 AV 等对象因路径迁移(同步、导入、历史布局变化)落到全局位置时产生噪声错误。
+func IsCiphertext(data []byte) bool {
+ return hasEncryptionMagic(data)
+}
+
// envelopeAAD 把公开信封头和调用方 AAD 一并纳入 GCM 认证,防止规范或算法标识被篡改。
func envelopeAAD(header, aad []byte) []byte {
ret := make([]byte, 0, len(header)+len(aad))