Merge pull request #530 from Tria-plc/freight/feat/chat-app

fix: websocket fix attempt
This commit is contained in:
Nathnael Wondisha
2026-07-08 09:39:30 +03:00
committed by GitHub
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 = [