{"record":{"id":"bf9d63b495f45126","repo":"siyuan-note/siyuan","slug":"encrypted-notebook-snapshot-document-is-plaintext","errorCode":null,"errorMessage":"encrypted notebook snapshot document is plaintext [%s]","messagePattern":"encrypted notebook snapshot document is plaintext \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history_diff.go","lineNumber":437,"sourceCode":"\t\treturn nil, err\n\t}\n\tciphertext := util.IsCiphertext(data)\n\tif ciphertext {\n\t\tif len(pathParts) < 2 || !ast.IsNodeIDPattern(pathParts[0]) || !IsEncryptedBox(pathParts[0]) {\n\t\t\treturn nil, errors.New(\"encrypted snapshot document is missing valid notebook context\")\n\t\t}\n\t\tHoldBoxReadLock(pathParts[0])\n\t\tdefer ReleaseBoxReadLock(pathParts[0])\n\t\tdek, unlockErr := GetDEKIfUnlocked(pathParts[0])\n\t\tif unlockErr != nil {\n\t\t\treturn nil, errors.New(Conf.Language(314))\n\t\t}\n\t\tdata, err = DecryptFile(pathParts[0], pathParts[1], dek, data)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t} else if len(pathParts) > 0 && IsEncryptedBox(pathParts[0]) {\n\t\treturn nil, fmt.Errorf(\"encrypted notebook snapshot document is plaintext [%s]\", pathParts[0])\n\t}\n\trootID := strings.TrimSuffix(filepath.Base(file.Path), filepath.Ext(file.Path))\n\ttree, err := parseDocVersionTree(data, rootID)\n\tboxID := \"\"\n\tif 0 < len(pathParts) && ast.IsNodeIDPattern(pathParts[0]) {\n\t\tboxID = pathParts[0]\n\t}\n\tif err != nil {\n\t\treturn &loadedDocVersion{\n\t\t\ttitle:    rootID,\n\t\t\trootID:   rootID,\n\t\t\traw:      data,\n\t\t\tparseErr: err,\n\t\t\tlarge:    1024*1024 <= len(data),\n\t\t\tboxID:    boxID,\n\t\t}, nil\n\t}\n\treturn &loadedDocVersion{","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history_diff.go#L419-L455","documentation":"loadSnapshotDocVersion reads a snapshot document for history/version viewing. When the snapshot file's path indicates an encrypted notebook (IsEncryptedBox), the code expects the stored document to be ciphertext and to be decrypted with the notebook DEK via DecryptFile. If the snapshot document is stored as plaintext (no encrypted second path part / no decryption step applied), the code refuses to process it because silently reading plaintext in an encrypted notebook would break the authenticated-encryption compatibility guarantees.","triggerScenarios":"Calling loadDocVersion/loadSnapshotDocVersion on a snapshot file belonging to a notebook registered as encrypted, where pathParts[1] is absent (document stored without an encrypted counterpart) so the plaintext branch of the decrypt-or-reject logic is reached.","commonSituations":"History snapshots created before encryption was enabled for the notebook, or after the notebook was switched to encrypted while old plaintext-format snapshots remain in the history index; also broken snapshot paths where the encrypted-part segment was lost.","solutions":["Verify the notebook is actually meant to be encrypted (check IsEncryptedBox(boxID)); if it should be plaintext, correct the notebook encryption flag instead of reading the snapshot","Recreate the history snapshot for that document so it is stored in the encrypted format, then retry","If the snapshot path is malformed (missing the encrypted path part), repair or regenerate the history index for the notebook","Do not attempt to bypass by patching out the check — existing encrypted data must remain readable only through authenticated decryption"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if model.IsEncryptedBox(boxID) { /* ensure snapshot was written after encryption was enabled */ }","typeGuard":null,"tryCatchPattern":"if err := model.LoadDocVersion(file); err != nil && strings.Contains(err.Error(), \"snapshot document is plaintext\") { // regenerate or resync history snapshot for this box }","preventionTips":["Keep encryption settings stable per notebook; do not toggle encryption after snapshots exist without regenerating them","After enabling notebook encryption, run a reindex/refresh of history data","Never manually edit or move files under the history snapshot store"],"tags":["history","encryption","snapshot","compatibility"],"backgroundTag":"incompatible-source-type","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"}