mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
fix: harden host exec env validation (#4896) (thanks @HassanFleyah)
This commit is contained in:
@@ -109,3 +109,17 @@ describe("exec PATH login shell merge", () => {
|
||||
expect(shellPathMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("exec host env validation", () => {
|
||||
it("blocks LD_/DYLD_ env vars on host execution", async () => {
|
||||
const { createExecTool } = await import("./bash-tools.exec.js");
|
||||
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
|
||||
|
||||
await expect(
|
||||
tool.execute("call1", {
|
||||
command: "echo ok",
|
||||
env: { LD_DEBUG: "1" },
|
||||
}),
|
||||
).rejects.toThrow(/Security Violation: Environment variable 'LD_DEBUG' is forbidden/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -76,6 +76,7 @@ const DANGEROUS_HOST_ENV_VARS = new Set([
|
||||
"IFS",
|
||||
"SSLKEYLOGFILE",
|
||||
]);
|
||||
const DANGEROUS_HOST_ENV_PREFIXES = ["DYLD_", "LD_"];
|
||||
|
||||
// Centralized sanitization helper.
|
||||
// Throws an error if dangerous variables or PATH modifications are detected on the host.
|
||||
@@ -84,6 +85,11 @@ function validateHostEnv(env: Record<string, string>): void {
|
||||
const upperKey = key.toUpperCase();
|
||||
|
||||
// 1. Block known dangerous variables (Fail Closed)
|
||||
if (DANGEROUS_HOST_ENV_PREFIXES.some((prefix) => upperKey.startsWith(prefix))) {
|
||||
throw new Error(
|
||||
`Security Violation: Environment variable '${key}' is forbidden during host execution.`,
|
||||
);
|
||||
}
|
||||
if (DANGEROUS_HOST_ENV_VARS.has(upperKey)) {
|
||||
throw new Error(
|
||||
`Security Violation: Environment variable '${key}' is forbidden during host execution.`,
|
||||
|
||||
Reference in New Issue
Block a user