Skip to content

Commit e959de4

Browse files
committed
🚨 disable export/history/import for encrypted notebooks (stage 7) #18034
Encrypted notebooks bypass filesys for export/history/import, which would either leak ciphertext (export) or corrupt data (import writes plaintext .sy into encrypted dir). Disable these three features for encrypted boxes until proper integration is built. - model/export.go: ExportNotebookSY and ExportSYs return early for encrypted boxes - model/history.go: GenerateFileHistory skips encrypted boxes in the ticker loop; generateTreeHistory returns early for encrypted trees (covers both auto and edit-triggered history) - model/import.go: ImportSY and ImportFromLocalPath return error for encrypted target boxes Sync (.sy/assets) is NOT changed: the sync loop is naturally correct — files are ciphertext on disk, dejavu reads ciphertext and uploads ciphertext, checkout writes ciphertext back. DEK encryption is preserved end-to-end without intervention. #18034
1 parent ea4264f commit e959de4

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

kernel/model/export.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,20 @@ func ExportSystemLog() (zipPath string) {
500500
}
501501

502502
func ExportNotebookSY(id string) (zipPath string) {
503+
// 加密笔记本不支持导出,避免密文 .sy 流出后无法解读
504+
if IsEncryptedBox(id) {
505+
return
506+
}
503507
zipPath = exportBoxSYZip(id)
504508
return
505509
}
506510

507511
func ExportSYs(ids []string) (zipPath string) {
508512
block := treenode.GetBlockTree(ids[0])
513+
// 加密笔记本不支持导出
514+
if nil != block && IsEncryptedBox(block.BoxID) {
515+
return
516+
}
509517
box := Conf.Box(block.BoxID)
510518
baseFolderName := path.Base(block.HPath)
511519
if "." == baseFolderName {

kernel/model/history.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ func GenerateFileHistory() {
7070

7171
// 生成文档历史
7272
for _, box := range Conf.GetOpenedBoxes() {
73+
// 加密笔记本不生成历史(历史目录不加密,密文 .sy 写进去也无意义)
74+
if IsEncryptedBox(box.ID) {
75+
continue
76+
}
7377
box.generateDocHistory0()
7478
}
7579

@@ -857,6 +861,10 @@ func CreateDocHistory(id string) (err error) {
857861
}
858862

859863
func generateTreeHistory(tree *parse.Tree, historyDir string) {
864+
// 加密笔记本不生成历史
865+
if IsEncryptedBox(tree.Box) {
866+
return
867+
}
860868
historyPath := filepath.Join(historyDir, tree.Box, tree.Path)
861869
var err error
862870
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); err != nil {

kernel/model/import.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ func HTML2Tree(htmlStr string, luteEngine *lute.Lute) (tree *parse.Tree, withMat
108108
}
109109

110110
func ImportSY(zipPath, boxID, toPath string) (err error) {
111+
// 加密笔记本不支持导入(导入的 .sy 是明文,落到加密目录会导致读取失败)
112+
if IsEncryptedBox(boxID) {
113+
err = errors.New("import to encrypted notebook is not supported")
114+
return
115+
}
111116
util.PushEndlessProgress(Conf.Language(73))
112117
defer util.ClearPushProgress(100)
113118

@@ -769,6 +774,11 @@ func ImportData(zipPath string) (err error) {
769774
}
770775

771776
func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
777+
// 加密笔记本不支持导入
778+
if IsEncryptedBox(boxID) {
779+
err = errors.New("import to encrypted notebook is not supported")
780+
return
781+
}
772782
util.PushEndlessProgress(Conf.Language(73))
773783
defer func() {
774784
util.PushClearProgress()

0 commit comments

Comments
 (0)