Firefox refuses WSS WebSocket upgrade due to strict Content-Security-Policy connect-src while Chrome succeeds
Environment
HTTPS site served from https://app.example.com with CSP header 'Content-Security-Policy: default-src 'self'; connect-src 'self';' Backend websocket endpoint wss://ws.example.com. Service Worker installed on the site. Issue reproduces on Firefox 116/120 on macOS and Linux; Chrome and Safari connect ok.
Symptoms
In Firefox the WebSocket connection fails at the upgrade step; console shows a CSP error 'Refused to connect to wss://ws.example.com because it violates the following Content Security Policy directive: "connect-src 'self'"'. The same CSP header allows XMLHttpRequest/fetch to ws.example.com when used via https fetch to an HTTP endpoint; service worker interceptors add fetch handlers.
Observations
Response header for CSP shows just connect-src 'self'. The WS endpoint is on a different subdomain (ws.example.com). Adding 'wss://ws.example.com' to connect-src appears to fix Chrome but Firefox still rejects when the connection is initiated from a page controlled by a Service Worker script. When the service worker is unregistered the wss connection succeeds in Firefox if connect-src includes the exact wss origin. No mixed-content TLS errors are present.
Already attempted
Updated CSP header to include wss: and specific host; still blocked in Firefox when service worker active. Tried using meta CSP (in-page) — same result. Tried moving WS to same origin — works. Verified TLS certificates chain and hostnames correct. Cleared caches, tested private window.
Question
Why does Firefox block the WSS upgrade even when the connect-src includes the wss origin, and how can I allow the WebSocket connection without disabling the service worker or weakening security?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags