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 trailing whitespace in POSIX scan roots (#2552)
Michael D'Angelocd47bb2b98ab
diff --git a/plugins/codex-security/mcp-app/src/workbench-client.ts b/plugins/codex-security/mcp-app/src/workbench-client.tsindex 983d87f58..cb509af73 100644--- a/plugins/codex-security/mcp-app/src/workbench-client.ts+++ b/plugins/codex-security/mcp-app/src/workbench-client.ts@@ -10,7 +10,13 @@ import {import { WORKBENCH_PYTHON } from "./server/workbench-process.js";const execFileAsync = promisify(execFile);-const CONFIGURED_SCAN_ROOT = process.env.CODEX_SECURITY_SCAN_ROOT?.trim();+const configuredScanRoot = process.env.CODEX_SECURITY_SCAN_ROOT;+// A padded absolute or home-relative override must keep its original base.+const CONFIGURED_SCAN_ROOT =+ process.platform !== "win32" &&+ configuredScanRoot?.trimStart() === configuredScanRoot+ ? configuredScanRoot+ : configuredScanRoot?.trim();export const PLUGIN_ROOT =process.env.CODEX_SECURITY_PLUGIN_ROOT || resolve(__dirname, "..");diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_storage.ts b/plugins/codex-security/mcp-app/tests/test_artifact_storage.tsindex 6d545cd5a..b40255ec4 100644--- a/plugins/codex-security/mcp-app/tests/test_artifact_storage.ts+++ b/plugins/codex-security/mcp-app/tests/test_artifact_storage.ts@@ -365,18 +365,33 @@ try {content,);- await client.close();- client = await connect({- CODEX_SECURITY_SCAN_ROOT: path.join(stateAlias, "missing", "scans"),- });- const relocated = await save({- targetPath: repository,- storage: "persistent",- });- assert.ok(- relocated.directory.startsWith(- path.join(stateRoot, "missing", "scans") + path.sep,- ),+ const rootName = process.platform === "win32" ? "scans" : "scans ";+ for (const [configured, expected] of [+ [+ path.join(stateAlias, "missing", rootName),+ path.join(stateRoot, "missing", rootName),+ ],+ [+ ` ${path.join(stateAlias, "padded", "scans")} `,+ path.join(stateRoot, "padded", "scans"),+ ],+ ]) {+ await client.close();+ client = await connect({ CODEX_SECURITY_SCAN_ROOT: configured });+ const relocated = await save({+ targetPath: repository,+ storage: "persistent",+ });+ assert.ok(relocated.directory.startsWith(expected + path.sep));+ }+ if (process.platform !== "win32")+ await assert.rejects(stat(path.join(stateRoot, "missing", "scans")), {+ code: "ENOENT",+ });+ assert.equal(+ (await read({ ...identity, storage: "persistent", path: relativePath }))+ .content,+ content,);const linkedScanRoot = path.join(fixture, "linked-scans");diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.tsindex 759ec571b..6476ba7fc 100644--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.ts+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.ts@@ -56,6 +56,7 @@ async function testDeepScanStdioLifecycle() {const failedTargetPath = path.join(fixtureRoot, "failed-target");const expiredTargetPath = path.join(fixtureRoot, "expired-target");const stateDir = path.join(fixtureRoot, "state]");+ const scanRoot = path.join(await realpath(fixtureRoot), "scans ");const codexHome = path.join(fixtureRoot, "codex [home]");const installedPluginRoot = path.join(codexHome, "plugins", "installed");const runtimeConfigPath = path.join(fixtureRoot, "active-config.toml");@@ -192,7 +193,7 @@ service_tier = "ultrafast"CODEX_HOME: codexHome,CODEX_SECURITY_CONFIG_PATH: runtimeConfigPath,CODEX_SECURITY_PLUGIN_ROOT: pluginRoot,- CODEX_SECURITY_SCAN_ROOT: path.join(fixtureRoot, "scans"),+ CODEX_SECURITY_SCAN_ROOT: scanRoot,CODEX_SECURITY_STATE_DIR: stateDir,PYTHON: pythonWrapperPath,CODEX_SECURITY_PYTHON_COMMAND: pythonWrapperPath,@@ -343,6 +344,7 @@ service_tier = "ultrafast"assert.match(startedWorker.stdin, /record_codex_security_scan_draft/);const startedState = await getDeepScan({ environment, scanId, threadId });assert.equal(startedState.config.maxTimeHours, 0.5);+ assert.ok(startedState.scanDir.startsWith(scanRoot + path.sep));await rm(projectConfigPath);const startedArtifactRoot = startedState.workers.find((worker: PersistedDeepScanWorker) => worker.kind === "discovery",@@ -774,6 +776,7 @@ service_tier = "ultrafast");const resumedScan = started.structuredContent.workspace.results;const resumedScanId = resumedScan.scanId;+ assert.ok(resumedScan.scanDir.startsWith(scanRoot + path.sep));await chmod(resumedScan.scanDir, 0o755);const handoffClaimToken = randomUUID();for (const [id, name, arguments_] of [diff --git a/plugins/codex-security/references/artifact-storage.md b/plugins/codex-security/references/artifact-storage.mdindex 5c6401505..7a013be8d 100644--- a/plugins/codex-security/references/artifact-storage.md+++ b/plugins/codex-security/references/artifact-storage.md@@ -22,7 +22,7 @@ Select `storage` explicitly:- `persistent`: retained documents/evidence under the authoritative scan directory or standalone collection. The default root is `$CODEX_SECURITY_STATE_DIR/scans`, or `$CODEX_HOME/state/plugins/codex-security/scans` when no state override is set; `CODEX_HOME` defaults to `~/.codex`. The existing `CODEX_SECURITY_SCAN_ROOT` override still takes precedence for plugin-created output. The workbench state directory must be writable; set `CODEX_SECURITY_STATE_DIR` explicitly on hosts with an unwritable default. Preserve an existing scan's saved path, including older temporary paths.- `temporary`: disposable staging and execution output in a context-specific OS temporary directory. Standalone temporary saves and reads do not create or require the persistent collection. It is not part of the completed result and must not be referenced from canonical findings or coverage. It can disappear independently of retained files.-Relative storage overrides resolve from the plugin directory, matching the workbench, regardless of the MCP launch directory.+Relative storage overrides resolve from the plugin directory, matching the workbench, regardless of the MCP launch directory. On POSIX, `CODEX_SECURITY_SCAN_ROOT` preserves trailing whitespace. A value with leading padding is trimmed. Use an absolute path or a `./` prefix for a relative directory name that begins with whitespace.Omit `path`, `content` and `sourcePath` to prepare the selected directory. Use the returned `directory`; never construct or guess the physical path. A save with a file requires `path` plus exactly one of `content` or `sourcePath`.