"use strict"; // Shared mount-path validator for node disks (panel side, admin-only disk API). // The daemon mirrors this exact list in main.go pathAllowedForDisk — keep the // two in sync: a disk accepted by the panel but refused by the daemon (or vice // versa) would leave the two sides of the disk inventory disagreeing. function validateDiskMountPathPanel(p) { const s = String(p || "").trim(); if (!s) return { ok: false, error: "mount path required" }; if (!s.startsWith("/")) return { ok: false, error: "mount path must be absolute" }; if (s.includes("..") || s.includes("\0")) return { ok: false, error: "invalid mount path" }; if (s.length > 1 && s.endsWith("/")) return { ok: false, error: "mount path must not end with '/'" }; // System trees that must never host server storage volumes. /var/lib covers // the daemon's own /var/lib/node tree; /run and /var/run are the same tmpfs. const denied = ["/", "/var/lib", "/var/log", "/var/run", "/run", "/srv", "/opt", "/tmp", "/home", "/etc", "/proc", "/sys", "/dev", "/boot", "/root", "/bin", "/sbin", "/usr", "/lib", "/lib64"]; for (const d of denied) { if (s === d || s.startsWith(d + "/")) return { ok: false, error: `mount path ${s} is not allowed` }; } return { ok: true, value: s }; } module.exports = { validateDiskMountPathPanel };