The vulnerability is a classic case of prototype pollution in JavaScript, affecting the immutable library. The core issue lies in several API functions that create or modify plain JavaScript objects from immutable data structures or other objects. These functions did not properly sanitize or block keys named __proto__ or constructor. When a user-controlled payload (e.g., a JSON object from an HTTP request) containing a __proto__ key is processed by these functions, the library would inadvertently modify the Object.prototype. This allows an attacker to inject properties into the prototype of all objects in the application, potentially leading to security bypasses, denial of service, or remote code execution, depending on how the application's code uses objects.
The analysis of the patches shows that the fix consistently involves adding a check, isProtoKey(key), before assigning a property to a new or copied object. This check blocks keys that are either __proto__ or constructor. The affected functions identified are merge, mergeDeep, mergeDeepWith (all using the vulnerable mergeWithSources logic), Map.toJS, Map.toObject, and the set function. The utility function shallowCopy was also patched as it was a source of the pollution in other functions.