{"record":{"id":"2426131bd22943b7","repo":"siyuan-note/siyuan","slug":"encrypted-notebook-asset-history-is-plaintext-s","errorCode":null,"errorMessage":"encrypted notebook asset history is plaintext [%s]","messagePattern":"encrypted notebook asset history is plaintext \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":583,"sourceCode":"\t}\n\n\tfrom := historyPath\n\t// 从路径提取 boxID 判断是否加密笔记本的资源\n\trelPath := strings.TrimPrefix(filepath.ToSlash(historyPath), filepath.ToSlash(util.HistoryDir))\n\trelPath = strings.TrimPrefix(relPath, \"/\")\n\tpathParts := strings.SplitN(relPath, \"/\", 3)\n\tdata, readErr := filelock.ReadFile(from)\n\tif readErr != nil {\n\t\treturn readErr\n\t}\n\tencrypted := bytes.HasPrefix(data, encryptedAssetMagic)\n\tif encrypted && (len(pathParts) < 3 || !ast.IsNodeIDPattern(pathParts[1]) || !IsEncryptedBox(pathParts[1])) {\n\t\treturn errors.New(\"encrypted asset history is missing valid notebook context\")\n\t}\n\tto := filepath.Join(util.DataDir, \"assets\", filepath.Base(historyPath))\n\tif len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {\n\t\tif !encrypted {\n\t\t\treturn fmt.Errorf(\"encrypted notebook asset history is plaintext [%s]\", pathParts[1])\n\t\t}\n\t\t// 加密笔记本的资源回滚到笔记本级 assets 目录\n\t\tto = filepath.Join(util.DataDir, pathParts[1], \"assets\", filepath.Base(historyPath))\n\t\tif err = os.MkdirAll(filepath.Dir(to), 0755); err != nil {\n\t\t\treturn\n\t\t}\n\t}\n\n\tif err = filelock.CopyNewtimes(from, to); err != nil {\n\t\tlogging.LogErrorf(\"copy file [%s] to [%s] failed: %s\", from, to, err)\n\t\treturn\n\t}\n\tIncSync()\n\tutil.PushMsg(Conf.Language(102), 3000)\n\treturn nil\n}\n\n// validateHistoryPath 校验历史路径是否位于工作区内且属于历史目录。","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L565-L601","documentation":"When rolling back an asset whose notebook is encrypted, the kernel requires the historical asset bytes to be encrypted (they must begin with encryptedAssetMagic). If the historical copy is plaintext while the destination notebook is an encrypted box, the rollback refuses with this error naming the notebook ID, because storing plaintext asset content in an encrypted notebook would silently break the encryption guarantee.","triggerScenarios":"Calling RollbackAssetsHistory where pathParts[1] is an encrypted notebook ID but filelock.ReadFile of the history asset shows no encrypted-asset magic prefix — e.g. the history was generated before encrypted-asset support or the asset was replaced with a plaintext copy.","commonSituations":"Migrating history snapshots from a plaintext notebook into an encrypted notebook; downgraded kernel versions that wrote plaintext assets; manual edits to history files.","solutions":["Encrypt the asset with the current kernel's encrypted-asset format and place it back in the history directory","Regenerate the history snapshot from the encrypted notebook so assets are enveloped","If the plaintext original is the only copy, decrypt-verify workflow: restore to a plaintext notebook instead, then migrate through the supported encrypted-notebook flow"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const head = fs.readFileSync(historyPath).subarray(0, MAGIC.length);\nif (isEncryptedBox(boxID) && !head.equals(ENCRYPTED_ASSET_MAGIC)) { throw new Error('history asset is plaintext'); }","typeGuard":null,"tryCatchPattern":"try { await rollbackAssetsHistory(p); } catch (e) { if (String(e).includes('is plaintext')) { await reencryptHistoryAsset(p, boxID); await rollbackAssetsHistory(p); } else { throw e; } }","preventionTips":["Never copy plaintext assets into encrypted-notebook history directories","Run the current kernel version when creating encrypted-notebook history","Verify the magic prefix of history assets before restoring them"],"tags":["history","assets","encrypted-notebook","plaintext"],"backgroundTag":"checksum-mismatch","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}