mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
merge conflict
This commit is contained in:
@ -18,14 +18,26 @@ export type IGAProps = {
|
|||||||
gaType: GaType
|
gaType: GaType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const extractNonceFromCSP = (cspHeader: string | null): string | undefined => {
|
||||||
|
if (!cspHeader)
|
||||||
|
return undefined
|
||||||
|
const nonceMatch = cspHeader.match(/'nonce-([^']+)'/)
|
||||||
|
return nonceMatch ? nonceMatch[1] : undefined
|
||||||
|
}
|
||||||
|
|
||||||
const GA: FC<IGAProps> = ({
|
const GA: FC<IGAProps> = ({
|
||||||
gaType,
|
gaType,
|
||||||
}) => {
|
}) => {
|
||||||
if (IS_CE_EDITION)
|
if (IS_CE_EDITION)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
const nonceValue = process.env.NODE_ENV === 'production' ? (headers() as unknown as UnsafeUnwrappedHeaders).get('x-nonce') : null
|
const cspHeader = process.env.NODE_ENV === 'production'
|
||||||
const nonce = nonceValue || undefined
|
? (headers() as unknown as UnsafeUnwrappedHeaders).get('content-security-policy')
|
||||||
|
: null
|
||||||
|
const nonce = extractNonceFromCSP(cspHeader)
|
||||||
|
|
||||||
|
if (typeof window === 'undefined')
|
||||||
|
console.log('[GA SSR] CSP header:', cspHeader ? 'exists' : 'MISSING', '| nonce:', nonce ? `extracted (${nonce.substring(0, 10)}...)` : 'NOT FOUND')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@ -33,7 +33,7 @@ export function middleware(request: NextRequest) {
|
|||||||
const cspHeader = `
|
const cspHeader = `
|
||||||
default-src 'self' ${scheme_source} ${csp} ${whiteList};
|
default-src 'self' ${scheme_source} ${csp} ${whiteList};
|
||||||
connect-src 'self' ${scheme_source} ${csp} ${whiteList};
|
connect-src 'self' ${scheme_source} ${csp} ${whiteList};
|
||||||
script-src 'self' ${scheme_source} ${csp} ${whiteList};
|
script-src 'self' 'wasm-unsafe-eval' ${scheme_source} ${csp} ${whiteList};
|
||||||
style-src 'self' 'unsafe-inline' ${scheme_source} ${whiteList};
|
style-src 'self' 'unsafe-inline' ${scheme_source} ${whiteList};
|
||||||
worker-src 'self' ${scheme_source} ${csp} ${whiteList};
|
worker-src 'self' ${scheme_source} ${csp} ${whiteList};
|
||||||
media-src 'self' ${scheme_source} ${csp} ${whiteList};
|
media-src 'self' ${scheme_source} ${csp} ${whiteList};
|
||||||
@ -56,7 +56,6 @@ export function middleware(request: NextRequest) {
|
|||||||
contentSecurityPolicyHeaderValue,
|
contentSecurityPolicyHeaderValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
// response.headers.set('x-nonce', nonce)
|
|
||||||
response.headers.set(
|
response.headers.set(
|
||||||
'Content-Security-Policy',
|
'Content-Security-Policy',
|
||||||
contentSecurityPolicyHeaderValue,
|
contentSecurityPolicyHeaderValue,
|
||||||
|
|||||||
Reference in New Issue
Block a user