{"record":{"id":"46936d57d65d3ccf","repo":"siyuan-note/siyuan","slug":"encrypted-notebook-attribute-view-history-is-plain","errorCode":null,"errorMessage":"encrypted notebook attribute view history is plaintext [%s]","messagePattern":"encrypted notebook attribute view history is plaintext \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":713,"sourceCode":"\t}\n\n\tfrom := historyPath\n\t// 从路径提取 boxID 判断是否加密笔记本的 AV\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\tciphertext := util.IsCiphertext(data)\n\tif ciphertext && (len(pathParts) < 3 || !ast.IsNodeIDPattern(pathParts[1]) || !IsEncryptedBox(pathParts[1])) {\n\t\treturn errors.New(\"encrypted attribute view history is missing valid notebook context\")\n\t}\n\tto := filepath.Join(util.DataDir, \"storage\", \"av\", filepath.Base(historyPath))\n\tif len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {\n\t\tif !ciphertext {\n\t\t\treturn fmt.Errorf(\"encrypted notebook attribute view history is plaintext [%s]\", pathParts[1])\n\t\t}\n\t\t// 加密笔记本的 AV 定义回滚到笔记本级目录\n\t\tto = filepath.Join(util.DataDir, pathParts[1], \"storage\", \"av\", 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\tavID := strings.TrimSuffix(filepath.Base(historyPath), \".json\")\n\tcache.RemoveAVData(avID)\n\tavBoxID := \"\"\n\tif len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {\n\t\tavBoxID = pathParts[1]\n\t}","sourceCodeStart":695,"sourceCodeEnd":731,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L695-L731","documentation":"For an encrypted notebook's AV history, the snapshot file must itself be ciphertext. If the path names an encrypted notebook but the file content is plaintext, the kernel refuses the rollback because silently writing plaintext into an encrypted notebook would break its confidentiality guarantees. The error names the offending notebook ID.","triggerScenarios":"RollbackAttributeViewHistory called with a path under an encrypted notebook ID where the .json snapshot on disk is unencrypted (e.g. created before encryption was enabled, or written by a tool that bypassed encryption).","commonSituations":"History snapshots produced by an older SiYuan version before encrypted-notebook support; third-party sync/backup tools restoring plaintext copies; mixed plaintext/ciphertext history after toggling notebook encryption.","solutions":["Re-create the AV history snapshot from the encrypted notebook so it is stored as ciphertext, then roll back.","If the data is legitimately plaintext (pre-encryption era), restore it manually into the notebook rather than via RollbackAttributeViewHistory.","Verify which notebook the snapshot belongs to; if it actually belongs to a non-encrypted notebook, correct the path."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (isEncryptedBox(boxID) && !isCiphertext(fileData)) {\n  throw new Error(\"plaintext snapshot for encrypted notebook \" + boxID);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only create AV histories through kernel APIs so snapshots are encrypted correctly.","After enabling notebook encryption, regenerate old plaintext snapshots.","Do not edit history snapshot files in place with external tools."],"tags":["encryption","plaintext","attribute-view","history"],"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"}