Skip to content

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

:bug: fix encrypted-notebook boot close + upload blocktree fallback #18034

Daniel1ee70ad20d0e
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index d9003d52f7..53717da392 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -49,42 +49,42 @@ var Conf *AppConf
// AppConf 维护应用元数据,保存在 ~/.siyuan/conf.json。
type AppConf struct {
- LogLevel string `json:"logLevel"` // 日志级别:off, trace, debug, info, warn, error, fatal
- Appearance *conf.Appearance `json:"appearance"` // 外观
- Langs []*conf.Lang `json:"langs"` // 界面语言列表
- Lang string `json:"lang"` // 选择的界面语言,同 Appearance.Lang
- FileTree *conf.FileTree `json:"fileTree"` // 文档面板
- Tag *conf.Tag `json:"tag"` // 标签面板
- Editor *conf.Editor `json:"editor"` // 编辑器配置
- Export *conf.Export `json:"export"` // 导出配置
- Graph *conf.Graph `json:"graph"` // 关系图配置
- UILayout *conf.UILayout `json:"uiLayout"` // 界面布局。不要直接使用,使用 GetUILayout() 和 SetUILayout() 方法
- UserData string `json:"userData"` // 社区用户信息,对 User 加密存储
- User *conf.User `json:"-"` // 社区用户内存结构,不持久化。不要直接使用,使用 GetUser() 和 SetUser() 方法
- Account *conf.Account `json:"account"` // 帐号配置
- ReadOnly bool `json:"readonly"` // 是否是以只读模式运行
- ServerAddrs []string `json:"serverAddrs"` // 本地服务器地址列表
- AccessAuthCode string `json:"accessAuthCode"` // 锁屏密码
- System *conf.System `json:"system"` // 系统配置
- Keymap *conf.Keymap `json:"keymap"` // 快捷键配置
- Sync *conf.Sync `json:"sync"` // 同步配置
- Search *conf.Search `json:"search"` // 搜索配置
- Flashcard *conf.Flashcard `json:"flashcard"` // 闪卡配置
- AI *conf.AI `json:"ai"` // 人工智能配置
- Secrets *conf.Secrets `json:"secrets"` // 全局密钥库
- Variables *conf.Variables `json:"variables"` // 全局变量库
- Bazaar *conf.Bazaar `json:"bazaar"` // 集市配置
- Stat *conf.Stat `json:"stat"` // 统计
- Api *conf.API `json:"api"` // API
- Repo *conf.Repo `json:"repo"` // 数据仓库
- NotebookCrypto *conf.NotebookCrypto `json:"notebookCrypto"` // 加密笔记本密钥管理
- Publish *conf.Publish `json:"publish"` // 发布服务
- OpenHelp bool `json:"openHelp"` // 启动后是否需要打开用户指南
- ShowChangelog bool `json:"showChangelog"` // 是否显示版本更新日志
- CloudRegion int `json:"cloudRegion"` // 云端区域,0:中国大陆,1:北美
- Snippet *conf.Snpt `json:"snippet"` // 代码片段
- DataIndexState int `json:"dataIndexState"` // 数据索引状态,0:已索引,1:未索引
- CookieKey string `json:"cookieKey"` // 用于加密 Cookie 的密钥
+ LogLevel string `json:"logLevel"` // 日志级别:off, trace, debug, info, warn, error, fatal
+ Appearance *conf.Appearance `json:"appearance"` // 外观
+ Langs []*conf.Lang `json:"langs"` // 界面语言列表
+ Lang string `json:"lang"` // 选择的界面语言,同 Appearance.Lang
+ FileTree *conf.FileTree `json:"fileTree"` // 文档面板
+ Tag *conf.Tag `json:"tag"` // 标签面板
+ Editor *conf.Editor `json:"editor"` // 编辑器配置
+ Export *conf.Export `json:"export"` // 导出配置
+ Graph *conf.Graph `json:"graph"` // 关系图配置
+ UILayout *conf.UILayout `json:"uiLayout"` // 界面布局。不要直接使用,使用 GetUILayout() 和 SetUILayout() 方法
+ UserData string `json:"userData"` // 社区用户信息,对 User 加密存储
+ User *conf.User `json:"-"` // 社区用户内存结构,不持久化。不要直接使用,使用 GetUser() 和 SetUser() 方法
+ Account *conf.Account `json:"account"` // 帐号配置
+ ReadOnly bool `json:"readonly"` // 是否是以只读模式运行
+ ServerAddrs []string `json:"serverAddrs"` // 本地服务器地址列表
+ AccessAuthCode string `json:"accessAuthCode"` // 锁屏密码
+ System *conf.System `json:"system"` // 系统配置
+ Keymap *conf.Keymap `json:"keymap"` // 快捷键配置
+ Sync *conf.Sync `json:"sync"` // 同步配置
+ Search *conf.Search `json:"search"` // 搜索配置
+ Flashcard *conf.Flashcard `json:"flashcard"` // 闪卡配置
+ AI *conf.AI `json:"ai"` // 人工智能配置
+ Secrets *conf.Secrets `json:"secrets"` // 全局密钥库
+ Variables *conf.Variables `json:"variables"` // 全局变量库
+ Bazaar *conf.Bazaar `json:"bazaar"` // 集市配置
+ Stat *conf.Stat `json:"stat"` // 统计
+ Api *conf.API `json:"api"` // API
+ Repo *conf.Repo `json:"repo"` // 数据仓库
+ NotebookCrypto *conf.NotebookCrypto `json:"notebookCrypto"` // 加密笔记本密钥管理
+ Publish *conf.Publish `json:"publish"` // 发布服务
+ OpenHelp bool `json:"openHelp"` // 启动后是否需要打开用户指南
+ ShowChangelog bool `json:"showChangelog"` // 是否显示版本更新日志
+ CloudRegion int `json:"cloudRegion"` // 云端区域,0:中国大陆,1:北美
+ Snippet *conf.Snpt `json:"snippet"` // 代码片段
+ DataIndexState int `json:"dataIndexState"` // 数据索引状态,0:已索引,1:未索引
+ CookieKey string `json:"cookieKey"` // 用于加密 Cookie 的密钥
m *sync.RWMutex // 配置数据锁
userLock *sync.RWMutex // 用户数据独立锁,避免与配置保存操作竞争
@@ -143,6 +143,21 @@ func InitConf() {
Conf.Save()
logging.LogInfof("migrated AI config [%s]", confPath)
}
+
+ // 重启后加密笔记本的 DEK 丢失(仅内存),必须重新解锁。
+ // 强制把所有加密笔记本标记为已关闭,避免启动索引读到无法解密的密文 .sy。
+ changed := false
+ for _, box := range Conf.GetBoxes() {
+ boxConf := box.GetConf()
+ if boxConf.Encrypted && !boxConf.Closed {
+ boxConf.Closed = true
+ box.SaveConf(boxConf)
+ changed = true
+ }
+ }
+ if changed {
+ logging.LogInfof("closed encrypted notebooks on boot (DEK not in memory)")
+ }
}
}
diff --git a/kernel/model/upload.go b/kernel/model/upload.go
index 92373b18df..018edf3b28 100644
--- a/kernel/model/upload.go
+++ b/kernel/model/upload.go
@@ -152,6 +152,15 @@ func Upload(c *gin.Context) {
if nil != form.Value["id"] {
id := form.Value["id"][0]
bt := treenode.GetBlockTree(id)
+ if nil == bt {
+ // 全局 blocktree 找不到时,遍历已打开的加密 box 查找
+ for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
+ if encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {
+ bt = encBT
+ break
+ }
+ }
+ }
if nil == bt {
ret.Code = -1
ret.Msg = Conf.Language(71)