{"record":{"id":"eaf439255d3ac285","repo":"siyuan-note/siyuan","slug":"missing-encrypted-index-setting-s","errorCode":null,"errorMessage":"missing encrypted index setting %s","messagePattern":"missing encrypted index setting (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/encrypted_index.go","lineNumber":24,"sourceCode":"\nimport (\n\t\"database/sql\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n)\n\n// CheckEncryptedIndexCompatibility 将索引版本保存在受 SQLCipher 认证的表中，拒绝复用缺少版本或参数不匹配的旧索引。\n// schema 由各索引维护，修改表结构时递增；索引重建由已认证源文档的调用方负责。\nfunc CheckEncryptedIndexCompatibility(db *sql.DB, kind string, schema int) error {\n\tsettings := map[string]string{}\n\tfor _, name := range []string{\"cipher_version\", \"cipher_page_size\", \"kdf_iter\", \"cipher_hmac_algorithm\", \"cipher_kdf_algorithm\", \"cipher_use_hmac\"} {\n\t\tvar value string\n\t\tif err := db.QueryRow(\"PRAGMA \" + name).Scan(&value); err != nil {\n\t\t\treturn fmt.Errorf(\"read encrypted index setting %s: %w\", name, err)\n\t\t}\n\t\tif value == \"\" {\n\t\t\treturn fmt.Errorf(\"missing encrypted index setting %s\", name)\n\t\t}\n\t\tsettings[name] = value\n\t}\n\tencoded, err := json.Marshal(settings)\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar metadataTables int\n\tif err = db.QueryRow(\"SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name = 'encrypted_index_meta'\").Scan(&metadataTables); err != nil {\n\t\treturn err\n\t}\n\tif metadataTables == 0 {\n\t\tvar tables int\n\t\tif err = db.QueryRow(\"SELECT count(*) FROM sqlite_master WHERE type = 'table'\").Scan(&tables); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif tables != 0 {\n\t\t\treturn errors.New(\"encrypted index has no compatibility metadata\")","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/encrypted_index.go#L6-L42","documentation":"CheckEncryptedIndexCompatibility requires every SQLCipher cipher PRAGMA (cipher_version, cipher_page_size, kdf_iter, cipher_hmac_algorithm, cipher_kdf_algorithm, cipher_use_hmac) to return a non-empty value. An empty value means cipher settings are not visible on this connection, so compatibility cannot be authenticated and the index is rejected.","triggerScenarios":"Opening an encrypted index whose PRAGMA query succeeds but returns an empty string for one of the six settings — e.g. the DB was opened without the SQLCipher key so cipher PRAGMAs are unset, or an index created by a driver lacking one of the settings.","commonSituations":"Index file created before encryption finished initializing (interrupted first open); driver version change making a PRAGMA unimplemented; a plain (unencrypted) index opened through the encrypted-open path.","solutions":["Identify the empty setting from the error message and compare with the SQLCipher version in use","Delete and let the caller rebuild the index from authenticated source documents (the sanctioned recovery path)","Restore the index from sync snapshot or backup if rebuilding is undesirable","Ensure the same SQLCipher build/version is used across kernel upgrades"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"for _, p := range []string{\"cipher_version\",\"cipher_page_size\",\"kdf_iter\"} {\n    var v string\n    db.QueryRow(\"PRAGMA \" + p).Scan(&v)\n    if v == \"\" { /* rebuild index from authenticated source */ }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat an empty cipher PRAGMA as a signal to rebuild, never to bypass","Keep kernel and SQLCipher versions consistent across machines in a sync group","Let the kernel create encrypted indexes itself; do not copy plain index files in"],"tags":["database","encryption","sqlcipher","pragma"],"backgroundTag":"missing-config-value","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"}