The vulnerability exists in the CookieJar.load method of the aiohttp library. Prior to the patch, this method used Python's pickle.load() function to deserialize cookie data from a file. The pickle module is known to be insecure for deserializing data from untrusted sources, as it can be exploited to execute arbitrary code. An attacker who can control the input file for the CookieJar.load method could craft a malicious pickle payload, leading to remote code execution on the server running the application.
The patch mitigates this vulnerability by changing the primary serialization format from pickle to JSON, which is a data-only format and not susceptible to code execution vulnerabilities. For backward compatibility with older cookie files, the load method now attempts to parse as JSON first. If that fails, it falls back to a restricted version of the pickle unpickler (_RestrictedCookieUnpickler). This custom unpickler maintains a strict whitelist of allowed classes, ensuring that only expected, safe cookie-related objects can be deserialized, thus preventing the execution of malicious payloads.
The primary vulnerable function is aiohttp.cookiejar.CookieJar.load. During exploitation, a profiler would show this function being called, which would then invoke the insecure pickle.load in the vulnerable versions.