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: patch verified security findings (#961)
mluck-openaib9fa40dc8443
diff --git a/plugins/codex-security/scripts/generate_in_scope_files.py b/plugins/codex-security/scripts/generate_in_scope_files.pyindex 3dfa4a756..c2cd77208 100644--- a/plugins/codex-security/scripts/generate_in_scope_files.py+++ b/plugins/codex-security/scripts/generate_in_scope_files.py@@ -86,6 +86,7 @@ def generate_in_scope_files(repository: Path, scope: str, output: Path) -> int:command = ["rg","--files",+ "--null","--hidden","--path-separator","/",@@ -138,10 +139,19 @@ def generate_in_scope_files(repository: Path, scope: str, output: Path) -> int:for path in tracked.stdout.split(b"\0"):candidate = repository / os.fsdecode(path)if path and candidate.is_file() and not candidate.is_symlink():- inventory.write(prefix + path + b"\n")+ inventory.write(prefix + path + b"\0")inventory.seek(0)- rows = sorted(inventory)+ rows: list[bytes] = []+ for path in inventory.read().split(b"\0"):+ if not path:+ continue+ if b"\n" in path or b"\r" in path:+ raise InventoryError(+ "Repository contains a path that cannot fit in the file inventory"+ )+ rows.append(path + b"\n")+ rows.sort()return write_inventory(output, rows)diff --git a/plugins/codex-security/tests/test_generate_in_scope_files.py b/plugins/codex-security/tests/test_generate_in_scope_files.pyindex 742328d24..c27d03d5d 100644--- a/plugins/codex-security/tests/test_generate_in_scope_files.py+++ b/plugins/codex-security/tests/test_generate_in_scope_files.py@@ -148,6 +148,33 @@ def test_inventory_keeps_ignored_tracked_files_without_ignored_untracked_files(assert "./app/ignored.skip" not in paths[email protected](os.name == "nt", reason="Windows does not allow CR/LF in filenames")[email protected]("separator", ["\n", "\r", "\r\n"])[email protected]("ignored_tracked", [False, True])[email protected]("scope_kind", ["repository", "directory", "file"])+def test_inventory_rejects_line_breaks_before_serializing_paths(+ tmp_path: Path, separator: str, ignored_tracked: bool, scope_kind: str+) -> None:+ repository = make_repository(tmp_path)+ directory = "ignored" if ignored_tracked else "app"+ name = f"{directory}/concealed.py{separator}phantom.py"+ write_file(repository, name)+ if ignored_tracked:+ git(repository, "add", "--force", "--", name)+ scope = {"repository": ".", "directory": f"./{directory}", "file": name}[scope_kind]+ output = tmp_path / "in_scope_files.txt"+ previous = b"previous.py\n"+ output.write_bytes(previous)++ result = run_inventory(repository, scope, output)++ assert result.returncode == 2+ assert "path that cannot fit in the file inventory" in result.stderr+ assert result.stdout == ""+ assert output.read_bytes() == previous+ assert list(output.parent.glob(f".{output.name}.*.tmp")) == []++def test_diff_inventory_includes_power_shell_files(tmp_path: Path) -> None:repository = tmp_path / "repository"repository.mkdir()@@ -334,7 +361,7 @@ def test_large_inventory_is_not_limited_by_a_subprocess_output_buffer(tmp_path:f"#!{sys.executable}\n""import sys\n""for index in range(12000, 0, -1):\n"- " sys.stdout.write(f\"./{'x' * 100}-{index:05d}.py\\n\")\n",+ " sys.stdout.write(f\"./{'x' * 100}-{index:05d}.py\\0\")\n",encoding="utf-8",)ripgrep.chmod(0o755)