mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 23:01:09 +03:00
fix isValidAllowedOrigins check and invalid URL
This commit is contained in:
@@ -1328,14 +1328,18 @@ export class App {
|
|||||||
if (chatflow.chatbotConfig) {
|
if (chatflow.chatbotConfig) {
|
||||||
const parsedConfig = JSON.parse(chatflow.chatbotConfig)
|
const parsedConfig = JSON.parse(chatflow.chatbotConfig)
|
||||||
// check whether the first one is not empty. if it is empty that means the user set a value and then removed it.
|
// check whether the first one is not empty. if it is empty that means the user set a value and then removed it.
|
||||||
const isValidAllowedOrigins = parsedConfig.allowedOrigins[0] !== ''
|
const isValidAllowedOrigins = parsedConfig.allowedOrigins?.length && parsedConfig.allowedOrigins[0] !== ''
|
||||||
if (parsedConfig.allowedOrigins && parsedConfig.allowedOrigins.length > 0 && isValidAllowedOrigins) {
|
if (isValidAllowedOrigins) {
|
||||||
const originHeader = req.headers.origin as string
|
const originHeader = req.headers.origin as string
|
||||||
const origin = new URL(originHeader).host
|
const origin = new URL(originHeader).host
|
||||||
isDomainAllowed =
|
isDomainAllowed =
|
||||||
parsedConfig.allowedOrigins.filter((domain: string) => {
|
parsedConfig.allowedOrigins.filter((domain: string) => {
|
||||||
|
try {
|
||||||
const allowedOrigin = new URL(domain).host
|
const allowedOrigin = new URL(domain).host
|
||||||
return origin === allowedOrigin
|
return origin === allowedOrigin
|
||||||
|
} catch (e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}).length > 0
|
}).length > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user