diegosouzapw/OmniRoute · error · Error
Invalid backup ID: path traversal detected
Error message
Invalid backup ID: path traversal detected
What it means
Security guard in restoreDbBackup: although the backupId already passed the format check (db_*.sqlite, no separators), the resolved absolute path escaped the backup directory, so the caller-supplied ID is rejected to prevent restoring an arbitrary file outside the backups folder via path traversal.
Solutions
- Pass only IDs that were produced by the backup listing/creation API, never user-typed file names
- Remove any ../ or path-like characters from the ID at the caller before calling restore
- Log the offending ID to detect malicious or buggy callers attempting traversal
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/lib/db/backup.ts:384 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/8c0c368696b4c3c5.
Report an issue: GitHub.
Appendix: source
Thrown at src/lib/db/backup.ts:384
const backupDir = getBackupDir();
// Validate format: must be db_<timestamp>_<reason>.sqlite, no path separators
if (
!backupId.startsWith("db_") ||
!backupId.endsWith(".sqlite") ||
backupId.includes(path.sep) ||
backupId.includes("/")
) {
throw new Error("Invalid backup ID");
}
const backupPath = path.resolve(backupDir, backupId);
// Prevent path traversal: resolved path must stay within backupDir
if (
!backupPath.startsWith(path.resolve(backupDir) + path.sep) &&
backupPath !== path.resolve(backupDir)
) {
throw new Error("Invalid backup ID: path traversal detected");
}
if (!fs.existsSync(backupPath)) {
throw new Error(`Backup not found: ${backupId}`);
}
// Validate backup integrity
try {
const { tryOpenSync } = await import("@/lib/db/adapters/driverFactory");
const testDb = tryOpenSync(backupPath, { readonly: true });
if (!testDb) {
throw new Error("Backup file is corrupt: could not open");
}
let result: Array<{ integrity_check?: string }>;
try {
result = testDb.pragma("integrity_check") as Array<{ integrity_check?: string }>;
} finally {
testDb.close();View on GitHub (pinned to a179ffed5b)