The vulnerability exists in the vm2 library's NodeVM component, specifically in how it handles the wildcard '*' option for built-in modules. The root cause is an incomplete filter applied during the initialization of the BUILTIN_MODULES constant in lib/builtin.js. This constant was populated with modules from require('module').builtinModules but failed to exclude undocumented, underscored modules (e.g., _http_client, _http_server) which provide direct access to network primitives.
The function makeBuiltinsFromLegacyOptions in lib/builtin.js uses this flawed BUILTIN_MODULES list to expand the '*' wildcard when processing the require.builtin configuration. Consequently, if a user configured NodeVM with builtin: ['*', '-http', '-net'] to restrict network access, the wildcard expansion would still grant access to the underscored network-capable modules. This allowed sandboxed code to bypass the intended security policy and perform network operations, leading to a Server-Side Request Forgery (SSRF) vulnerability.
The patch rectifies this by adding !s.startsWith('_') to the filter for BUILTIN_MODULES, ensuring that these internal modules are not included in wildcard expansions. The function makeBuiltinsFromLegacyOptions is identified as the key vulnerable function because it is responsible for processing the configuration that enables the vulnerability.