Bug 1631384 - Added upgrade exceptions for HTTPS Only Mode. r=ckerschb,necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D72002
This commit is contained in:
julianwels
2020-04-27 13:29:24 +00:00
parent 531c85e1b4
commit 0b655ee575
6 changed files with 253 additions and 27 deletions

View File

@@ -1579,22 +1579,26 @@ nsresult WebSocketImpl::Init(JSContext* aCx, nsIPrincipal* aLoadingPrincipal,
// If the HTTPS-Only mode is enabled, we need to upgrade the websocket
// connection from ws:// to wss:// and mark it as secure.
if (!mIsServerSide && !mSecure &&
StaticPrefs::dom_security_https_only_mode()) {
// let's use the old specification before the upgrade for logging
AutoTArray<nsString, 2> params;
CopyUTF8toUTF16(mURI, *params.AppendElement());
if (!mIsServerSide && !mSecure) {
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), mURI);
NS_ENSURE_SUCCESS(rv, rv);
mURI.ReplaceSubstring("ws://", "wss://");
if (NS_WARN_IF(mURI.Find("wss://") != 0)) {
return NS_OK;
nsCOMPtr<nsIChannel> channel = originDoc->GetChannel();
uint32_t httpsOnlyStatus = nsILoadInfo::HTTPS_ONLY_UNINITIALIZED;
if (channel) {
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
httpsOnlyStatus = loadInfo->GetHttpsOnlyStatus();
}
mSecure = true;
params.AppendElement(NS_LITERAL_STRING("wss"));
nsHTTPSOnlyUtils::LogLocalizedString("HTTPSOnlyUpgradeRequest", params,
nsIScriptError::warningFlag,
mInnerWindowID, mPrivateBrowsing);
if (nsHTTPSOnlyUtils::ShouldUpgradeWebSocket(
uri, mInnerWindowID, mPrivateBrowsing, httpsOnlyStatus)) {
mURI.ReplaceSubstring("ws://", "wss://");
if (NS_WARN_IF(mURI.Find("wss://") != 0)) {
return NS_OK;
}
mSecure = true;
}
}
// Potentially the page uses the CSP directive 'upgrade-insecure-requests'.