The vulnerability lies in the apply trap of the bridge, which allows sandbox code to invoke host functions with a host object as this. This can be exploited to mutate the prototype of a host object, leading to a sandbox escape. The patch addresses this by adding a two-layer fix in lib/bridge.js.
The first layer is a write-side fix that refuses to apply host prototype mutators. It does this by caching the identity of every host-realm function that mutates [[Prototype]] and refusing any apply-trap invocation that reaches one.
The second layer is a read-side, defense-in-depth fix that cache-checks mappingOtherToThis before the proto-walk in thisEnsureThis. This ensures that any previously-bridged host value returns the existing proxy even with a tampered proto chain.
Based on the patch, the following functions are identified as vulnerable:
createBridge in lib/bridge.js: This function is the main entry point for creating the bridge between the sandbox and the host. The patch adds a significant amount of code to this function to address the vulnerability.
thisEnsureThis in lib/bridge.js: This function is responsible for ensuring that a value is a this value. The patch adds a cache check to this function to prevent the vulnerability from being exploited.
The following functions are also relevant to the vulnerability, as they are used in the exploit:
Buffer.call.call({}.__lookupGetter__, Buffer, "__proto__")
Buffer.call.call({}.__lookupSetter__, Buffer, "__proto__")
WebAssembly.compileStreaming()
However, these functions are not directly patched. The vulnerability is in the vm2 library, not in these built-in Node.js functions.
Therefore, the vulnerable functions are createBridge and thisEnsureThis in lib/bridge.js.