mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
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
This commit is contained in:
committed by
copyberry
parent
333bcaa7ff
commit
3fe546357c
@@ -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!(
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user