From 86741ad489c3ee2d519eeb071be846721b90412c Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Thu, 13 May 2021 04:13:34 -0400 Subject: Fix: [Emscripten] Force secure WebSockets over HTTPS (#9248) --- os/emscripten/pre.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'os') diff --git a/os/emscripten/pre.js b/os/emscripten/pre.js index 82664004e..2fb641017 100644 --- a/os/emscripten/pre.js +++ b/os/emscripten/pre.js @@ -9,7 +9,15 @@ Module['websocket'] = { url: function(host, port, proto) { * If you run your own server you can setup your own WebSocket proxy in * front of it and let people connect to your server via the proxy. You * are best to add another "if" statement as above for this. */ - return null; + + if (location.protocol === 'https:') { + /* Insecure WebSockets do not work over HTTPS, so we force + * secure ones. */ + return 'wss://'; + } else { + /* Use the default provided by Emscripten. */ + return null; + } } }; Module.preRun.push(function() { -- cgit v1.2.3-54-g00ecf