siyuan-note/siyuan · error

encrypted notebook asset history is plaintext

Error message

encrypted notebook asset history is plaintext [%s]

What it means

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.

Solutions

  1. Encrypt the asset with the current kernel's encrypted-asset format and place it back in the history directory
  2. Regenerate the history snapshot from the encrypted notebook so assets are enveloped
  3. 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
Defensive patterns

Strategy: validation

Validate before calling

const head = fs.readFileSync(historyPath).subarray(0, MAGIC.length);
if (isEncryptedBox(boxID) && !head.equals(ENCRYPTED_ASSET_MAGIC)) { throw new Error('history asset is plaintext'); }

Try / catch

try { await rollbackAssetsHistory(p); } catch (e) { if (String(e).includes('is plaintext')) { await reencryptHistoryAsset(p, boxID); await rollbackAssetsHistory(p); } else { throw e; } }

Prevention

When it happens

Trigger: 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.

Common situations: Migrating history snapshots from a plaintext notebook into an encrypted notebook; downgraded kernel versions that wrote plaintext assets; manual edits to history files.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/2426131bd22943b7. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/history.go:583

	}

	from := historyPath
	// 从路径提取 boxID 判断是否加密笔记本的资源
	relPath := strings.TrimPrefix(filepath.ToSlash(historyPath), filepath.ToSlash(util.HistoryDir))
	relPath = strings.TrimPrefix(relPath, "/")
	pathParts := strings.SplitN(relPath, "/", 3)
	data, readErr := filelock.ReadFile(from)
	if readErr != nil {
		return readErr
	}
	encrypted := bytes.HasPrefix(data, encryptedAssetMagic)
	if encrypted && (len(pathParts) < 3 || !ast.IsNodeIDPattern(pathParts[1]) || !IsEncryptedBox(pathParts[1])) {
		return errors.New("encrypted asset history is missing valid notebook context")
	}
	to := filepath.Join(util.DataDir, "assets", filepath.Base(historyPath))
	if len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {
		if !encrypted {
			return fmt.Errorf("encrypted notebook asset history is plaintext [%s]", pathParts[1])
		}
		// 加密笔记本的资源回滚到笔记本级 assets 目录
		to = filepath.Join(util.DataDir, pathParts[1], "assets", filepath.Base(historyPath))
		if err = os.MkdirAll(filepath.Dir(to), 0755); err != nil {
			return
		}
	}

	if err = filelock.CopyNewtimes(from, to); err != nil {
		logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
		return
	}
	IncSync()
	util.PushMsg(Conf.Language(102), 3000)
	return nil
}

// validateHistoryPath 校验历史路径是否位于工作区内且属于历史目录。

View on GitHub (pinned to 9f775e8a12)