The vulnerability lies in Flask's session management, specifically within the SecureCookieSession class. Before the patch, this class attempted to track whether a session was accessed by overriding a few specific methods like __getitem__, get, and setdefault to set an accessed flag. This flag was then used to add a Vary: Cookie header to responses, preventing caching of user-specific pages.
The flaw was that this implementation was incomplete. It did not account for all possible ways the session could be accessed. For example, read-only operations like checking for a key's existence ('key' in session, which uses __contains__) or getting the number of items (len(session), which uses __len__) did not have corresponding overrides to set the accessed flag.
As a result, if an application accessed the session using one of these overlooked methods without otherwise modifying it, the Vary: Cookie header would not be set. A downstream caching proxy, seeing no instruction not to cache, could then store and serve a page containing user-specific data to other users.
The fix, introduced in commit 089cb86dd22bff589a4eafb7ab8e42dc357623b4, was to centralize access tracking. Instead of relying on individual method overrides in SecureCookieSession, the patch introduced a property getter for session on the RequestContext object (flask.ctx.RequestContext.session). Now, any access to the flask.session proxy triggers this getter, which unconditionally sets the accessed flag on the underlying session object. This ensures that any interaction with the session, read-only or not, correctly marks the response as varying by cookie.
The functions SecureCookieSession.__getitem__, get, and setdefault are identified because their removal in the patch is direct evidence of the old, flawed, and incomplete implementation that caused the vulnerability. They represent the piecemeal approach that was replaced by a comprehensive fix.