OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(plugin): preserve closed stdin when launching helpers (#1329)
mldangelo-oai0f2ba8fedd22
diff --git a/plugins/codex-security/scripts/launch_codex_security_mcp b/plugins/codex-security/scripts/launch_codex_security_mcpindex cc4557bc2..6e9847ff5 100755--- a/plugins/codex-security/scripts/launch_codex_security_mcp+++ b/plugins/codex-security/scripts/launch_codex_security_mcp@@ -15,7 +15,11 @@ launch_node() {if [ "${1:-}" = "--helper" ]; thenshift# Preserve POSIX argv and HOME bytes without temporary files or consuming stdin.- exec 4<&0+ helper_stdin=-+ if (exec 4<&0) 2>&-; then+ exec 4<&0+ helper_stdin=4+ fiwait_helper() {if wait "$!" 2>&-; then exit 0; else exit $?; fi}@@ -30,7 +34,7 @@ launch_node() {trap 'forward_signal INT 130' INTtrap 'forward_signal TERM 143' TERMprintf '%s\000' "${HOME+x}" "${HOME-}" "$@" | od -An -v -tx1 | tr -d ' \n' |- "$node_command" "$server_path" --helper 3<&0 0<&4 4<&- &+ "$node_command" "$server_path" --helper 3<&0 0<&"$helper_stdin" 4<&- &exec 4<&-wait_helperfidiff --git a/sdk/typescript/tests-ts/mcp-launcher.test.ts b/sdk/typescript/tests-ts/mcp-launcher.test.tsindex 73f44d673..2339d887a 100644--- a/sdk/typescript/tests-ts/mcp-launcher.test.ts+++ b/sdk/typescript/tests-ts/mcp-launcher.test.ts@@ -194,6 +194,66 @@ process.exitCode = 23;},);+test.skipIf(process.platform === "win32")(+ "launches argument-only helpers with closed stdin",+ async () => {+ const node = Bun.which("node");+ if (node === null)+ throw new Error("Node is required for the launcher test.");+ const root = await realpath(+ await mkdtemp(join(tmpdir(), "codex-security-helper-closed-stdin-")),+ );+ try {+ const scripts = join(root, "plugin with spaces", "scripts");+ const mcp = join(root, "plugin with spaces", "mcp");+ await mkdir(scripts, { recursive: true });+ await mkdir(mcp);+ const launcher = join(scripts, "launch_codex_security_mcp");+ await copyFile(+ join(PLUGIN_ROOT, "scripts", "launch_codex_security_mcp"),+ launcher,+ );+ await chmod(launcher, 0o700);+ await writeFile(+ join(mcp, "helpers.mjs"),+ `import { readFileSync } from "node:fs";+const payload = Buffer.from(readFileSync(3, "ascii").trim(), "hex");+console.log(JSON.stringify({ payload: payload.toString("hex") }));+process.exitCode = 23;+`,+ );+ const result = spawnSync(+ "/bin/sh",+ [+ "-c",+ 'exec 0<&-; exec "$1" --helper probe "argument with spaces"',+ "helper-test",+ launcher,+ ],+ {+ encoding: "utf8",+ env: { ...process.env, CODEX_MCP_NODE_PATH: node },+ },+ );+ expect(result.status, result.stderr || result.error?.message).toBe(23);+ expect(result.stderr).toBe("");+ expect(JSON.parse(result.stdout)).toEqual({+ payload: Buffer.from(+ [+ process.env["HOME"] === undefined ? "" : "x",+ process.env["HOME"] ?? "",+ "probe",+ "argument with spaces",+ "",+ ].join("\0"),+ ).toString("hex"),+ });+ } finally {+ await removeTemporaryDirectory(root);+ }+ },+);+for (const mode of ["managed", "PATH"] as const) {test.skipIf(process.platform !== "darwin")(`resolves security policy with ${mode} Node and filesystem writes denied`,