UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

20 lines (19 loc) • 737 B
//#region src/infra/exec-safety.ts const SHELL_METACHARS = /[;&|`$<>]/; const CONTROL_CHARS = /[\r\n]/; const QUOTE_CHARS = /["']/; const BARE_NAME_PATTERN = /^[A-Za-z0-9._+-]+$/; function isLikelyPath(e) { return e.startsWith(".") || e.startsWith("~") || e.includes("/") || e.includes("\\"); } /** Validates that a configured executable value cannot smuggle shell syntax. */ function isSafeExecutableValue(e) { if (!e) return false; const t = e.trim(); if (!t || t.includes("\0") || CONTROL_CHARS.test(t) || SHELL_METACHARS.test(t) || QUOTE_CHARS.test(t)) return false; if (isLikelyPath(t)) return true; if (t.startsWith("-")) return false; return BARE_NAME_PATTERN.test(t); } //#endregion export { isSafeExecutableValue as t };