summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@gmail.com>2023-01-11 08:39:06 +1000
committerLorn Potter <lorn.potter@gmail.com>2023-02-09 11:39:25 +1000
commitedbea44a9af0c16833ede6a38d79390cdc6f8958 (patch)
treefbd4a5c8d306cfa733a765bec628fe888f6c7259
parent937a3bf5a4186f494f95a32456cd473349802f70 (diff)
downloadqtwebsockets-edbea44a9af0c16833ede6a38d79390cdc6f8958.tar.gz
wasm: make exception for localhost,127.0.0.1 and ::1
Localhost is a special case for secure context and is considered secure, so we can open this up for mixed ws:// on https:// Pick-to: 6.4 6.5 Change-Id: I150ce6447b57b70040039a4da2a3966025e3bb33 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/websockets/qwebsocket_wasm_p.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/websockets/qwebsocket_wasm_p.cpp b/src/websockets/qwebsocket_wasm_p.cpp
index d38c527..9e73e1d 100644
--- a/src/websockets/qwebsocket_wasm_p.cpp
+++ b/src/websockets/qwebsocket_wasm_p.cpp
@@ -12,6 +12,8 @@
#include <emscripten/websocket.h>
#include <emscripten/val.h>
+#include <QHostAddress>
+
static EM_BOOL q_onWebSocketErrorCallback(int eventType,
const EmscriptenWebSocketErrorEvent *e,
void *userData)
@@ -150,12 +152,22 @@ void QWebSocketPrivate::open(const QNetworkRequest &request,
return;
}
- if (isSecureContext && url.scheme() == QStringLiteral("ws")) {
- const QString message =
+ // exception for localhost/127.0.0.1/[::1]
+ // localhost has special privledges
+
+ QHostAddress hostAddress(url.host());
+
+ bool hostAddressIsLocal = (hostAddress == QHostAddress::LocalHost
+ || hostAddress == QHostAddress::LocalHostIPv6);
+
+ if (url.host() != QStringLiteral("localhost") && !hostAddressIsLocal) {
+ if (isSecureContext && url.scheme() == QStringLiteral("ws")) {
+ const QString message =
QWebSocket::tr("Unsupported WebSocket scheme: %1").arg(url.scheme());
- setErrorString(message);
- emitErrorOccurred(QAbstractSocket::UnsupportedSocketOperationError);
- return;
+ setErrorString(message);
+ emitErrorOccurred(QAbstractSocket::UnsupportedSocketOperationError);
+ return;
+ }
}
EmscriptenWebSocketCreateAttributes attr;