From 5db60be47643d4a43a9cf85b5ec925ddce673a02 Mon Sep 17 00:00:00 2001 From: Valentin Batz Date: Fri, 14 Mar 2025 11:46:38 +0100 Subject: [PATCH] Remove zone id from IPv6 host in prepareRequest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure that link-local IPv6 addresses in a HTTP Request do not include the zone identifier in the 'Host' header, as per RFC 6874. This prevents connection failures due to invalid host syntax. Fixes: QTBUG-134727 Change-Id: I7067a991f67d44241717a89b656a3fcbda1fcd3a Reviewed-by: Øystein Heskestad Reviewed-by: Thiago Macieira --- src/network/access/qhttpnetworkconnection.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index cf7aad1930d..08eee386728 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -234,6 +234,18 @@ static QByteArray makeAcceptLanguage() return (systemLocale + ",en,*"_L1).toLatin1(); } +static QStringView removeZoneId(QStringView ipv6HostAddress) +{ + const auto zoneIdentfierIndex = ipv6HostAddress.indexOf(u'%'); + // Only perform a minimal sanity check, as at this point the + // ipv6HostAddress was already used successfully to establish the connection. + if (zoneIdentfierIndex == -1) { + return ipv6HostAddress; + } + + return ipv6HostAddress.left(zoneIdentfierIndex); +} + void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair) { QHttpNetworkRequest &request = messagePair.first; @@ -317,7 +329,7 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair) QByteArray host; if (add.setAddress(hostName)) { if (add.protocol() == QAbstractSocket::IPv6Protocol) - host = (u'[' + hostName + u']').toLatin1(); //format the ipv6 in the standard way + host = (u'[' + removeZoneId(hostName) + u']').toLatin1(); //format the ipv6 in the standard way else host = hostName.toLatin1();