fix(package): reject rooted Windows dependency paths
CI / runtime contract (windows-latest) (push) Waiting to run
CI / fmt + clippy + test (Linux x86_64) (push) Waiting to run
CI / schema instance validation + consumers (push) Waiting to run
CI / runtime contract (macos-latest) (push) Waiting to run
Linux strict security lane (G-C) / strict isolation escape matrix (push) Waiting to run
ci/woodpecker/push/woodpecker Pipeline was successful
CI / runtime contract (windows-latest) (push) Waiting to run
CI / fmt + clippy + test (Linux x86_64) (push) Waiting to run
CI / schema instance validation + consumers (push) Waiting to run
CI / runtime contract (macos-latest) (push) Waiting to run
Linux strict security lane (G-C) / strict isolation escape matrix (push) Waiting to run
ci/woodpecker/push/woodpecker Pipeline was successful
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.
This commit is contained in:
1 parent
a24161c934
commit
5fcc111a30
1 file changed
+12
-1
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user