The vulnerability lies in the improper handling of the returnTo query parameter within the Auth0 Next.js SDK. The analysis of the patch commit 35eb321de3345ccf23e8c0d6f66c9f2f2f57d26c clearly shows the fix. The file src/server/helpers/with-page-auth-required.ts was modified to address the issue. Specifically, within the appRouteHandlerFactory function, the returnTo parameter is now wrapped with encodeURIComponent before being appended to the login redirect URL. The vulnerable code did not encode this parameter, allowing an attacker to inject malicious OAuth parameters into the authorization flow. The test file src/server/helpers/with-page-auth-required.test.ts was also updated with new test cases that explicitly check for this URL encoding, confirming the nature of the vulnerability and the fix. Therefore, the appRouteHandlerFactory is identified as the vulnerable function, as it contains the logic that constructs the improperly formed redirect URL.