From 3fe546357c63846e9fdbc8a81e206fa0aca42d24 Mon Sep 17 00:00:00 2001 From: caseysilver-oai Date: Tue, 1 Dec 2026 02:23:01 +0000 Subject: [PATCH] Reject colon-containing plugin archive paths on Windows (#64893) ## Why A nested drive prefix in a tar entry can redirect extraction outside the plugin bundle staging directory on Windows. ## What changed Reject tar entries with a colon in any path component on Windows. ## Testing Add a Windows-only regression test for nested drive prefixes with both forward slashes and backslashes. GitOrigin-RevId: b19b3d0de16ffe73726981f823a8f4db6629ad22 --- codex-rs/core-plugins/src/plugin_bundle_archive.rs | 8 ++++++-- .../core-plugins/src/plugin_bundle_archive_tests.rs | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/codex-rs/core-plugins/src/plugin_bundle_archive.rs b/codex-rs/core-plugins/src/plugin_bundle_archive.rs index 0063510d7d..2b052a47ab 100644 --- a/codex-rs/core-plugins/src/plugin_bundle_archive.rs +++ b/codex-rs/core-plugins/src/plugin_bundle_archive.rs @@ -213,12 +213,16 @@ fn checked_tar_output_path( let mut has_component = false; for component in entry_name.components() { match component { - std::path::Component::Normal(component) => { + // On Windows, push reparses a nested drive prefix and replaces the destination. + std::path::Component::Normal(component) + if !cfg!(windows) || !component.as_encoded_bytes().contains(&b':') => + { has_component = true; output_path.push(component); } std::path::Component::CurDir => {} - std::path::Component::ParentDir + std::path::Component::Normal(_) + | std::path::Component::ParentDir | std::path::Component::RootDir | std::path::Component::Prefix(_) => { return Err(PluginBundleUnpackError::InvalidBundle(format!( diff --git a/codex-rs/core-plugins/src/plugin_bundle_archive_tests.rs b/codex-rs/core-plugins/src/plugin_bundle_archive_tests.rs index aa77c4661b..6bb8fd4ceb 100644 --- a/codex-rs/core-plugins/src/plugin_bundle_archive_tests.rs +++ b/codex-rs/core-plugins/src/plugin_bundle_archive_tests.rs @@ -1,6 +1,17 @@ use super::*; use tempfile::tempdir; +#[cfg(windows)] +#[test] +fn rejects_nested_drive_prefixes() { + for path in ["package/C:../file", r"package\d:\file"] { + assert!(matches!( + checked_tar_output_path(Path::new(r"C:\staging"), Path::new(path)), + Err(PluginBundleUnpackError::InvalidBundle(_)) + )); + } +} + #[test] fn portable_root_manifest_can_be_packed_and_unpacked() { let source = tempdir().expect("source tempdir");