{"record":{"id":"441794687b127613","repo":"BigPizzaV3/CodexPlusPlus","slug":"backup-source-database-is-not-an-allowed-local-sto","errorCode":null,"errorMessage":"Backup source database is not an allowed local storage path","messagePattern":"Backup source database is not an allowed local storage path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-data/src/storage.rs","lineNumber":1012,"sourceCode":") -> anyhow::Result<PathBuf> {\n    let source_db = backup[\"source_db\"]\n        .as_str()\n        .filter(|path| !path.trim().is_empty())\n        .map(PathBuf::from)\n        .unwrap_or_else(|| fallback_db_path.to_path_buf());\n    if !source_db.is_file() {\n        anyhow::bail!(\n            \"Backup source database not found: {}\",\n            source_db.to_string_lossy()\n        );\n    }\n    let source_db = fs::canonicalize(source_db)?;\n    let allowed = allowed_db_paths\n        .iter()\n        .filter_map(|path| fs::canonicalize(path).ok())\n        .any(|path| path == source_db);\n    if !allowed {\n        anyhow::bail!(\"Backup source database is not an allowed local storage path\");\n    }\n    Ok(source_db)\n}\n\nfn schema_kind(db: &Connection) -> anyhow::Result<Option<SchemaKind>> {\n    if has_table(db, \"sessions\")? && has_columns(db, \"sessions\", &[\"id\", \"title\"])? {\n        if has_table(db, \"messages\")? && !has_columns(db, \"messages\", &[\"session_id\"])? {\n            return Ok(None);\n        }\n        return Ok(Some(SchemaKind::GenericSessions));\n    }\n    if has_table(db, \"threads\")? && has_columns(db, \"threads\", &[\"id\", \"title\", \"rollout_path\"])? {\n        return Ok(Some(SchemaKind::CodexThreads));\n    }\n    if has_table(db, \"automation_runs\")? && has_columns(db, \"automation_runs\", &[\"thread_id\"])? {\n        return Ok(Some(SchemaKind::CodexAutomationRuns));\n    }\n    Ok(None)","sourceCodeStart":994,"sourceCodeEnd":1030,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-data/src/storage.rs#L994-L1030","documentation":"After confirming the backup's source_db exists, backup_source_db canonicalizes it and bails unless it matches one of the allowed local storage database paths (allowed_db_paths, canonicalized). This is a path-safety whitelist: restore can only write into databases the adapter was explicitly configured to manage, not arbitrary SQLite files.","triggerScenarios":"Calling restore_backups where backup.source_db resolves to a real file that is not in the adapter's allowed_db_paths — foreign absolute path, symlink resolving elsewhere, or adapter configured with a different (narrower) allowlist.","commonSituations":"Backups taken on another machine/user account with different absolute paths; CODEX_HOME moved or symlinked so canonicalize() differs from the configured path; adapter constructed without the needed path in allowed_db_paths (see LauncherDataService candidate_db_paths).","solutions":["Construct the adapter with the actual DB location included in allowed_db_paths (compare canonicalized paths, not raw strings).","Rewrite backup.source_db to the local equivalent path under the current codex_home before restoring.","Check symlinks: ensure fs::canonicalize(source_db) equals one of the allowed paths; adjust symlinks or configuration.","Re-create the backup on the current machine so source_db records a local allowed path."],"exampleFix":"// before\nlet adapter = SQLiteStorageAdapter::new(); // default allowlist missing custom db location\n// after\nlet adapter = SQLiteStorageAdapter::new()\n    .with_allowed_db_paths(vec![fs::canonicalize(&my_db_path)?]); // include the real (canonical) path","handlingStrategy":"validation","validationCode":"let canonical = fs::canonicalize(Path::new(backup[\"source_db\"].as_str().unwrap()))?;\nlet allowed: bool = allowed_db_paths.iter()\n    .filter_map(|p| fs::canonicalize(p).ok())\n    .any(|p| p == canonical);\nif !allowed { anyhow::bail!(\"source_db {:?} not in allowlist; configure with_allowed_db_paths\", canonical); }","typeGuard":"fn in_allowlist(path: &Path, allowed: &[PathBuf]) -> bool {\n    fs::canonicalize(path).ok()\n        .map(|c| allowed.iter().filter_map(|p| fs::canonicalize(p).ok()).any(|a| a == c))\n        .unwrap_or(false)\n}","tryCatchPattern":"match storage.restore_backups(&backup) {\n    Ok(()) => {}\n    Err(e) if e.to_string().contains(\"not an allowed local storage path\") => {\n        eprintln!(\"{e}; reconfigure allowed_db_paths or re-anchor source_db\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Configure allowed_db_paths with canonicalized paths so symlinked homes compare correctly","Rewrite backup source_db to local paths when importing backups from other machines","Only construct backups through the library so source_db always records an allowed location","Compare canonical paths, never raw strings, when validating DB locations"],"tags":["path-safety","sqlite","restore","validation"],"backgroundTag":"permission-denied","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}