mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 03:32:23 +08:00
fix: validate languages (#3638)
This commit is contained in:
parent
73e9f35ab1
commit
7251748d59
|
@ -46,6 +46,12 @@ export const getLocaleOnServer = (): Locale => {
|
|||
languages = new Negotiator({ headers: negotiatorHeaders }).languages()
|
||||
}
|
||||
|
||||
// Validate languages
|
||||
if (!Array.isArray(languages) || languages.length === 0 || !languages.every(lang => typeof lang === 'string' && /^[\w-]+$/.test(lang))) {
|
||||
console.error(`Invalid languages: ${languages}`)
|
||||
languages = [i18n.defaultLocale]
|
||||
}
|
||||
|
||||
// match locale
|
||||
const matchedLocale = match(languages, locales, i18n.defaultLocale) as Locale
|
||||
return matchedLocale
|
||||
|
|
Loading…
Reference in New Issue
Block a user