fix(h5): prevent internal asset host exposure
Some checks failed
CI / verify (push) Has been cancelled
Some checks failed
CI / verify (push) Has been cancelled
Made-with: Proma
This commit is contained in:
@@ -100,9 +100,7 @@ export const dataSourceConfig = {
|
||||
audioApiTimeoutMs: normalizeTimeout(
|
||||
import.meta.env.VITE_AUDIO_API_TIMEOUT_MS || import.meta.env.VITE_EXPLAIN_API_TIMEOUT_MS,
|
||||
defaultExplainRequestTimeoutMs
|
||||
),
|
||||
publicSameOriginAssetHost: import.meta.env.VITE_PUBLIC_SAME_ORIGIN_ASSET_HOST?.trim() || '',
|
||||
publicLegacyAudioHost: import.meta.env.VITE_PUBLIC_LEGACY_AUDIO_HOST?.trim() || ''
|
||||
)
|
||||
}
|
||||
|
||||
export const isSgsSdkMode = () => dataSourceConfig.guideDataMode === 'sdk'
|
||||
|
||||
2
src/env.d.ts
vendored
2
src/env.d.ts
vendored
@@ -25,8 +25,6 @@ interface ImportMetaEnv {
|
||||
readonly VITE_SGS_SDK_ORIGIN?: string
|
||||
readonly VITE_SGS_SDK_TIMEOUT_MS?: string
|
||||
readonly VITE_TENCENT_MAP_KEY?: string
|
||||
readonly VITE_PUBLIC_SAME_ORIGIN_ASSET_HOST?: string
|
||||
readonly VITE_PUBLIC_LEGACY_AUDIO_HOST?: string
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
@@ -4,24 +4,6 @@ import {
|
||||
|
||||
const isAbsoluteHttpUrl = (url: string) => /^https?:\/\//i.test(url)
|
||||
|
||||
const defaultSameOriginAssetHosts = [
|
||||
['1', '92', '206', '90'].join('.')
|
||||
]
|
||||
|
||||
const defaultLegacyAudioHosts = [
|
||||
['47', '120', '48', '148'].join('.')
|
||||
]
|
||||
|
||||
const configuredSameOriginAssetHosts = () => [
|
||||
dataSourceConfig.publicSameOriginAssetHost,
|
||||
...defaultSameOriginAssetHosts
|
||||
].filter(Boolean)
|
||||
|
||||
const configuredLegacyAudioHosts = () => [
|
||||
dataSourceConfig.publicLegacyAudioHost,
|
||||
...defaultLegacyAudioHosts
|
||||
].filter(Boolean)
|
||||
|
||||
const resolveSdkMinioProxyBaseUrl = () => {
|
||||
const apiBaseUrl = dataSourceConfig.apiBaseUrl.trim().replace(/\/+$/, '')
|
||||
const normalizedApiBaseUrl = apiBaseUrl.endsWith('/app-api')
|
||||
@@ -50,11 +32,8 @@ export const normalizeSameOriginPublicUrl = (url: string | null | undefined) =>
|
||||
|
||||
try {
|
||||
const parsed = new URL(value)
|
||||
const isSameServer = configuredSameOriginAssetHosts().includes(parsed.hostname)
|
||||
|
||||
if (
|
||||
isSameServer
|
||||
&& parsed.port === '9000'
|
||||
parsed.port === '9000'
|
||||
&& (
|
||||
parsed.pathname.startsWith('/museum-assets/')
|
||||
|| parsed.pathname.startsWith('/tts-audio/')
|
||||
@@ -64,16 +43,14 @@ export const normalizeSameOriginPublicUrl = (url: string | null | undefined) =>
|
||||
}
|
||||
|
||||
if (
|
||||
isSameServer
|
||||
&& parsed.port === '48080'
|
||||
parsed.port === '48080'
|
||||
&& parsed.pathname.startsWith('/yudao-server/')
|
||||
) {
|
||||
return `${parsed.pathname}${parsed.search}${parsed.hash}`
|
||||
}
|
||||
|
||||
if (
|
||||
configuredLegacyAudioHosts().includes(parsed.hostname)
|
||||
&& parsed.port === '19000'
|
||||
parsed.port === '19000'
|
||||
&& parsed.pathname.startsWith('/nhm/audio/')
|
||||
) {
|
||||
return `${parsed.pathname}${parsed.search}${parsed.hash}`
|
||||
|
||||
Reference in New Issue
Block a user