CVE-2026-43998: Bypassing the require.root restriction via symbolic links in vm2

This article examines a bypass of the require.root configuration option in the vm2 library. This option is intended to prevent an instance of the NodeVM class from loading code outside the specified root directory, but before the fix, the check compared only path strings. A symbolic link inside the root directory passed the check, even though Node.js's built-in require() function subsequently dereferenced it and loaded a file from elsewhere. With context: 'host' set, such a file executed in the host realm without isolation through the bridge.
The issue was in the isPathAllowed method in lib/resolver-compat.js: the filename variable was built using path.resolve(), which operates lexically and does not follow symbolic links, and then checked with the string method startsWith. Meanwhile, require() called fs.realpathSync and resolved links before reading the file. As a result, a path such as node_modules/some-pkg/index.js could pass the check as being inside the root directory while actually pointing outside it.
The practical aspect of the attack lies in the directory layout of modern package managers. The pnpm package manager creates symbolic links for dependencies from the node_modules directory to the node_modules/.pnpm/ store, the npm link command points to a package's source directory, and npm workspaces points to the packages/ directory inside the monorepo. Thus, the condition that “an attacker can create a symbolic link inside the root directory” is already satisfied by default in many projects immediately after dependencies are installed.
Vulnerabilities
Vendors
Products