From 36588ef48b72798ff93ab929c14594e00f61727f Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 17 Sep 2026 05:17:03 +0000 Subject: [PATCH 1/4] install: refuse a registry package's escaping file: folder in the isolated linker The isolated linker opens every folder path relative to the project and hardlinks it into node_modules/.bun. It did not check whether the path leaves the project. The resolver refuses such a path when a registry package declares it, but a bun.lock can still carry the row. The hoisted installer refuses it at install time. The isolated installer linked it. Refuse the folder entry with the error of the hoisted installer when the path leaves the project and no trusted dependency in the lockfile resolves to the package (Lockfile::is_trusted_folder_package). Every dependency counts, not the one the store node carries and not only the ones this install keeps: the isolated store has one entry per package. --- src/install/isolated_install/Installer.rs | 20 ++ src/install/isolated_install/Store.rs | 2 + src/install/lockfile.rs | 18 ++ test/cli/install/bun-install.test.ts | 265 ++++++++++++++++++++++ 4 files changed, 305 insertions(+) diff --git a/src/install/isolated_install/Installer.rs b/src/install/isolated_install/Installer.rs index 1ee1715dbf53..547eaedfa33b 100644 --- a/src/install/isolated_install/Installer.rs +++ b/src/install/isolated_install/Installer.rs @@ -351,6 +351,15 @@ impl<'a> Installer<'a> { ), ); } + TaskError::UnsafeFolderPath => { + Output::err_generic( + "refusing to install dependency {} 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(), @@ -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), @@ -901,6 +912,15 @@ impl Task { ResolutionTag::Root => b".", _ => unreachable!(), }; + // `path` is opened relative to the project. The resolver refuses a + // path that leaves it unless the user wrote it, but a lockfile can + // still carry one (the hoisted installer has the same check). + if pkg_res.tag == ResolutionTag::Folder + && bin::bin_target_escapes_package_dir(path) + && !lockfile.is_trusted_folder_package(pkg_id) + { + return Ok(Yield::failure(TaskError::UnsafeFolderPath)); + } // 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) { diff --git a/src/install/isolated_install/Store.rs b/src/install/isolated_install/Store.rs index 9ae9d1c16780..91485e81e8bd 100644 --- a/src/install/isolated_install/Store.rs +++ b/src/install/isolated_install/Store.rs @@ -620,6 +620,8 @@ pub mod node { pub use super::Ids as DependencyIds; pub struct Node { + /// Only the first dependency that reached this node: `build_store` shares a + /// node between the dependents of a package, whatever declares them. pub dep_id: DependencyID, pub pkg_id: PackageID, pub parent_id: Id, diff --git a/src/install/lockfile.rs b/src/install/lockfile.rs index e44ef3156924..2eb409165687 100644 --- a/src/install/lockfile.rs +++ b/src/install/lockfile.rs @@ -905,6 +905,24 @@ impl Lockfile { .contains_name(dep.name_hash, dep.name.slice(buf), buf) } + /// May the path of folder package `id` leave the project? Yes when a trusted + /// dependency resolves to it. Every dependency in the lockfile counts, also one + /// that this install filters out (`--production`, `--filter`): the user wrote + /// the path either way. For the isolated linker, which links a folder package + /// once for all of its dependents. + 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( + DependencyID::try_from(dep_id).expect("int cast"), + ) + }) + } + /// 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 { diff --git a/test/cli/install/bun-install.test.ts b/test/cli/install/bun-install.test.ts index cf57430b5f2d..c7ebe434a5c6 100644 --- a/test/cli/install/bun-install.test.ts +++ b/test/cli/install/bun-install.test.ts @@ -10523,6 +10523,271 @@ it("installs transitive file: dependencies of a local file: package that point o ).toBe(true); }); +describe.concurrent("isolated linker: file: dependencies that point outside the project", () => { + // The isolated linker opens every folder path relative to the project, so the + // project is one level below the temp directory and "../" is a sibling + // that the test owns. + const bunfig = (ctx: TestContext) => + Bun.TOML.stringify({ install: { cache: false, registry: ctx.registry_url, linker: "isolated" } }); + + async function install(projectDir: string, ...flags: string[]) { + await using proc = spawn({ + cmd: [bunExe(), "install", ...flags], + cwd: projectDir, + stdout: "pipe", + stdin: "ignore", + stderr: "pipe", + env, + }); + const [err, out, exitCode] = await Promise.all([proc.stderr.text(), proc.stdout.text(), proc.exited]); + return { err, out, exitCode }; + } + + // The first install resolves (enqueue path), the second one starts from the + // saved lockfile with an empty node_modules (installer path). + async function installTwice(projectDir: string) { + for (let i = 0; i < 2; i++) { + if (i === 1) { + await rm(join(projectDir, "node_modules"), { recursive: true, force: true }); + } + const { err, exitCode } = await install(projectDir); + expect(err).not.toContain("error:"); + expect(exitCode).toBe(0); + } + } + + // The resolver does not record these dependencies, but a lockfile from an + // older bun (or a migrated or edited one) can carry the rows. Registry content + // is not written by the user, so the installer must refuse the path that + // leaves the project, the way the hoisted linker does. + const refusedRows: Record object> = { + "a registry package declares with a relative path": tarball => ({ + "baz": ["baz@0.0.3", tarball, { dependencies: { loot: "file:../secret" } }, ""], + "baz/loot": ["loot@file:../secret", {}], + }), + "a registry package declares with an absolute path": (tarball, secretDir) => ({ + "baz": ["baz@0.0.3", tarball, { dependencies: { loot: "file:" + secretDir } }, ""], + "baz/loot": ["loot@file:" + secretDir, {}], + }), + // Trust for a folder parent is anchored at the root or a workspace. + "the folder of a registry package declares": tarball => ({ + "baz": ["baz@0.0.3", tarball, { dependencies: { inner: "file:vendor/inner" } }, ""], + "baz/inner": ["inner@file:vendor/inner", { dependencies: { loot: "file:../secret" } }], + "baz/inner/loot": ["loot@file:../secret", {}], + }), + }; + + for (const [title, packages] of Object.entries(refusedRows)) { + it(`refuses one that ${title} in the lockfile`, async () => { + await withContext(undefined, async ctx => { + const urls: string[] = []; + setContextHandler(ctx, dummyRegistryForContext(ctx, urls, { "0.0.3": {} })); + using dir = tempDir("isolated-registry-file-dep-lockfile", { + "secret/package.json": JSON.stringify({ name: "loot", version: "1.0.0" }), + "secret/credentials.txt": "do-not-link-me", + "project/bunfig.toml": bunfig(ctx), + "project/package.json": JSON.stringify({ + name: "my-app", + version: "1.0.0", + dependencies: { baz: "0.0.3" }, + }), + "project/vendor/inner/package.json": JSON.stringify({ name: "inner", version: "1.0.0" }), + }); + const projectDir = join(String(dir), "project"); + await write( + join(projectDir, "bun.lock"), + JSON.stringify({ + lockfileVersion: 1, + workspaces: { "": { name: "my-app", dependencies: { baz: "0.0.3" } } }, + packages: packages(`${ctx.registry_url}baz-0.0.3.tgz`, join(String(dir), "secret").replaceAll("\\", "/")), + }), + ); + + const { err, exitCode } = await install(projectDir); + + expect(err).toContain("refusing to install dependency loot with unsafe folder path"); + // Nothing in the store is made from the outside directory. + const store = await readdirSorted(join(projectDir, "node_modules", ".bun")); + expect(store.filter(name => name.startsWith("loot@"))).toEqual([]); + expect(exitCode).toBe(1); + }); + }); + } + + it("links one that the root declares when a registry package peer-depends on it", async () => { + // `baz` is visited before `shared`, so the first dependency that reaches the + // folder package is the peer dependency of a registry package. The folder is + // still the one the root package.json names. + await withContext(undefined, async ctx => { + const urls: string[] = []; + setContextHandler( + ctx, + dummyRegistryForContext(ctx, urls, { + "0.0.3": { + peerDependencies: { shared: "*" }, + peerDependenciesMeta: { shared: { optional: true } }, + }, + }), + ); + using dir = tempDir("isolated-root-file-dep-peer", { + "shared/package.json": JSON.stringify({ name: "shared", version: "1.0.0" }), + "shared/index.js": "module.exports = 'shared';", + "project/bunfig.toml": bunfig(ctx), + "project/package.json": JSON.stringify({ + name: "my-app", + version: "1.0.0", + dependencies: { baz: "0.0.3", shared: "file:../shared" }, + }), + }); + const projectDir = join(String(dir), "project"); + + await installTwice(projectDir); + + const store = join(projectDir, "node_modules", ".bun"); + const bazEntry = (await readdirSorted(store)).find(name => name.startsWith("baz@"))!; + expect( + await Promise.all([ + file(join(projectDir, "node_modules", "shared", "index.js")).text(), + file(join(store, bazEntry, "node_modules", "shared", "index.js")).text(), + ]), + ).toEqual(["module.exports = 'shared';", "module.exports = 'shared';"]); + }); + }); + + // These flags leave the root's own dependency on the folder out of the + // install. The peer dependency of the registry package still reaches it, and + // the path is still the one the root package.json names. + for (const flags of [["--production"], ["--omit", "dev"], ["--frozen-lockfile", "--production"], ["--filter", "b"]]) { + it(`links one that the root declares when ${flags.join(" ")} leaves only a registry package's peer dependency on it`, async () => { + await withContext(undefined, async ctx => { + const urls: string[] = []; + setContextHandler( + ctx, + dummyRegistryForContext(ctx, urls, { + "0.0.3": { + peerDependencies: { shared: "*" }, + peerDependenciesMeta: { shared: { optional: true } }, + }, + }), + ); + using dir = tempDir("isolated-root-file-dep-flags", { + "shared/package.json": JSON.stringify({ name: "shared", version: "1.0.0" }), + "shared/index.js": "module.exports = 'shared';", + "project/bunfig.toml": bunfig(ctx), + ...(flags[0] === "--filter" + ? { + "project/package.json": JSON.stringify({ + name: "my-app", + version: "1.0.0", + workspaces: ["packages/*"], + dependencies: { shared: "file:../shared" }, + }), + "project/packages/b/package.json": JSON.stringify({ + name: "b", + version: "1.0.0", + dependencies: { baz: "0.0.3" }, + }), + } + : { + "project/package.json": JSON.stringify({ + name: "my-app", + version: "1.0.0", + dependencies: { baz: "0.0.3" }, + devDependencies: { shared: "file:../shared" }, + }), + }), + }); + const projectDir = join(String(dir), "project"); + + // A full install writes the lockfile. + const full = await install(projectDir); + expect(full.err).not.toContain("error:"); + expect(full.exitCode).toBe(0); + await Promise.all([ + rm(join(projectDir, "node_modules"), { recursive: true, force: true }), + rm(join(projectDir, "packages", "b", "node_modules"), { recursive: true, force: true }), + ]); + + const { err, exitCode } = await install(projectDir, ...flags); + + expect(err).not.toContain("error:"); + const store = join(projectDir, "node_modules", ".bun"); + const bazEntry = (await readdirSorted(store)).find(name => name.startsWith("baz@"))!; + expect(await file(join(store, bazEntry, "node_modules", "shared", "index.js")).text()).toBe( + "module.exports = 'shared';", + ); + expect(exitCode).toBe(0); + }); + }); + } + + it("links the ones that a local file: package declares", async () => { + using dir = tempDir("isolated-local-file-dep-outside", { + "packages/plugin/package.json": JSON.stringify({ + name: "plugin", + version: "1.0.0", + dependencies: { "shared-lib": "../shared-lib" }, + devDependencies: { "shared-dev-lib": "file:../shared-dev-lib" }, + }), + "packages/plugin/index.js": `module.exports = [require("shared-lib/package.json").name, require("shared-dev-lib/package.json").name];`, + "packages/shared-lib/package.json": JSON.stringify({ name: "shared-lib", version: "1.0.0" }), + "packages/shared-dev-lib/package.json": JSON.stringify({ name: "shared-dev-lib", version: "1.0.0" }), + "project/bunfig.toml": Bun.TOML.stringify({ install: { cache: false, linker: "isolated" } }), + "project/package.json": JSON.stringify({ + name: "my-app", + version: "1.0.0", + dependencies: { plugin: "file:../packages/plugin" }, + }), + }); + const projectDir = join(String(dir), "project"); + + await installTwice(projectDir); + + await using run = spawn({ + cmd: [bunExe(), "-e", `console.log(JSON.stringify(require("plugin")))`], + cwd: projectDir, + stdout: "pipe", + stderr: "pipe", + env, + }); + const [runErr, runOut, runExit] = await Promise.all([run.stderr.text(), run.stdout.text(), run.exited]); + expect(runErr).toBe(""); + expect(runOut.trim()).toBe(`["shared-lib","shared-dev-lib"]`); + expect(runExit).toBe(0); + }); + + for (const field of ["resolutions", "overrides"]) { + it(`links one that root "${field}" applies to a registry package's dependency`, async () => { + await withContext(undefined, async ctx => { + const urls: string[] = []; + setContextHandler(ctx, dummyRegistryForContext(ctx, urls, { "0.0.3": { dependencies: { shared: "1.0.0" } } })); + using dir = tempDir(`isolated-${field}-registry-file-dep`, { + "shared/package.json": JSON.stringify({ name: "shared", version: "1.0.0" }), + "shared/index.js": "module.exports = 'shared';", + "project/bunfig.toml": bunfig(ctx), + "project/package.json": JSON.stringify({ + name: "my-app", + version: "1.0.0", + dependencies: { baz: "0.0.3" }, + [field]: { shared: "file:../shared" }, + }), + }); + const projectDir = join(String(dir), "project"); + + await installTwice(projectDir); + + // No registry request was made for `shared`, and `baz` gets the folder. + expect(urls.filter(url => url.includes("shared"))).toEqual([]); + expect( + await file( + join(projectDir, "node_modules", ".bun", "baz@0.0.3", "node_modules", "shared", "index.js"), + ).text(), + ).toBe("module.exports = 'shared';"); + }); + }); + } +}); + it("does not install transitive file: dependencies with overlong folder targets", async () => { const overlongTarget = "file:./" + Buffer.alloc(120000, "a").toString(); using dir = tempDir("transitive-file-dep-overlong", { From 52d6877a431c3e3528cb8382e2195e41207b99d3 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 17 Sep 2026 15:11:29 +0000 Subject: [PATCH 2/4] test: pin a nested override for a local file: package under the isolated linker The only dependency that resolves to the folder has an npm range. A nested overrides or resolutions rule supplies the path, and the trust checks consult only plain rules. The trust comes from the package that declares the dependency. A check on the version of the dependency refuses this install. --- test/cli/install/bun-install.test.ts | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/cli/install/bun-install.test.ts b/test/cli/install/bun-install.test.ts index c7ebe434a5c6..07ca23bd2f75 100644 --- a/test/cli/install/bun-install.test.ts +++ b/test/cli/install/bun-install.test.ts @@ -10785,6 +10785,45 @@ describe.concurrent("isolated linker: file: dependencies that point outside the ).toBe("module.exports = 'shared';"); }); }); + + it(`links one that a nested root "${field}" rule gives to a local file: package's dependency`, async () => { + // The only dependency that resolves to the folder is `"shared": "1.0.0"` of + // `pkg-a`. The trust checks consult only plain rules, so the trust comes + // from the package that declares the dependency, not from its version. + using dir = tempDir(`isolated-nested-${field}-local-file-dep`, { + "shared/package.json": JSON.stringify({ name: "shared", version: "1.0.0" }), + "shared/index.js": "module.exports = 'shared';", + "project/bunfig.toml": Bun.TOML.stringify({ install: { cache: false, linker: "isolated" } }), + "project/package.json": JSON.stringify({ + name: "my-app", + version: "1.0.0", + dependencies: { "pkg-a": "file:./pkg-a" }, + [field]: + field === "overrides" ? { "pkg-a": { shared: "file:../shared" } } : { "pkg-a/shared": "file:../shared" }, + }), + "project/pkg-a/package.json": JSON.stringify({ + name: "pkg-a", + version: "1.0.0", + dependencies: { shared: "1.0.0" }, + }), + "project/pkg-a/index.js": "module.exports = require('shared');", + }); + const projectDir = join(String(dir), "project"); + + await installTwice(projectDir); + + await using run = spawn({ + cmd: [bunExe(), "-e", `console.log(require("pkg-a"))`], + cwd: projectDir, + stdout: "pipe", + stderr: "pipe", + env, + }); + const [runErr, runOut, runExit] = await Promise.all([run.stderr.text(), run.stdout.text(), run.exited]); + expect(runErr).toBe(""); + expect(runOut).toBe("shared\n"); + expect(runExit).toBe(0); + }); } }); From ed0c89df1a4cf1875fdb797a566d3ff3f4f8435e Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 17 Sep 2026 15:14:11 +0000 Subject: [PATCH 3/4] install: shorten the comments of the isolated folder path check --- src/install/isolated_install/Installer.rs | 4 +--- src/install/isolated_install/Store.rs | 3 +-- src/install/lockfile.rs | 6 +----- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/install/isolated_install/Installer.rs b/src/install/isolated_install/Installer.rs index 547eaedfa33b..97d099d48894 100644 --- a/src/install/isolated_install/Installer.rs +++ b/src/install/isolated_install/Installer.rs @@ -912,9 +912,7 @@ impl Task { ResolutionTag::Root => b".", _ => unreachable!(), }; - // `path` is opened relative to the project. The resolver refuses a - // path that leaves it unless the user wrote it, but a lockfile can - // still carry one (the hoisted installer has the same check). + // A lockfile can carry a path that the resolver refuses. if pkg_res.tag == ResolutionTag::Folder && bin::bin_target_escapes_package_dir(path) && !lockfile.is_trusted_folder_package(pkg_id) diff --git a/src/install/isolated_install/Store.rs b/src/install/isolated_install/Store.rs index 91485e81e8bd..afe96ee495de 100644 --- a/src/install/isolated_install/Store.rs +++ b/src/install/isolated_install/Store.rs @@ -620,8 +620,7 @@ pub mod node { pub use super::Ids as DependencyIds; pub struct Node { - /// Only the first dependency that reached this node: `build_store` shares a - /// node between the dependents of a package, whatever declares them. + /// Only the first dependency that reached this node, which its dependents share. pub dep_id: DependencyID, pub pkg_id: PackageID, pub parent_id: Id, diff --git a/src/install/lockfile.rs b/src/install/lockfile.rs index 2eb409165687..e9f52bf0eef3 100644 --- a/src/install/lockfile.rs +++ b/src/install/lockfile.rs @@ -905,11 +905,7 @@ impl Lockfile { .contains_name(dep.name_hash, dep.name.slice(buf), buf) } - /// May the path of folder package `id` leave the project? Yes when a trusted - /// dependency resolves to it. Every dependency in the lockfile counts, also one - /// that this install filters out (`--production`, `--filter`): the user wrote - /// the path either way. For the isolated linker, which links a folder package - /// once for all of its dependents. + /// 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 From 1b6cc5d570cef334140bfb940041cb9db5d07210 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 17 Sep 2026 15:45:11 +0000 Subject: [PATCH 4/4] install: treat a NUL in a file: path as leaving the package bin_target_escapes_package_dir splits the path on separators, so "..\0x" is one ordinary component for it. The OS ends the path at the NUL and opens "..". The resolver, the hoisted installer and the new isolated check all accepted such a path from a registry manifest or a lockfile row. A release build then linked the parent directory. A debug build panicked in ZStr::as_cstr. --- src/install/bin.rs | 4 ++ test/cli/install/bun-install.test.ts | 76 ++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/install/bin.rs b/src/install/bin.rs index d28f5941115b..9dc7c33729c8 100644 --- a/src/install/bin.rs +++ b/src/install/bin.rs @@ -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 diff --git a/test/cli/install/bun-install.test.ts b/test/cli/install/bun-install.test.ts index 07ca23bd2f75..adbdadd08c7e 100644 --- a/test/cli/install/bun-install.test.ts +++ b/test/cli/install/bun-install.test.ts @@ -10451,6 +10451,77 @@ it("refuses to install an escaping file: dependency that a registry package's ow }); }); +describe.concurrent('a registry package\'s file: dependency that hides ".." behind a NUL', () => { + // The OS ends a path at a NUL. For a check that only splits on separators, + // "..\0not-a-parent" is one ordinary component, but the directory that gets + // opened is "..". + const target = "..\u0000not-a-parent"; + + it("is refused by the resolver", async () => { + await withContext(defaultOpts, async ctx => { + const urls: string[] = []; + setContextHandler( + ctx, + dummyRegistryForContext(ctx, urls, { "0.0.3": { dependencies: { loot: "file:" + target } } }), + ); + await writeFile( + join(ctx.package_dir, "package.json"), + JSON.stringify({ name: "my-app", version: "1.0.0", dependencies: { baz: "0.0.3" } }), + ); + + await using proc = spawn({ + cmd: [bunExe(), "install"], + cwd: ctx.package_dir, + stdout: "pipe", + stdin: "ignore", + stderr: "pipe", + env, + }); + const [err, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]); + + expect(err).toContain("Could not find package.json"); + expect(await exists(join(ctx.package_dir, "node_modules", "baz", "node_modules", "loot"))).toBe(false); + expect(exitCode).toBe(1); + }); + }); + + it("is refused by the hoisted installer when the lockfile carries it", async () => { + await withContext(defaultOpts, async ctx => { + const urls: string[] = []; + setContextHandler(ctx, dummyRegistryForContext(ctx, urls, { "0.0.3": {} })); + await writeFile( + join(ctx.package_dir, "package.json"), + JSON.stringify({ name: "my-app", version: "1.0.0", dependencies: { baz: "0.0.3" } }), + ); + await writeFile( + join(ctx.package_dir, "bun.lock"), + JSON.stringify({ + lockfileVersion: 1, + workspaces: { "": { name: "my-app", dependencies: { baz: "0.0.3" } } }, + packages: { + "baz": ["baz@0.0.3", `${ctx.registry_url}baz-0.0.3.tgz`, { dependencies: { loot: "file:" + target } }, ""], + "baz/loot": ["loot@file:" + target, {}], + }, + }), + ); + + await using proc = spawn({ + cmd: [bunExe(), "install"], + cwd: ctx.package_dir, + stdout: "pipe", + stdin: "ignore", + stderr: "pipe", + env, + }); + const [err, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]); + + expect(err).toContain("refusing to install dependency loot with unsafe folder path"); + expect(await exists(join(ctx.package_dir, "node_modules", "baz", "node_modules", "loot"))).toBe(false); + expect(exitCode).toBe(1); + }); + }); +}); + it("installs transitive file: dependencies of a local file: package that point outside the project", async () => { // A file: package referenced by the root package.json lives outside the // project and declares its own relative folder dependencies that also land @@ -10569,6 +10640,11 @@ describe.concurrent("isolated linker: file: dependencies that point outside the "baz": ["baz@0.0.3", tarball, { dependencies: { loot: "file:" + secretDir } }, ""], "baz/loot": ["loot@file:" + secretDir, {}], }), + // The OS ends a path at a NUL, so this row opens "..". + 'a registry package declares with ".." hidden behind a NUL': tarball => ({ + "baz": ["baz@0.0.3", tarball, { dependencies: { loot: "file:..\u0000not-a-parent" } }, ""], + "baz/loot": ["loot@file:..\u0000not-a-parent", {}], + }), // Trust for a folder parent is anchored at the root or a workspace. "the folder of a registry package declares": tarball => ({ "baz": ["baz@0.0.3", tarball, { dependencies: { inner: "file:vendor/inner" } }, ""],