Skip to content

Commit 920537d

Browse files
committed
fix: throw on blocked env vars instead of silent strip
- sanitizeEnv now throws with descriptive message listing the blocked keys, so callers cannot silently fall back to ambient process.env - Add JSDoc safety note to runSsh documenting that remoteCmd is executed by the remote shell and must use constant strings or shellQuote() for dynamic values
1 parent 10c4f22 commit 920537d

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

‎bin/lib/deploy.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ function validateInstanceName(name) {
2222

2323
const SSH_OPTS = ["-o", "StrictHostKeyChecking=accept-new", "-o", "LogLevel=ERROR"];
2424

25+
/** @param remoteCmd — executed by the remote shell. Use only constant strings
26+
* or values wrapped in shellQuote(). Never interpolate unsanitized input. */
2527
function runSsh(host, remoteCmd, opts = {}) {
2628
const args = [...SSH_OPTS];
2729
if (opts.tty) args.unshift("-t");

‎bin/lib/runner.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ const BLOCKED_ENV_VARS = new Set([
5050

5151
function sanitizeEnv(callerEnv) {
5252
if (!callerEnv) return {};
53-
const clean = {};
54-
for (const [k, v] of Object.entries(callerEnv)) {
55-
if (!BLOCKED_ENV_VARS.has(k)) clean[k] = v;
53+
const blocked = Object.keys(callerEnv).filter((k) => BLOCKED_ENV_VARS.has(k));
54+
if (blocked.length > 0) {
55+
throw new Error(`runArgv() does not allow overriding: ${blocked.join(", ")}`);
5656
}
57-
return clean;
57+
return { ...callerEnv };
5858
}
5959

6060
/**

‎test/deploy.test.js‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,18 @@ describe("deploy helpers", () => {
190190
assert.equal(out, outWithCwd);
191191
});
192192

193-
it("LD_PRELOAD in caller env is stripped", () => {
194-
const out = runCaptureArgv("printenv", ["LD_PRELOAD"], {
195-
env: { LD_PRELOAD: "/tmp/evil.so" },
196-
ignoreError: true,
197-
});
198-
assert.equal(out, "");
199-
});
200-
201-
it("NODE_OPTIONS in caller env is stripped", () => {
202-
const out = runCaptureArgv("printenv", ["NODE_OPTIONS"], {
203-
env: { NODE_OPTIONS: "--require=/tmp/evil.js" },
204-
ignoreError: true,
205-
});
206-
assert.equal(out, "");
193+
it("LD_PRELOAD in caller env throws", () => {
194+
assert.throws(
195+
() => runCaptureArgv("echo", ["x"], { env: { LD_PRELOAD: "/tmp/evil.so" } }),
196+
/does not allow overriding: LD_PRELOAD/
197+
);
198+
});
199+
200+
it("NODE_OPTIONS in caller env throws", () => {
201+
assert.throws(
202+
() => runCaptureArgv("echo", ["x"], { env: { NODE_OPTIONS: "--require=/tmp/evil.js" } }),
203+
/does not allow overriding: NODE_OPTIONS/
204+
);
207205
});
208206

209207
it("safe caller env vars pass through", () => {

0 commit comments

Comments
 (0)