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(windows): pin directories during scan artifact operations (#2427)

Michael D'Angelob833a4342311
diff --git a/plugins/codex-security/scripts/windows_scan_local_files.py b/plugins/codex-security/scripts/windows_scan_local_files.py
index cb12fed53..81a4a274c 100644
--- a/plugins/codex-security/scripts/windows_scan_local_files.py
+++ b/plugins/codex-security/scripts/windows_scan_local_files.py
@@ -469,12 +469,12 @@ def _open_directory(
missing_ok: bool = False,
missing_is_path_error: bool = True,
movable: bool = False,
- require_traverse: bool = False,
) -> _OwnedHandle | None:
try:
handle = _create_file(
path,
- access=_FILE_READ_ATTRIBUTES | (_FILE_TRAVERSE if require_traverse else 0),
+ # Attribute-only handles do not participate in Win32 sharing checks.
+ access=_FILE_READ_ATTRIBUTES | (0 if movable else _FILE_TRAVERSE),
share=_FILE_SHARE_READ | _FILE_SHARE_WRITE | (_FILE_SHARE_DELETE if movable else 0),
disposition=_OPEN_EXISTING,
flags=_FILE_FLAG_BACKUP_SEMANTICS | _FILE_FLAG_OPEN_REPARSE_POINT,
@@ -644,7 +644,7 @@ def pinned_root_git_marker(cwd: Path, metadata: Path) -> Iterator[Path | None]:
# Pin each literal ancestor before opening the next component. Never resolve
# a repository-controlled reparse point to find the directory to be pinned.
for directory in (*reversed(path.parents), path):
- handle = _open_directory(directory, require_traverse=True)
+ handle = _open_directory(directory)
assert handle is not None
pins.enter_context(handle)
assert handle.value is not None
diff --git a/plugins/codex-security/tests/test_windows_workbench_output_permissions.py b/plugins/codex-security/tests/test_windows_workbench_output_permissions.py
index 5aa0659f8..99014086f 100644
--- a/plugins/codex-security/tests/test_windows_workbench_output_permissions.py
+++ b/plugins/codex-security/tests/test_windows_workbench_output_permissions.py
@@ -63,3 +63,21 @@ def test_private_temporary_directory_rejects_post_creation_substitution(
path.rmdir()
assert list(external.iterdir()) == []
+
+
+def test_parent_remains_in_place_while_verifying_new_output(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ parent = tmp_path / "parent"
+ moved = tmp_path / "moved"
+ parent.mkdir()
+
+ def rename_parent(_path: Path, _information: int) -> None:
+ parent.rename(moved)
+ pytest.fail("Renamed the parent during verification")
+
+ monkeypatch.setattr(windows_scan_local_files, "_directory_security_descriptor", rename_parent)
+ with pytest.raises(PermissionError) as error:
+ storage.create_private_temporary_directory(parent, prefix="scan_")
+ assert error.value.winerror == 32 # ERROR_SHARING_VIOLATION
+ parent.rename(moved)