Skip to content

Commit dac4bf5

Browse files
committed
fix(qa): block exported Bash functions
1 parent 9ef352a commit dac4bf5

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎extensions/qa-lab/src/gateway-child-env.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ function scrubQaGatewayChildEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
3434
for (const envKey of QA_GATEWAY_CHILD_BLOCKED_ENV_VARS) {
3535
delete env[envKey];
3636
}
37+
// Bash imports exported functions before the launcher can apply its allowlist.
38+
for (const envKey of Object.keys(env)) {
39+
if (envKey.startsWith("BASH_FUNC_")) {
40+
delete env[envKey];
41+
}
42+
}
3743
return env;
3844
}
3945

‎extensions/qa-lab/src/gateway-child.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ describe("buildQaRuntimeEnv", () => {
812812
OPENCLAW_QA_TELEGRAM_GROUP_ID: "-1001234567890",
813813
OPENCLAW_QA_TELEGRAM_DRIVER_BOT_TOKEN: "driver-token",
814814
OPENCLAW_QA_TELEGRAM_SUT_BOT_TOKEN: "sut-token",
815+
"BASH_FUNC_sudo%%": "() { printf imported; }",
815816
},
816817
});
817818

@@ -823,13 +824,15 @@ describe("buildQaRuntimeEnv", () => {
823824
expect(env.OPENCLAW_QA_TELEGRAM_GROUP_ID).toBeUndefined();
824825
expect(env.OPENCLAW_QA_TELEGRAM_DRIVER_BOT_TOKEN).toBeUndefined();
825826
expect(env.OPENCLAW_QA_TELEGRAM_SUT_BOT_TOKEN).toBeUndefined();
827+
expect(env["BASH_FUNC_sudo%%"]).toBeUndefined();
826828
});
827829

828830
it.runIf(process.platform === "linux")(
829831
"scrubs inherited shell startup env before the workflow allowlist runs",
830832
async () => {
831833
const tempRoot = await tempDirs.makeTempDir("qa-shell-startup-env-");
832834
const markerPath = path.join(tempRoot, "bash-env-ran");
835+
const functionMarkerPath = path.join(tempRoot, "bash-function-ran");
833836
const bashEnvPath = path.join(tempRoot, "malicious-bash-env");
834837
const allowlistProbePath = path.join(tempRoot, "allowlist-probe.sh");
835838
await writeFile(bashEnvPath, `printf 'ran' > ${JSON.stringify(markerPath)}\n`, "utf8");
@@ -858,12 +861,14 @@ describe("buildQaRuntimeEnv", () => {
858861
BASHOPTS: "checkwinsize",
859862
ENV: bashEnvPath,
860863
SHELLOPTS: "braceexpand",
864+
"BASH_FUNC_compgen%%": `() { printf 'ran' > ${JSON.stringify(functionMarkerPath)}; builtin compgen "$@"; }`,
861865
},
862866
});
863867

864868
for (const key of ["BASH_ENV", "BASHOPTS", "ENV", "SHELLOPTS"]) {
865869
expect(env[key]).toBeUndefined();
866870
}
871+
expect(env["BASH_FUNC_compgen%%"]).toBeUndefined();
867872

868873
const result = spawnSync("/bin/bash", ["--noprofile", "--norc", allowlistProbePath], {
869874
encoding: "utf8",
@@ -873,6 +878,7 @@ describe("buildQaRuntimeEnv", () => {
873878
expect(result.status, result.stderr).toBe(0);
874879
expect(result.stdout).toBe("allowlist-survived");
875880
await expect(readFile(markerPath, "utf8")).rejects.toMatchObject({ code: "ENOENT" });
881+
await expect(readFile(functionMarkerPath, "utf8")).rejects.toMatchObject({ code: "ENOENT" });
876882
},
877883
);
878884

0 commit comments

Comments
 (0)