v2: Fix redirect to strip jwt_token in url-host mode (#3014)

This commit is contained in:
Samy Pessé
2025-03-21 00:46:39 +01:00
committed by GitHub
parent 9ba8783952
commit ce030fdf76
2 changed files with 13 additions and 7 deletions
+6 -4
View File
@@ -141,10 +141,12 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
// Make sure the URL is clean of any va token after a successful lookup
// The token is stored in a cookie that is set on the redirect response
//
const requestURLWithoutToken = normalizeVisitorAuthURL(
mode === 'url' ? requestURL : siteURL
);
if (requestURLWithoutToken.toString() !== requestURL.toString()) {
const incomingURL = mode === 'url' ? requestURL : siteURL;
const requestURLWithoutToken = normalizeVisitorAuthURL(incomingURL);
if (
requestURLWithoutToken !== incomingURL &&
requestURLWithoutToken.toString() !== incomingURL.toString()
) {
return writeResponseCookies(
NextResponse.redirect(requestURLWithoutToken.toString()),
cookies
+7 -3
View File
@@ -151,9 +151,13 @@ export function getVisitorAuthCookieValue(basePath: string, token: string): stri
* Normalize the URL by removing the visitor authentication token from the query parameters (if present).
*/
export function normalizeVisitorAuthURL(url: URL): URL {
const withoutVAParam = new URL(url);
withoutVAParam.searchParams.delete(VISITOR_AUTH_PARAM);
return withoutVAParam;
if (url.searchParams.has(VISITOR_AUTH_PARAM)) {
const withoutVAParam = new URL(url);
withoutVAParam.searchParams.delete(VISITOR_AUTH_PARAM);
return withoutVAParam;
}
return url;
}
/**