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(scan): isolate Git pathspec modes for file inventories (#2565)
Michael D'Angeloa86445c84151
diff --git a/plugins/codex-security/mcp-app/src/helpers/inventory-git.ts b/plugins/codex-security/mcp-app/src/helpers/inventory-git.tsindex 6a3403a33..3c233794f 100644--- a/plugins/codex-security/mcp-app/src/helpers/inventory-git.ts+++ b/plugins/codex-security/mcp-app/src/helpers/inventory-git.ts@@ -54,6 +54,8 @@ const repositoryEnvironment = ["GIT_COMMON_DIR","GIT_DIR","GIT_DISCOVERY_ACROSS_FILESYSTEM",+ "GIT_GLOB_PATHSPECS",+ "GIT_ICASE_PATHSPECS","GIT_INDEX_FILE","GIT_LITERAL_PATHSPECS","GIT_NAMESPACE",diff --git a/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts b/plugins/codex-security/mcp-app/tests/support/fake-codex-source.tsindex 3ac8307a8..e5f1dd08a 100644--- a/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts+++ b/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts@@ -21,7 +21,7 @@ const accountResult = ${JSON.stringify(accountResult)};const preflightMarkerPath = process.env.FAKE_CODEX_PREFLIGHT_MARKER ?? ${JSON.stringify(preflightMarkerPath)};const temporaryEnvironment = Object.fromEntries(['TEMP', 'TMP'].map(name => [name, process.env[name]]));if (process.argv.includes('app-server')) {- const preflight = { executablePath: process.argv[1], argv: process.argv.slice(2), configPath: process.env.CODEX_SECURITY_CONFIG_PATH, stateDirectory: process.env.CODEX_SECURITY_STATE_DIR, temporaryEnvironment, runnerTrackingId: process.env.RUNNER_TRACKING_ID, libraryPath: process.env["LD_LIBRARY_PATH"], cwd: process.cwd(), codexHome: process.env.CODEX_HOME, providerKey: process.env.SYNTHETIC_GATEWAY_KEY, providerHeaders: Object.fromEntries(['SYNTHETIC_HEADER_VALUE', 'OPENROUTER_API_KEY', 'FIREWORKS_API_KEY'].map(name => [name, process.env[name]])), providerHeader: process.env.SYNTHETIC_HEADER_VALUE, cacheDirectory: process.env.XDG_CACHE_HOME, gitEnvironment: Object.fromEntries(['PATH', 'HOME', 'NODE_OPTIONS', 'NODE_DEBUG', 'NODE_EXTRA_CA_CERTS', 'CODEX_MCP_NODE_PATH', 'CODEX_SECURITY_GIT', 'GIT_SSH_COMMAND', 'GIT_CONFIG_GLOBAL'].map(name => [name, process.env[name]])), requests: [] };+ const preflight = { executablePath: process.argv[1], argv: process.argv.slice(2), configPath: process.env.CODEX_SECURITY_CONFIG_PATH, stateDirectory: process.env.CODEX_SECURITY_STATE_DIR, temporaryEnvironment, runnerTrackingId: process.env.RUNNER_TRACKING_ID, libraryPath: process.env["LD_LIBRARY_PATH"], cwd: process.cwd(), codexHome: process.env.CODEX_HOME, providerKey: process.env.SYNTHETIC_GATEWAY_KEY, providerHeaders: Object.fromEntries(['SYNTHETIC_HEADER_VALUE', 'OPENROUTER_API_KEY', 'FIREWORKS_API_KEY'].map(name => [name, process.env[name]])), providerHeader: process.env.SYNTHETIC_HEADER_VALUE, cacheDirectory: process.env.XDG_CACHE_HOME, gitEnvironment: Object.fromEntries(['PATH', 'HOME', 'NODE_OPTIONS', 'NODE_DEBUG', 'NODE_EXTRA_CA_CERTS', 'CODEX_MCP_NODE_PATH', 'CODEX_SECURITY_GIT', 'GIT_SSH_COMMAND', 'GIT_CONFIG_GLOBAL', 'GIT_GLOB_PATHSPECS', 'GIT_ICASE_PATHSPECS'].map(name => [name, process.env[name]])), requests: [] };writeFileSync(preflightMarkerPath, JSON.stringify(preflight));${jsonLineInputSource(` if (message.method === 'initialized') continue;if (message.method === 'config/read' || message.method === 'permissionProfile/list') {@@ -80,7 +80,7 @@ const pythonRuntime = pythonProbe ? JSON.parse(pythonProbe.stdout) : undefined;const knowledgePath = stdin.includes('synthetic worker configuration fixture') ? process.env.CODEX_SECURITY_KNOWLEDGE_BASE : undefined;const knowledgeDocuments = knowledgePath === undefined ? undefined : Object.fromEntries(readdirSync(knowledgePath).map(name => [name, readFileSync(join(knowledgePath, name), 'utf8')]));const deepConfig = process.env.CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH ? readFileSync(process.env.CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH, 'utf8') : undefined;-writeFileSync(process.env.FAKE_CODEX_MARKER, JSON.stringify({ executablePath: process.argv[1], ...(scopeInput === undefined ? {} : { scopeInput }), argv: process.argv.slice(2), stdin, cwd: process.cwd(), knowledgePath, knowledgeDocuments, deepConfig, codexHome: process.env.CODEX_HOME, temporaryEnvironment, cacheDirectory: process.env.XDG_CACHE_HOME, gitEnvironment: Object.fromEntries(['PATH', 'HOME', 'NODE_OPTIONS', 'NODE_DEBUG', 'NODE_EXTRA_CA_CERTS', 'CODEX_MCP_NODE_PATH', 'CODEX_SECURITY_GIT', 'GIT_SSH_COMMAND', 'GIT_CONFIG_GLOBAL'].map(name => [name, process.env[name]])), configPath: process.env.CODEX_SECURITY_CONFIG_PATH, deepConfigPath: process.env.CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH, python: process.env.PYTHON, mcpNodePath: process.env.CODEX_MCP_NODE_PATH, bundledTool: toolProbe?.stdout.trim(), pythonPrefix: pythonRuntime?.[0], pythonLibraryPath: pythonRuntime?.[1], runtimeEnvironment, codexConfig, providerHeaders: Object.fromEntries(['SYNTHETIC_HEADER_VALUE', 'OPENROUTER_API_KEY', 'FIREWORKS_API_KEY'].map(name => [name, process.env[name]])), providerKey: process.env.SYNTHETIC_GATEWAY_KEY, providerHeader: process.env.SYNTHETIC_HEADER_VALUE, originator: process.env.CODEX_INTERNAL_ORIGINATOR_OVERRIDE, ...(profileContents === undefined ? {} : { profileContents }), ...(openaiAuthentication ? { openaiAuthentication } : {}), ...(bedrockAuthentication ? { bedrockAuthentication } : {}) }));+writeFileSync(process.env.FAKE_CODEX_MARKER, JSON.stringify({ executablePath: process.argv[1], ...(scopeInput === undefined ? {} : { scopeInput }), argv: process.argv.slice(2), stdin, cwd: process.cwd(), knowledgePath, knowledgeDocuments, deepConfig, codexHome: process.env.CODEX_HOME, temporaryEnvironment, cacheDirectory: process.env.XDG_CACHE_HOME, gitEnvironment: Object.fromEntries(['PATH', 'HOME', 'NODE_OPTIONS', 'NODE_DEBUG', 'NODE_EXTRA_CA_CERTS', 'CODEX_MCP_NODE_PATH', 'CODEX_SECURITY_GIT', 'GIT_SSH_COMMAND', 'GIT_CONFIG_GLOBAL', 'GIT_GLOB_PATHSPECS', 'GIT_ICASE_PATHSPECS'].map(name => [name, process.env[name]])), configPath: process.env.CODEX_SECURITY_CONFIG_PATH, deepConfigPath: process.env.CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH, python: process.env.PYTHON, mcpNodePath: process.env.CODEX_MCP_NODE_PATH, bundledTool: toolProbe?.stdout.trim(), pythonPrefix: pythonRuntime?.[0], pythonLibraryPath: pythonRuntime?.[1], runtimeEnvironment, codexConfig, providerHeaders: Object.fromEntries(['SYNTHETIC_HEADER_VALUE', 'OPENROUTER_API_KEY', 'FIREWORKS_API_KEY'].map(name => [name, process.env[name]])), providerKey: process.env.SYNTHETIC_GATEWAY_KEY, providerHeader: process.env.SYNTHETIC_HEADER_VALUE, originator: process.env.CODEX_INTERNAL_ORIGINATOR_OVERRIDE, ...(profileContents === undefined ? {} : { profileContents }), ...(openaiAuthentication ? { openaiAuthentication } : {}), ...(bedrockAuthentication ? { bedrockAuthentication } : {}) }));if (stdin.includes('COMPLETE_THEN_HANG')) process.on('SIGTERM', () => { if (!stdin.includes('IGNORE_TERMINATION')) setTimeout(() => process.exit(0), 100); });if (stdin.includes('THREAD_START_CONFIG_ERROR')) { console.error('Error: thread/start: thread/start failed: agents.max_threads cannot be set when features.multi_agent_v2 is enabled (code -32600)'); process.exit(1); }@@ -140,6 +140,8 @@ export function workerGitEnvironment(root: string) {),CODEX_SECURITY_GIT: path.join(root, "selected tools", "git"),GIT_SSH_COMMAND: "synthetic-ssh --fixture",+ GIT_GLOB_PATHSPECS: "1",+ GIT_ICASE_PATHSPECS: "1",GIT_CONFIG_GLOBAL: path.join(root, "operator.gitconfig"),};}diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_inventory.ts b/plugins/codex-security/mcp-app/tests/test_artifact_inventory.tsindex bd171620b..5e112bba5 100644--- a/plugins/codex-security/mcp-app/tests/test_artifact_inventory.ts+++ b/plugins/codex-security/mcp-app/tests/test_artifact_inventory.ts@@ -236,6 +236,25 @@ test(async function testPrepareWithIgnoredTrackedFiles() {{ items: [{ path: "-generated/b.ts" }] },);+ // Git pathspec defaults cannot override the literal scope selected by the helper.+ for (const mode of ["GIT_GLOB_PATHSPECS", "GIT_ICASE_PATHSPECS"]) {+ await execFile(+ process.execPath,+ [+ path.join(fixture.scan.pluginRoot, "mcp", "helpers.mjs"),+ "generate-in-scope-files",+ `--repo=${fixture.repoRoot}`,+ "--scope=-generated",+ `--out=${fixture.scanInventory}`,+ ],+ { env: { ...process.env, [mode]: "1" } },+ );+ assert.equal(+ await readFile(fixture.scanInventory, "utf8"),+ "-generated/a.ts\n-generated/b.ts\n",+ );+ }+const previous = await readFile(fixture.scanInventory);await fixture.writeRepositoryFile(".git/index", "invalid");await assert.rejects(diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.tsindex f7712ba2d..c6ce61d45 100644--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts@@ -1456,6 +1456,8 @@ async function testWorkerRuntimeSettings() {"CODEX_SECURITY_GIT","GIT_SSH_COMMAND","GIT_CONFIG_GLOBAL",+ "GIT_GLOB_PATHSPECS",+ "GIT_ICASE_PATHSPECS","CODEX_CLI_PATH","CODEX_BROWSER_USE_NODE_PATH","CODEX_HOME",diff --git a/plugins/codex-security/scripts/workbench_constants.py b/plugins/codex-security/scripts/workbench_constants.pyindex befd0c27c..695d48172 100644--- a/plugins/codex-security/scripts/workbench_constants.py+++ b/plugins/codex-security/scripts/workbench_constants.py@@ -58,6 +58,8 @@ GIT_REPOSITORY_ENVIRONMENT = ("GIT_COMMON_DIR","GIT_DIR","GIT_DISCOVERY_ACROSS_FILESYSTEM",+ "GIT_GLOB_PATHSPECS",+ "GIT_ICASE_PATHSPECS","GIT_INDEX_FILE","GIT_NAMESPACE","GIT_OBJECT_DIRECTORY",diff --git a/plugins/codex-security/tests/test_workbench_target.py b/plugins/codex-security/tests/test_workbench_target.pyindex 3d311fdc7..01f24a41e 100644--- a/plugins/codex-security/tests/test_workbench_target.py+++ b/plugins/codex-security/tests/test_workbench_target.py@@ -1166,13 +1166,17 @@ def test_windows_directory_query_preserves_exclusions_with_inherited_noglob(assert dict(os.environ) == environment-def test_directory_content_digest_uses_git_file_set(tmp_path: Path) -> None:[email protected]("pathspec_mode", ["GIT_GLOB_PATHSPECS", "GIT_ICASE_PATHSPECS"])+def test_directory_content_digest_uses_git_file_set(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, pathspec_mode: str+) -> None:target = tmp_path / "target"initialize_unborn_git_repository(target)(target / ".gitignore").write_text("ignored-cache/\n")source = target / "app.py"source.write_text("print('fixture')\n")original_digest = directory_content_digest(target)+ monkeypatch.setenv(pathspec_mode, "1")source.write_text("print('changed')\n")assert directory_content_digest(target) != original_digest