From fea2ffb3ba583bd1a3d734c3a676ab76c5d313d7 Mon Sep 17 00:00:00 2001 From: GuanMu Date: Fri, 17 Oct 2025 17:46:28 +0800 Subject: [PATCH] fix: improve URL validation logic in validateRedirectUrl function (#27058) --- web/utils/urlValidation.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/web/utils/urlValidation.ts b/web/utils/urlValidation.ts index 372dd54cb4..abc15a1365 100644 --- a/web/utils/urlValidation.ts +++ b/web/utils/urlValidation.ts @@ -7,18 +7,17 @@ */ export function validateRedirectUrl(url: string): void { try { - const parsedUrl = new URL(url); - if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") { - throw new Error("Authorization URL must be HTTP or HTTPS"); - } - } catch (error) { - if ( - error instanceof Error && - error.message === "Authorization URL must be HTTP or HTTPS" - ) { - throw error; - } - // If URL parsing fails, it's also invalid - throw new Error(`Invalid URL: ${url}`); + const parsedUrl = new URL(url) + if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') + throw new Error('Authorization URL must be HTTP or HTTPS') } -} \ No newline at end of file + catch (error) { + if ( + error instanceof Error + && error.message === 'Authorization URL must be HTTP or HTTPS' + ) + throw error + // If URL parsing fails, it's also invalid + throw new Error(`Invalid URL: ${url}`) + } +}