Require a path boundary in external module prefix check

fix(GHSA-7q3f-wx44-378m): require a path boundary in external module prefix check
Require a path boundary in external module prefix check6ac391-fix-require-a-path-boundary-in-external-cve-2026-100721fixrequire path boundary external module prefix

Committed by patriksimek-bot

commit message
fix(GHSA-7q3f-wx44-378m): require a path boundary in external module prefix check

`LegacyResolver.isPathAllowedForModule` authorized a require originating
inside an allowlisted external module with a raw `path.startsWith(mod.path)`
test. `startsWith` is string containment, not a path boundary, so a
prefix-sharing sibling package matched: for allowlisted
`.../node_modules/foo`, the path `.../node_modules/foo2/index.js` passed and
loaded as if it were `foo`. The `node_modules` guard on the stripped
remainder did not catch it — that guard stops a genuine nested dependency,
and a sibling's remainder (`2/index.js`) has no `node_modules` segment.
Under `external: {modules: ['foo'], transitive: false}` an allowlisted
package performing a relative require therefore reached an un-allowlisted
package the embedder never authorized.
 
lib/resolver-compat.js now requires a path boundary after `mod.path` —
exact match, `mod.path` already ending in a separator, or the next character
being a separator — mirroring the idiom already used by the base
`CustomResolver.isPathAllowed`. Separator testing goes through
`this.fs.isSeparator` so the active `VMFileSystem` decides, rather than a
hardcoded character. The `node_modules` remainder test, the
`mod.allowTransitive` short-circuit and the `this.externals` fallback are
unchanged. This restores the external-package allowlist boundary
(Defense Invariant: an allowlist is an identity test, not a containment test).
 
Scoped packages carry no separate boundary semantics and were affected
identically (`@scope/pkg` vs `@scope/pkg-evil`); the fix covers them
uniformly. `transitive: true` is deliberately unaffected — `allowTransitive`
short-circuits before this check, which is what the option means, and its
behavior is identical before and after.
 
The check is lexical on both operands by design: `super.isPathAllowed`
canonicalizes into a local only to test `rootPaths`, so `path` and
`mod.path` both remain resolver-lexical. Canonicalizing one side alone would
over-block a legitimate subpath reached through a symlinked `node_modules`;
symlink escape is held separately by the `require.root` realpath gate
(GHSA-cp6g-6699-wx9c), which runs first. Orthogonal to
GHSA-c48m-32m9-vx93, which guards specifiers before the custom resolver.
 
docs/ATTACKS.md: new Category 46 (renumbered from the branch, which claimed
no category), a "How The Bridge Defends" row, and a cross-reference added to
Category 45.
Tests: test/ghsa/GHSA-7q3f-wx44-378m/repro.js — the direct
`isPathAllowedForModule` cases plus end-to-end NodeVM coverage of the
relative-require attack, the scoped variant, `transitive` both ways, and
over-block guards (14 assertions).
package.json version unchanged.

Editor assessment

This commit patches CVE-2026-100721. The body is excellent: it explains the raw startsWith check versus a real path boundary, the foo/foo2 sibling-package attack, why the node_modules guard did not catch it, and the separator-based fix that mirrors CustomResolver.isPathAllowed, plus 14 assertions. The fatal flaw is formal: a GHSA identifier is used as the scope, which is not a codebase area under CCv1, capping the score at 3. Style-wise the body is excellent and separated; the GHSA-id scope is the only formal violation, and it is the one that caps the score.

Browse categories

More fix examples · Back to search