mirror of
https://github.com/prompt-security/clawsec.git
synced 2026-06-19 16:31:20 +03:00
fix(openclaw-audit-watchdog): escape shell env interpolation in setup_cron
This commit is contained in:
@@ -53,7 +53,16 @@ function oneline(v) {
|
||||
return String(v ?? "")
|
||||
.replace(/[\r\n]+/g, " ")
|
||||
.replace(/"/g, "\\\"")
|
||||
.trim();
|
||||
}
|
||||
|
||||
function escapeForShellEnvVar(v) {
|
||||
return String(v ?? "")
|
||||
.replace(/[\r\n]+/g, " ")
|
||||
.replace(/\\/g, "\\\\")
|
||||
.replace(/\$/g, "\\$")
|
||||
.replace(/`/g, "\\`")
|
||||
.replace(/"/g, "\\\"")
|
||||
.trim();
|
||||
}
|
||||
|
||||
@@ -66,7 +75,9 @@ function defaultInstallDir() {
|
||||
}
|
||||
|
||||
function buildAgentMessage({ dmChannel, dmTo, hostLabel, installDir }) {
|
||||
const safeDir = oneline(installDir || "");
|
||||
const safeDir = escapeForShellEnvVar(installDir || "");
|
||||
const escapedHostLabel = escapeForShellEnvVar(hostLabel);
|
||||
|
||||
return [
|
||||
"Run daily openclaw security audits and deliver report (DM + email).",
|
||||
"",
|
||||
@@ -74,7 +85,7 @@ function buildAgentMessage({ dmChannel, dmTo, hostLabel, installDir }) {
|
||||
`Email: ${COMPANY_EMAIL} (local sendmail)`,
|
||||
"",
|
||||
"Execute:",
|
||||
`- Run via exec: cd "${safeDir}" && PROMPTSEC_HOST_LABEL="${oneline(hostLabel)}" ./scripts/runner.sh`,
|
||||
`- Run via exec: cd "${safeDir}" && PROMPTSEC_HOST_LABEL="${escapedHostLabel}" ./scripts/runner.sh`,
|
||||
"",
|
||||
"Output requirements:",
|
||||
"- Print the report to stdout (cron deliver will DM it).",
|
||||
|
||||
Reference in New Issue
Block a user