The vulnerability is a cache poisoning issue in Next.js, specifically in the App Router. The root cause is the omission of the Vary header in HTTP responses for certain requests. This could cause a cache to incorrectly serve a cached RSC (React Server Components) payload instead of the expected HTML, especially when middleware and redirects are involved.
The provided patch addresses this by modifying the Server.handleRequest function in packages/next/src/server/base-server.ts. The changes ensure that the Vary header is correctly appended to responses for App Router and RSC requests. This signals to caches that the response varies based on headers like RSC, Next-Router-State-Tree, and Next-Router-Prefetch, thus preventing the cache from serving stale or incorrect content.
The function Server.handleRequest is identified as the vulnerable function because it is where the logic for setting the Vary header resides. The patch directly modifies this function to correct the flawed logic. Therefore, any runtime profile of an exploitation attempt would show this function in the stack trace as it processes the malicious request and generates the incorrectly cached response.