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:
caseysilver-oai
2026-12-01 02:56:43 +00:00
committed by copyberry
parent 333bcaa7ff
commit 3fe546357c
2 changed files with 17 additions and 2 deletions
@@ -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");