diegosouzapw/OmniRoute · error · Error
Invalid path: directory traversal detected
Error message
Invalid path: directory traversal detected
What it means
Path-traversal guard error from safePath(): a requested path under BACKUP_DIR resolves outside the backup root (segments contained `..` or absolute components). It is a security sentinel — the caller-supplied toolId/backupId/name tried to escape the backups directory.
Solutions
- Sanitize toolId/backupId inputs — reject any path containing `..`, leading `/`, or drive letters
- Only pass identifiers previously produced by the backup listing API, never raw user paths
- Return 400 to the API client attempting traversal
- Keep the safePath() guard on every filesystem join under BACKUP_DIR
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/shared/services/backupService.ts:16 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/eee19f71ff3e745a.
Report an issue: GitHub.
Appendix: source
Thrown at src/shared/services/backupService.ts:16
import fs from "fs/promises";
import path from "path";
import { resolveDataDir } from "@/lib/dataPaths";
const BACKUP_DIR = path.join(resolveDataDir(), "backups");
const MAX_BACKUPS_PER_TOOL = 5;
/**
* Resolve a path within BACKUP_DIR and verify it stays within bounds.
* Throws if the resolved path escapes BACKUP_DIR (path traversal guard).
*/
function safePath(...segments: string[]): string {
const resolved = path.resolve(BACKUP_DIR, ...segments);
const base = path.resolve(BACKUP_DIR);
if (resolved !== base && !resolved.startsWith(base + path.sep)) {
throw new Error("Invalid path: directory traversal detected");
}
return resolved;
}
/**
* Get backup directory for a specific tool
*/
function getToolBackupDir(toolId: string) {
return safePath(toolId);
}
/**
* Ensure backup directory exists for a tool
*/
async function ensureBackupDir(toolId: string) {
const dir = getToolBackupDir(toolId);
await fs.mkdir(dir, { recursive: true });
return dir;View on GitHub (pinned to a179ffed5b)