Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix: expand tilde CODEX_HOME during security preflight (#80)

ianw-oaibb4876d22cce
diff --git a/sdk/typescript/_bundled_plugin/scripts/config_preflight.py b/sdk/typescript/_bundled_plugin/scripts/config_preflight.py
index 4f7e73928..2cba25ed5 100644
--- a/sdk/typescript/_bundled_plugin/scripts/config_preflight.py
+++ b/sdk/typescript/_bundled_plugin/scripts/config_preflight.py
@@ -19,7 +19,7 @@ except ModuleNotFoundError: # pragma: no cover - Python 3.10 only
PLUGIN_ROOT = Path(__file__).resolve().parents[1]
DEFAULT_REGISTRY = PLUGIN_ROOT / "preflight" / "capability-profiles.toml"
-DEFAULT_CODEX_HOME = Path(os.environ.get("CODEX_HOME", Path.home() / ".codex"))
+DEFAULT_CODEX_HOME = Path(os.environ.get("CODEX_HOME", "~/.codex")).expanduser()
SYSTEM_CONFIG = Path("/etc/codex/config.toml")
DEFAULT_CONFIG = DEFAULT_CODEX_HOME / "config.toml"
VALID_SEVERITIES = {"block", "warn", "suggest"}
diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.ts
index 42e072732..0c2f0e210 100644
--- a/sdk/typescript/tests-ts/runtime.test.ts
+++ b/sdk/typescript/tests-ts/runtime.test.ts
@@ -1,3 +1,4 @@
+import { spawnSync } from "node:child_process";
import { existsSync, renameSync, symlinkSync } from "node:fs";
import {
chmod,
@@ -53,6 +54,7 @@ import {
requirePrivateOutputDirectory,
runWorkbench,
} from "../src/runtime.js";
+import { PLUGIN_ROOT } from "./plugin-root.js";
const temporaryDirectories: string[] = [];
const testPosix = process.platform === "win32" ? test.skip : test;
@@ -849,6 +851,69 @@ describe("runtime directories and plugin Python boundary", () => {
}
});
+ test("expands a tilde CODEX_HOME when discovering preflight configuration", async () => {
+ const root = await temporaryDirectory();
+ const home = join(root, "home");
+ const codexHome = join(home, ".codex");
+ const repository = join(root, "repository");
+ const configPath = join(codexHome, "config.toml");
+ await mkdir(codexHome, { recursive: true });
+ await mkdir(repository);
+ await writeFile(configPath, "[agents]\nmax_threads = 8\n");
+
+ const python = Bun.which("python3") ?? Bun.which("python");
+ expect(python).not.toBeNull();
+ const result = spawnSync(
+ python!,
+ [
+ "-I",
+ "-B",
+ join(PLUGIN_ROOT, "scripts", "config_preflight.py"),
+ "--profile",
+ "security_scan",
+ "--cwd",
+ repository,
+ "--runtime-check",
+ "delegation_available=true",
+ "--runtime-check",
+ "goal_tools_available=true",
+ "--multi-agent-runtime-owner",
+ "native",
+ "--multi-agent-runtime-version",
+ "v1",
+ "--multi-agent-runtime-provenance",
+ "app-server",
+ ],
+ {
+ encoding: "utf8",
+ env: {
+ ...process.env,
+ HOME: home,
+ USERPROFILE: home,
+ CODEX_HOME: "~/.codex",
+ },
+ },
+ );
+
+ expect(result.status).toBe(0);
+ expect(result.stderr).toBe("");
+ const payload = JSON.parse(result.stdout) as {
+ user_config_path: string;
+ config_paths: string[];
+ results: { capability: string; actual: number; source: string }[];
+ };
+ expect(payload.user_config_path).toBe(configPath);
+ expect(payload.config_paths).toEqual([
+ join("/", "etc", "codex", "config.toml"),
+ configPath,
+ ]);
+ expect(
+ payload.results.find(
+ (result) => result.capability === "usable_worker_slots_6",
+ ),
+ ).toMatchObject({ actual: 8, source: configPath });
+ });
+
test("runs workbench commands without credentials or generated bytecode", async () => {
const root = await temporaryDirectory();
const pluginRoot = join(root, "plugin");