Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/install/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,10 @@ pub(crate) fn bin_target_escapes_package_dir(target: &[u8]) -> bool {
if path::is_absolute(target) {
return true;
}
// The OS ends a path at a NUL, so `..\0x` is one component below but opens `..`.
if strings::contains_char(target, 0) {
return true;
}
// Windows drive-relative paths (`C:foo`, `C:..\evil`) are not "absolute"
// (no separator after the colon) and their `C:..` component is not a bare
// `..`, so they would slip past the depth walk below while still resolving
Expand Down
18 changes: 18 additions & 0 deletions src/install/isolated_install/Installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ impl<'a> Installer<'a> {
),
);
}
TaskError::UnsafeFolderPath => {
Output::err_generic(
"refusing to install dependency <b>{}<r> with unsafe folder path \"{}\"",
(
bstr::BStr::new(pkg_name.slice(string_buf)),
bstr::BStr::new(pkg_res.folder().slice(string_buf)),
),
);
}
TaskError::SymlinkDependencies(symlink_err) => {
Output::err(
symlink_err.clone(),
Expand Down Expand Up @@ -692,6 +701,8 @@ pub struct DownloadError {

pub enum TaskError {
LinkPackage(sys::Error),
/// Only a `ResolutionTag::Folder` entry fails with this.
UnsafeFolderPath,
SymlinkDependencies(sys::Error),
RunScripts(crate::Error),
Binaries(crate::Error),
Expand Down Expand Up @@ -901,6 +912,13 @@ impl Task {
ResolutionTag::Root => b".",
_ => unreachable!(),
};
// A lockfile can carry a path that the resolver refuses.
if pkg_res.tag == ResolutionTag::Folder
&& bin::bin_target_escapes_package_dir(path)
Comment thread
robobun marked this conversation as resolved.
Resolved
&& !lockfile.is_trusted_folder_package(pkg_id)
{
return Ok(Yield::failure(TaskError::UnsafeFolderPath));
Comment thread
robobun marked this conversation as resolved.
Resolved
}
// the folder does not exist in the cache. xdev is per folder dependency
let folder_dir = match bun_sys::open_dir_for_iteration(Fd::cwd(), path)
{
Expand Down
1 change: 1 addition & 0 deletions src/install/isolated_install/Store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ pub mod node {
pub use super::Ids as DependencyIds;

pub struct Node {
/// Only the first dependency that reached this node, which its dependents share.
pub dep_id: DependencyID,
pub pkg_id: PackageID,
pub parent_id: Id,
Expand Down
14 changes: 14 additions & 0 deletions src/install/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,20 @@ impl Lockfile {
.contains_name(dep.name_hash, dep.name.slice(buf), buf)
}

/// Does a trusted dependency, installed or filtered out, resolve to folder package `id`?
pub(crate) fn is_trusted_folder_package(&self, id: PackageID) -> bool {
self.buffers
.resolutions
.iter()
.enumerate()
.any(|(dep_id, &pkg_id)| {
pkg_id == id
&& self.is_trusted_folder_dependency(
Comment thread
robobun marked this conversation as resolved.
Resolved
DependencyID::try_from(dep_id).expect("int cast"),
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
})
Comment thread
robobun marked this conversation as resolved.
Resolved
}

/// Does this tree id belong to a workspace (including workspace root)?
/// TODO(dylan-conway) fix!
pub(crate) fn is_workspace_tree_id(&self, id: tree::Id) -> bool {
Expand Down
Loading
Loading