From 5fcc111a304211dfbb3a4c85d72e0b3f4a2318be Mon Sep 17 00:00:00 2001 From: cflmy Date: Sat, 21 Nov 2026 18:55:53 +0800 Subject: [PATCH] fix(package): reject rooted Windows dependency paths A drive-less rooted path such as /tmp/x or \tmp\x is not Path::is_absolute() on Windows, but joining it still escapes the project root. Validate with has_root() so every rooted dependency path is rejected on every platform. The existing rejection test now also covers the Windows root-relative form. --- crates/marqdo-package/src/lib.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/marqdo-package/src/lib.rs b/crates/marqdo-package/src/lib.rs index 8620b98..0ce27f8 100644 --- a/crates/marqdo-package/src/lib.rs +++ b/crates/marqdo-package/src/lib.rs @@ -65,7 +65,10 @@ impl Dependency { (None, Some(_)) if !is_full_commit(self.rev.as_deref().unwrap_or("")) => Err(format!( "dependency `{name}` git rev must be a full lowercase 40- or 64-character commit hash" )), - (Some(path), None) if path.is_absolute() => Err(format!( + // `has_root`, not `is_absolute`: on Windows a drive-less rooted + // path such as `/tmp/x` or `\tmp\x` is not `is_absolute()` but + // still escapes the project when joined. Reject every rooted path. + (Some(path), None) if path.has_root() => Err(format!( "dependency `{name}` path must be project-relative" )), _ => Ok(()), @@ -1629,6 +1632,14 @@ capabilities: fn rejects_absolute_dependency_paths() { let yaml = "project:\n name: p\n version: 0.1.0\ndependencies:\n x:\n path: /tmp/x\n"; assert!(Manifest::from_yaml(yaml).is_err()); + #[cfg(windows)] + { + // Rooted but drive-less: `is_absolute()` is false on Windows, yet + // joining it escapes the project root. + let rooted = + "project:\n name: p\n version: 0.1.0\ndependencies:\n x:\n path: \\tmp\\x\n"; + assert!(Manifest::from_yaml(rooted).is_err()); + } } fn have_git() -> bool {