mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 23:31:24 +00:00
refactor(security): centralize host env policy and harden env ingestion
This commit is contained in:
@@ -140,6 +140,31 @@ describe("buildGatewayInstallPlan", () => {
|
||||
expect(plan.environment.HOME).toBe("/Users/me");
|
||||
});
|
||||
|
||||
it("drops dangerous config env vars before service merge", async () => {
|
||||
mockNodeGatewayPlanFixture({
|
||||
serviceEnvironment: {
|
||||
OPENCLAW_PORT: "3000",
|
||||
},
|
||||
});
|
||||
|
||||
const plan = await buildGatewayInstallPlan({
|
||||
env: {},
|
||||
port: 3000,
|
||||
runtime: "node",
|
||||
config: {
|
||||
env: {
|
||||
vars: {
|
||||
NODE_OPTIONS: "--require /tmp/evil.js",
|
||||
SAFE_KEY: "safe-value",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(plan.environment.NODE_OPTIONS).toBeUndefined();
|
||||
expect(plan.environment.SAFE_KEY).toBe("safe-value");
|
||||
});
|
||||
|
||||
it("does not include empty config env values", async () => {
|
||||
mockNodeGatewayPlanFixture();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { formatCliCommand } from "../cli/command-format.js";
|
||||
import { collectConfigEnvVars } from "../config/env-vars.js";
|
||||
import { collectConfigServiceEnvVars } from "../config/env-vars.js";
|
||||
import type { OpenClawConfig } from "../config/types.js";
|
||||
import { resolveGatewayLaunchAgentLabel } from "../daemon/constants.js";
|
||||
import { resolveGatewayProgramArguments } from "../daemon/program-args.js";
|
||||
@@ -67,7 +67,7 @@ export async function buildGatewayInstallPlan(params: {
|
||||
// Merge config env vars into the service environment (vars + inline env keys).
|
||||
// Config env vars are added first so service-specific vars take precedence.
|
||||
const environment: Record<string, string | undefined> = {
|
||||
...collectConfigEnvVars(params.config),
|
||||
...collectConfigServiceEnvVars(params.config),
|
||||
};
|
||||
Object.assign(environment, serviceEnvironment);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user