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(workbench): pin Git metadata on another Windows fixed drive (#2539)
Michael D'Angeloa353226b4749
diff --git a/plugins/codex-security/scripts/windows_scan_local_files.py b/plugins/codex-security/scripts/windows_scan_local_files.pyindex f7d5c3b89..aed3acf64 100644--- a/plugins/codex-security/scripts/windows_scan_local_files.py+++ b/plugins/codex-security/scripts/windows_scan_local_files.py@@ -1044,11 +1044,12 @@ def pinned_root_git_marker(not cwd.is_absolute()or not metadata.is_absolute()or len(cwd.drive) != 2- or cwd.drive != metadata.drive+ or len(metadata.drive) != 2or len(work_tree.parts) < 2or cwd.parts[: len(work_tree.parts)] != work_tree.partsor len(metadata.parts) < 2or _GetDriveTypeW(cwd.anchor) != _DRIVE_FIXED+ or _GetDriveTypeW(metadata.anchor) != _DRIVE_FIXED):yield Nonereturndiff --git a/plugins/codex-security/tests/test_workbench_target.py b/plugins/codex-security/tests/test_workbench_target.pyindex 01f24a41e..3900c0a60 100644--- a/plugins/codex-security/tests/test_workbench_target.py+++ b/plugins/codex-security/tests/test_workbench_target.py@@ -1724,7 +1724,9 @@ def test_root_git_marker_declines_unsupported_paths_without_opening_directories() -> None:import windows_scan_local_files as windows_files- monkeypatch.setattr(windows_files, "_GetDriveTypeW", lambda _anchor: 3)+ monkeypatch.setattr(+ windows_files, "_GetDriveTypeW", lambda anchor: 4 if anchor == "D:\\" else 3+ )def unexpected_open(*_args, **_kwargs):pytest.fail("unsupported paths must be declined before opening directories")@@ -1732,6 +1734,7 @@ def test_root_git_marker_declines_unsupported_paths_without_opening_directories(monkeypatch.setattr(windows_files, "_open_directory", unexpected_open)for target, metadata in ((r"C:\repo", r"D:\metadata"),+ (r"C:\repo", r"\\server.invalid\share\metadata"),(r"\\?\C:\repo", r"\\?\C:\metadata"),(r"\\server.invalid\share\repo", r"\\server.invalid\share\metadata"),(r"C:checkout", r"C:\metadata"),@@ -1745,6 +1748,52 @@ def test_root_git_marker_declines_unsupported_paths_without_opening_directories(assert selected is None[email protected]_windows[email protected](os.name != "nt", reason="requires Windows drive semantics")+def test_root_git_marker_pins_the_checkout_and_metadata_on_independent_fixed_drives(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ from unittest.mock import MagicMock++ import windows_scan_local_files as windows_files++ root, metadata = Path(r"C:\worktree"), Path(r"D:\metadata")+ scope = root / "selected"+ marker = tmp_path / "gitfile"+ marker.write_bytes(f"gitdir: {metadata.as_posix()}\n".encode())+ drives = []+ opened = []++ def fixed_drive(anchor):+ drives.append(anchor)+ return 3++ def open_fixture(path):+ opened.append(path)+ return MagicMock(value=path)++ monkeypatch.setattr(windows_files, "_GetDriveTypeW", fixed_drive)+ monkeypatch.setattr(windows_files, "_open_directory", open_fixture)++ monkeypatch.setattr(windows_files, "_final_path", windows_files._extended_path)++ def open_marker(parent, name, context):+ assert (parent, name) == (root, ".git")+ return os.open(marker, os.O_RDONLY | os.O_BINARY), name++ monkeypatch.setattr(windows_files, "open_read_fd_with_path", open_marker)+ with windows_files.pinned_root_git_marker(scope, metadata, work_tree=root) as selected:+ assert selected == Path("..", ".git")+ assert opened == [+ Path(root.anchor),+ root,+ scope,+ Path(metadata.anchor),+ metadata,+ ]+ assert set(drives) == {root.anchor, metadata.anchor}++@pytest.mark.native_windows@pytest.mark.skipif(os.name != "nt", reason="requires Windows directory junctions")@pytest.mark.parametrize("inside_scope", [False, True])