fix: websocket fix attempt

This commit is contained in:
Nathnael
2026-07-08 06:38:24 +00:00
parent a817976db8
commit 972b1e973a
2 changed files with 10 additions and 2 deletions

View File

@@ -35,8 +35,12 @@ function buildCsp(nonce: string): string {
? `'self' 'nonce-${nonce}' 'strict-dynamic'`
: `'self' 'unsafe-inline' 'unsafe-eval'`;
// The Socket.IO WebSocket upgrade connects to wss://<api-host>; under CSP a
// `https://host` source does NOT cover `wss://host`, so add it explicitly.
const wsOrigin = apiOrigin.replace(/^http/, 'ws'); // https→wss, http→ws
const connectSrc = isProd
? `'self' ${apiOrigin}`.trim()
? `'self' ${apiOrigin} ${wsOrigin}`.trim()
: `'self' ${apiOrigin} ws: wss:`.trim();
const directives = [

View File

@@ -48,8 +48,12 @@ function buildCsp(nonce: string): string {
? `'self' 'nonce-${nonce}' 'strict-dynamic'`
: `'self' 'unsafe-inline' 'unsafe-eval'`;
// The Socket.IO WebSocket upgrade connects to wss://<api-host>; under CSP a
// `https://host` source does NOT cover `wss://host`, so add it explicitly.
const wsOrigin = apiOrigin.replace(/^http/, 'ws'); // https→wss, http→ws
const connectSrc = isProd
? `'self' ${apiOrigin}`.trim()
? `'self' ${apiOrigin} ${wsOrigin}`.trim()
: `'self' ${apiOrigin} ws: wss:`.trim();
const directives = [