mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 22:09:57 +00:00
fix(security): harden shell env fallback startup env handling
This commit is contained in:
@@ -31,13 +31,21 @@ describe("config env vars", () => {
|
||||
|
||||
it("blocks dangerous startup env vars from config env", async () => {
|
||||
await withEnvOverride(
|
||||
{ BASH_ENV: undefined, SHELL: undefined, OPENROUTER_API_KEY: undefined },
|
||||
{
|
||||
BASH_ENV: undefined,
|
||||
SHELL: undefined,
|
||||
HOME: undefined,
|
||||
ZDOTDIR: undefined,
|
||||
OPENROUTER_API_KEY: undefined,
|
||||
},
|
||||
async () => {
|
||||
const config = {
|
||||
env: {
|
||||
vars: {
|
||||
BASH_ENV: "/tmp/pwn.sh",
|
||||
SHELL: "/tmp/evil-shell",
|
||||
HOME: "/tmp/evil-home",
|
||||
ZDOTDIR: "/tmp/evil-zdotdir",
|
||||
OPENROUTER_API_KEY: "config-key",
|
||||
},
|
||||
},
|
||||
@@ -45,11 +53,15 @@ describe("config env vars", () => {
|
||||
const entries = collectConfigRuntimeEnvVars(config as OpenClawConfig);
|
||||
expect(entries.BASH_ENV).toBeUndefined();
|
||||
expect(entries.SHELL).toBeUndefined();
|
||||
expect(entries.HOME).toBeUndefined();
|
||||
expect(entries.ZDOTDIR).toBeUndefined();
|
||||
expect(entries.OPENROUTER_API_KEY).toBe("config-key");
|
||||
|
||||
applyConfigEnvVars(config as OpenClawConfig);
|
||||
expect(process.env.BASH_ENV).toBeUndefined();
|
||||
expect(process.env.SHELL).toBeUndefined();
|
||||
expect(process.env.HOME).toBeUndefined();
|
||||
expect(process.env.ZDOTDIR).toBeUndefined();
|
||||
expect(process.env.OPENROUTER_API_KEY).toBe("config-key");
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import { isDangerousHostEnvVarName, normalizeEnvVarKey } from "../infra/host-env-security.js";
|
||||
import {
|
||||
isDangerousHostEnvOverrideVarName,
|
||||
isDangerousHostEnvVarName,
|
||||
normalizeEnvVarKey,
|
||||
} from "../infra/host-env-security.js";
|
||||
import type { OpenClawConfig } from "./types.js";
|
||||
|
||||
function isBlockedConfigEnvVar(key: string): boolean {
|
||||
return isDangerousHostEnvVarName(key) || isDangerousHostEnvOverrideVarName(key);
|
||||
}
|
||||
|
||||
function collectConfigEnvVarsByTarget(cfg?: OpenClawConfig): Record<string, string> {
|
||||
const envConfig = cfg?.env;
|
||||
if (!envConfig) {
|
||||
@@ -18,7 +26,7 @@ function collectConfigEnvVarsByTarget(cfg?: OpenClawConfig): Record<string, stri
|
||||
if (!key) {
|
||||
continue;
|
||||
}
|
||||
if (isDangerousHostEnvVarName(key)) {
|
||||
if (isBlockedConfigEnvVar(key)) {
|
||||
continue;
|
||||
}
|
||||
entries[key] = value;
|
||||
@@ -36,7 +44,7 @@ function collectConfigEnvVarsByTarget(cfg?: OpenClawConfig): Record<string, stri
|
||||
if (!key) {
|
||||
continue;
|
||||
}
|
||||
if (isDangerousHostEnvVarName(key)) {
|
||||
if (isBlockedConfigEnvVar(key)) {
|
||||
continue;
|
||||
}
|
||||
entries[key] = value;
|
||||
|
||||
Reference in New Issue
Block a user