From 6a43634fb69e7de93bbba1bb617410d18bb9345e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zo=C3=AB=20Ma?= Date: Mon, 22 Jul 2024 21:10:43 +0800 Subject: [PATCH] 22003: prevent redirect loop in Wb2 client-side redirect handler MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Check that the target URL is not empty before setting window.location.href (browsing to new URL), because setting it to empty effectively reloads the page and triggers the redirect handler again, causing an endless loop. Arvados-DCO-1.1-Signed-off-by: Zoë Ma --- services/workbench2/src/common/redirect-to.ts | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/services/workbench2/src/common/redirect-to.ts b/services/workbench2/src/common/redirect-to.ts index 95dc3b2d5d..d8bf6e9446 100644 --- a/services/workbench2/src/common/redirect-to.ts +++ b/services/workbench2/src/common/redirect-to.ts @@ -55,19 +55,21 @@ export const handleRedirects = (token: string, config: Config) => { redirectKey && localStorage.removeItem(redirectKey); if (redirectKey && redirectPath) { - let redirectUrl = new URL(keepWebServiceUrl); - // encodeURI will not touch characters such as # ? that may be - // delimiter in overall URL syntax - // Setting pathname attribute will in effect encode # and ? - // while leaving others minimally disturbed (useful for debugging - // and avoids excessive percent-encoding) - redirectUrl.pathname = encodeURI(redirectPath); - redirectUrl.searchParams.set("api_token", token); + let redirectUrl = new URL(keepWebServiceUrl); + // encodeURI will not touch characters such as # ? that may be + // delimiter in overall URL syntax + // Setting pathname attribute will in effect encode # and ? + // while leaving others minimally disturbed (useful for debugging + // and avoids excessive percent-encoding) + redirectUrl.pathname = encodeURI(redirectPath); + redirectUrl.searchParams.set("api_token", token); let u = redirectUrl.href; if (redirectKey === REDIRECT_TO_PREVIEW_KEY) { u = getInlineFileUrl(u, keepWebServiceUrl, keepWebInlineServiceUrl); } - window.location.href = u; + if (u) { + window.location.href = u; + } } } }; -- 2.30.2