The vulnerability GHSA-jf8q-945g-9q4c in vm2 versions 3.11.4 through 3.11.6 stems from an incomplete filtering of Node.js internal symbols across the sandbox boundary. Specifically, the symbols nodejs.stream.disturbed and nodejs.stream.errored were not properly identified as dangerous. This allowed sandboxed code to obtain these symbols and use them to manipulate host WebStream objects, leading to state corruption (e.g., making an already-consumed stream appear undisturbed).
The analysis is based on the detailed description provided in the GitHub advisory and the release notes for vm2 v3.11.7. These sources explicitly name the affected files (lib/setup-sandbox.js and lib/bridge.js) and describe the nature of the fix: changing from a fixed-list approach to a namespace-based check for dangerous symbols.
isDangerousSymbol (lib/setup-sandbox.js): This function was responsible for filtering symbols during extraction. In the vulnerable state, it used a hardcoded list (realDangerousSymbols) that did not include the newly identified dangerous stream symbols. The fix involved modifying this function to check if Symbol.keyFor(sym) starts with nodejs., making the filtering more robust.
isDangerousCrossRealmSymbol (lib/bridge.js): This function was involved in cross-realm symbol checks. Like isDangerousSymbol, it relied on an incomplete fixed list, allowing the dangerous stream symbols to bypass checks. The fix applied a similar namespace-based check.
- Write traps (lib/bridge.js): The advisory explicitly mentions that 'write traps' in
lib/bridge.js (likely implemented via a Proxy apply trap or similar logic) were the 'last line of defense' but failed because they also relied on the same incomplete fixed list. This allowed writes using the unfiltered nodejs.stream.disturbed and nodejs.stream.errored symbols, leading to state corruption.
Despite issues retrieving commit diffs directly, the detailed textual descriptions from the official advisories provide sufficient evidence to confidently identify these functions as central to the vulnerability. The functions listed are those that existed in the vulnerable version and were modified to implement the fix, thus representing the points of failure in the security mechanism.