mirror of
https://github.com/langgenius/dify.git
synced 2026-01-14 06:07:33 +08:00
Merge commit from fork
This commit is contained in:
parent
4f7cb7cd2a
commit
bfda4ce7e6
@ -1,5 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
import { validateRedirectUrl } from '@/utils/urlValidation'
|
||||||
|
|
||||||
export const useOAuthCallback = () => {
|
export const useOAuthCallback = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -18,6 +19,7 @@ export const openOAuthPopup = (url: string, callback: () => void) => {
|
|||||||
const left = window.screenX + (window.outerWidth - width) / 2
|
const left = window.screenX + (window.outerWidth - width) / 2
|
||||||
const top = window.screenY + (window.outerHeight - height) / 2
|
const top = window.screenY + (window.outerHeight - height) / 2
|
||||||
|
|
||||||
|
validateRedirectUrl(url)
|
||||||
const popup = window.open(
|
const popup = window.open(
|
||||||
url,
|
url,
|
||||||
'OAuth',
|
'OAuth',
|
||||||
|
|||||||
24
web/utils/urlValidation.ts
Normal file
24
web/utils/urlValidation.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Validates that a URL is safe for redirection.
|
||||||
|
* Only allows HTTP and HTTPS protocols to prevent XSS attacks.
|
||||||
|
*
|
||||||
|
* @param url - The URL string to validate
|
||||||
|
* @throws Error if the URL has an unsafe protocol
|
||||||
|
*/
|
||||||
|
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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user