fix: improve URL validation logic in validateRedirectUrl function (#27058)
This commit is contained in:
@@ -7,18 +7,17 @@
|
|||||||
*/
|
*/
|
||||||
export function validateRedirectUrl(url: string): void {
|
export function validateRedirectUrl(url: string): void {
|
||||||
try {
|
try {
|
||||||
const parsedUrl = new URL(url);
|
const parsedUrl = new URL(url)
|
||||||
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:')
|
||||||
throw new Error("Authorization URL must be HTTP or 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}`);
|
|
||||||
}
|
}
|
||||||
}
|
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}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user