openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.54 kB
JavaScript
import{c as resolveUserPath}from"./home-dir-DEN5DisQ.mjs";import{t as FsSafeError}from"./fs-safe-Bxzu1j4h.mjs";import{isPathInside}from"@openclaw/fs-safe/path";import{inspectPathPermissions,safeStat}from"@openclaw/fs-safe/permissions";
//!src/secrets/exec-provider-path-validation.ts
async function assertSecureExecCommandPath(e){const t=resolveUserPath(e.command);if(!t)throw new Error(`${e.label} must be an absolute path.`);const n=await safeStat(t);if(!n.ok)throw new Error(`${e.label} is not readable: ${t}`);if(n.isDir)throw new Error(`${e.label} must be a file: ${t}`);if(n.isSymlink)throw new Error(`${e.label} must not be a symlink: ${t}`);if(e.trustedDirs&&e.trustedDirs.length>0){if(!e.trustedDirs.map(e=>resolveUserPath(e)).some(e=>isPathInside(e,t)))throw new Error(`${e.label} is outside trustedDirs: ${t}`)}const r=await inspectPathPermissions(t);if(!r.ok)throw new Error(`${e.label} permissions could not be verified: ${t}`);if(r.worldWritable||r.groupWritable)throw new Error(`${e.label} permissions are too open: ${t}`);if(process.platform===`win32`&&r.source===`unknown`)throw new FsSafeError(`permission-unverified`,`${e.label} ACL verification unavailable on Windows for ${t}. Move the command to a path whose ACLs OpenClaw can verify; there is no provider-level bypass.`);if(process.platform!==`win32`&&typeof process.getuid===`function`&&n.uid!=null){const r=process.getuid();if(n.uid!==r)throw new Error(`${e.label} must be owned by the current user (uid=${r}): ${t}`)}return t}export{assertSecureExecCommandPath as t};