Bug 1883954: Update, improve and unify HTTPS Telemetry, r=freddyb,kershaw,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D212661
This commit is contained in:
Christoph Kerschbaumer 2024-06-24 12:56:31 +00:00
Родитель 8cb4eaad8b
Коммит 811a0a736d
18 изменённых файлов: 257 добавлений и 70 удалений

Просмотреть файл

@ -91,6 +91,7 @@ nsDocShellLoadState::nsDocShellLoadState(
mTriggeringStorageAccess = aLoadState.TriggeringStorageAccess();
mTriggeringRemoteType = aLoadState.TriggeringRemoteType();
mWasSchemelessInput = aLoadState.WasSchemelessInput();
mHttpsUpgradeTelemetry = aLoadState.HttpsUpgradeTelemetry();
mCsp = aLoadState.Csp();
mOriginalURIString = aLoadState.OriginalURIString();
mCancelContentJSEpoch = aLoadState.CancelContentJSEpoch();
@ -196,7 +197,8 @@ nsDocShellLoadState::nsDocShellLoadState(const nsDocShellLoadState& aOther)
mUnstrippedURI(aOther.mUnstrippedURI),
mRemoteTypeOverride(aOther.mRemoteTypeOverride),
mTriggeringRemoteType(aOther.mTriggeringRemoteType),
mWasSchemelessInput(aOther.mWasSchemelessInput) {
mWasSchemelessInput(aOther.mWasSchemelessInput),
mHttpsUpgradeTelemetry(aOther.mHttpsUpgradeTelemetry) {
MOZ_DIAGNOSTIC_ASSERT(
XRE_IsParentProcess(),
"Cloning a nsDocShellLoadState with the same load identifier is only "
@ -242,6 +244,11 @@ nsDocShellLoadState::nsDocShellLoadState(nsIURI* aURI, uint64_t aLoadIdentifier)
: NOT_REMOTE_TYPE),
mWasSchemelessInput(false) {
MOZ_ASSERT(aURI, "Cannot create a LoadState with a null URI!");
if (aURI->SchemeIs("https")) {
mHttpsUpgradeTelemetry = nsILoadInfo::ALREADY_HTTPS;
} else {
mHttpsUpgradeTelemetry = nsILoadInfo::NO_UPGRADE;
}
}
nsDocShellLoadState::~nsDocShellLoadState() {
@ -1308,6 +1315,7 @@ DocShellLoadStateInit nsDocShellLoadState::Serialize(
loadState.TriggeringStorageAccess() = mTriggeringStorageAccess;
loadState.TriggeringRemoteType() = mTriggeringRemoteType;
loadState.WasSchemelessInput() = mWasSchemelessInput;
loadState.HttpsUpgradeTelemetry() = mHttpsUpgradeTelemetry;
loadState.Csp() = mCsp;
loadState.OriginalURIString() = mOriginalURIString;
loadState.CancelContentJSEpoch() = mCancelContentJSEpoch;

Просмотреть файл

@ -337,6 +337,15 @@ class nsDocShellLoadState final {
bool GetWasSchemelessInput() { return mWasSchemelessInput; }
void SetHttpsUpgradeTelemetry(
nsILoadInfo::HTTPSUpgradeTelemetryType aHttpsUpgradeTelemetry) {
mHttpsUpgradeTelemetry = aHttpsUpgradeTelemetry;
}
nsILoadInfo::HTTPSUpgradeTelemetryType GetHttpsUpgradeTelemetry() {
return mHttpsUpgradeTelemetry;
}
// Determine the remote type of the process which should be considered
// responsible for this load for the purposes of security checks.
//
@ -612,6 +621,10 @@ class nsDocShellLoadState final {
// if the to-be-loaded address had it protocol added through a fixup
bool mWasSchemelessInput = false;
// Solely for the use of collecting Telemetry for HTTPS upgrades.
nsILoadInfo::HTTPSUpgradeTelemetryType mHttpsUpgradeTelemetry =
nsILoadInfo::NO_UPGRADE;
};
#endif /* nsDocShellLoadState_h__ */

Просмотреть файл

@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include "mozilla/dom/DomSecurityIPCUtils.h";
include "mozilla/GfxMessageUtils.h";
include "mozilla/dom/CSPMessageUtils.h";
include "mozilla/dom/DocShellMessageUtils.h";
@ -43,6 +44,7 @@ using mozilla::ImageIntSize from "Units.h";
using nsSizeMode from "nsIWidgetListener.h";
using mozilla::ScrollbarPreference from "mozilla/ScrollbarPreferences.h";
using mozilla::gfx::SurfaceFormat from "mozilla/gfx/Types.h";
using nsILoadInfo::HTTPSUpgradeTelemetryType from "nsILoadInfo.h";
[RefCounted] using class nsIPrincipal from "nsIPrincipal.h";
using mozilla::dom::MaybeDiscardedBrowsingContext from "mozilla/dom/BrowsingContext.h";
[RefCounted] using class nsIURI from "nsIURI.h";
@ -210,6 +212,7 @@ struct DocShellLoadStateInit
bool AllowFocusMove;
bool IsFromProcessingFrameAttributes;
bool WasSchemelessInput;
HTTPSUpgradeTelemetryType HttpsUpgradeTelemetry;
// Fields missing due to lack of need or serialization
// nsCOMPtr<nsIDocShell> mSourceDocShell;

Просмотреть файл

@ -1431,6 +1431,8 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvReloadWithHttpsOnlyException() {
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(insecureURI);
loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
loadState->SetLoadType(LOAD_NORMAL_REPLACE);
loadState->SetHttpsUpgradeTelemetry(
nsILoadInfo::HTTPS_ONLY_UPGRADE_DOWNGRADE);
RefPtr<CanonicalBrowsingContext> topBC = BrowsingContext()->Top();
topBC->LoadURI(loadState, /* setNavigating */ true);

Просмотреть файл

@ -0,0 +1,25 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_domsecurityipcutils_h
#define mozilla_dom_domsecurityipcutils_h
#include "ipc/EnumSerializer.h"
#include "nsILoadInfo.h"
namespace IPC {
// nsILoadInfo::HTTPSUpgradeTelemetryType over IPC.
template <>
struct ParamTraits<nsILoadInfo::HTTPSUpgradeTelemetryType>
: public ContiguousEnumSerializerInclusive<
nsILoadInfo::HTTPSUpgradeTelemetryType,
nsILoadInfo::HTTPSUpgradeTelemetryType::NO_UPGRADE,
nsILoadInfo::HTTPSUpgradeTelemetryType::HTTPS_RR> {};
} // namespace IPC
#endif // mozilla_dom_domsecurityipcutils_h

Просмотреть файл

@ -14,6 +14,7 @@ DIRS += ["featurepolicy", "sanitizer", "trusted-types"]
EXPORTS.mozilla.dom += [
"CSPEvalChecker.h",
"CSPViolationData.h",
"DomSecurityIPCUtils.h",
"DOMSecurityMonitor.h",
"FramingChecker.h",
"nsContentSecurityManager.h",

Просмотреть файл

@ -589,6 +589,19 @@ void nsHTTPSOnlyUtils::UpdateLoadStateAfterHTTPSFirstDowngrade(
// loop
aLoadState->SetIsExemptFromHTTPSFirstMode(true);
// we can safely set the flag to indicate the downgrade here and it will be
// propagated all the way to nsHttpChannel::OnStopRequest() where we collect
// the telemetry.
nsCOMPtr<nsIChannel> channel = aDocumentLoadListener->GetChannel();
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
if (loadInfo->GetWasSchemelessInput()) {
aLoadState->SetHttpsUpgradeTelemetry(
nsILoadInfo::HTTPS_FIRST_SCHEMELESS_UPGRADE_DOWNGRADE);
} else {
aLoadState->SetHttpsUpgradeTelemetry(
nsILoadInfo::HTTPS_FIRST_UPGRADE_DOWNGRADE);
}
// Add downgrade data for later telemetry usage to load state
nsDOMNavigationTiming* timing = aDocumentLoadListener->GetTiming();
if (timing) {
@ -597,9 +610,6 @@ void nsHTTPSOnlyUtils::UpdateLoadStateAfterHTTPSFirstDowngrade(
mozilla::TimeDuration duration =
mozilla::TimeStamp::Now() - navigationStart;
nsCOMPtr<nsIChannel> channel = aDocumentLoadListener->GetChannel();
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
bool isPrivateWin = loadInfo->GetOriginAttributes().IsPrivateBrowsing();
bool isSchemeless =
loadInfo->GetWasSchemelessInput() &&

Просмотреть файл

@ -576,10 +576,10 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
aLoadInfo->GetIsFormSubmission(), aLoadInfo->GetSendCSPViolationEvents(),
aLoadInfo->GetOriginAttributes(), redirectChainIncludingInternalRedirects,
redirectChain, aLoadInfo->GetHasInjectedCookieForCookieBannerHandling(),
aLoadInfo->GetWasSchemelessInput(), ipcClientInfo, ipcReservedClientInfo,
ipcInitialClientInfo, ipcController, aLoadInfo->CorsUnsafeHeaders(),
aLoadInfo->GetForcePreflight(), aLoadInfo->GetIsPreflight(),
aLoadInfo->GetLoadTriggeredFromExternal(),
aLoadInfo->GetWasSchemelessInput(), aLoadInfo->GetHttpsUpgradeTelemetry(),
ipcClientInfo, ipcReservedClientInfo, ipcInitialClientInfo, ipcController,
aLoadInfo->CorsUnsafeHeaders(), aLoadInfo->GetForcePreflight(),
aLoadInfo->GetIsPreflight(), aLoadInfo->GetLoadTriggeredFromExternal(),
aLoadInfo->GetServiceWorkerTaintingSynthesized(),
aLoadInfo->GetDocumentHasUserInteracted(),
aLoadInfo->GetAllowListFutureDocumentsCreatedFromThisRedirectChain(),
@ -885,7 +885,7 @@ nsresult LoadInfoArgsToLoadInfo(const LoadInfoArgs& loadInfoArgs,
loadInfoArgs.originTrialCoepCredentiallessEnabledForTopLevel(),
loadInfoArgs.unstrippedURI(), interceptionInfo,
loadInfoArgs.hasInjectedCookieForCookieBannerHandling(),
loadInfoArgs.wasSchemelessInput());
loadInfoArgs.wasSchemelessInput(), loadInfoArgs.httpsUpgradeTelemetry());
if (loadInfoArgs.isFromProcessingFrameAttributes()) {
loadInfo->SetIsFromProcessingFrameAttributes();
@ -953,6 +953,7 @@ void LoadInfoToParentLoadInfoForwarder(
*aForwarderArgsOut = ParentLoadInfoForwarderArgs(
aLoadInfo->GetAllowInsecureRedirectToDataURI(), ipcController, tainting,
aLoadInfo->GetSkipContentSniffing(), aLoadInfo->GetHttpsOnlyStatus(),
aLoadInfo->GetWasSchemelessInput(), aLoadInfo->GetHttpsUpgradeTelemetry(),
aLoadInfo->GetHstsStatus(), aLoadInfo->GetHasValidUserGestureActivation(),
aLoadInfo->GetAllowDeprecatedSystemRequests(),
aLoadInfo->GetIsInDevToolsContext(), aLoadInfo->GetParserCreatedScript(),
@ -996,6 +997,13 @@ nsresult MergeParentLoadInfoForwarder(
rv = aLoadInfo->SetHttpsOnlyStatus(aForwarderArgs.httpsOnlyStatus());
NS_ENSURE_SUCCESS(rv, rv);
rv = aLoadInfo->SetWasSchemelessInput(aForwarderArgs.wasSchemelessInput());
NS_ENSURE_SUCCESS(rv, rv);
rv = aLoadInfo->SetHttpsUpgradeTelemetry(
aForwarderArgs.httpsUpgradeTelemetry());
NS_ENSURE_SUCCESS(rv, rv);
rv = aLoadInfo->SetHstsStatus(aForwarderArgs.hstsStatus());
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -691,7 +691,8 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
mInterceptionInfo(rhs.mInterceptionInfo),
mHasInjectedCookieForCookieBannerHandling(
rhs.mHasInjectedCookieForCookieBannerHandling),
mWasSchemelessInput(rhs.mWasSchemelessInput) {
mWasSchemelessInput(rhs.mWasSchemelessInput),
mHttpsUpgradeTelemetry(rhs.mHttpsUpgradeTelemetry) {
}
LoadInfo::LoadInfo(
@ -738,7 +739,8 @@ LoadInfo::LoadInfo(
nsILoadInfo::CrossOriginEmbedderPolicy aLoadingEmbedderPolicy,
bool aIsOriginTrialCoepCredentiallessEnabledForTopLevel,
nsIURI* aUnstrippedURI, nsIInterceptionInfo* aInterceptionInfo,
bool aHasInjectedCookieForCookieBannerHandling, bool aWasSchemelessInput)
bool aHasInjectedCookieForCookieBannerHandling, bool aWasSchemelessInput,
nsILoadInfo::HTTPSUpgradeTelemetryType aHttpsUpgradeTelemetry)
: mLoadingPrincipal(aLoadingPrincipal),
mTriggeringPrincipal(aTriggeringPrincipal),
mPrincipalToInherit(aPrincipalToInherit),
@ -816,7 +818,8 @@ LoadInfo::LoadInfo(
mInterceptionInfo(aInterceptionInfo),
mHasInjectedCookieForCookieBannerHandling(
aHasInjectedCookieForCookieBannerHandling),
mWasSchemelessInput(aWasSchemelessInput) {
mWasSchemelessInput(aWasSchemelessInput),
mHttpsUpgradeTelemetry(aHttpsUpgradeTelemetry) {
// Only top level TYPE_DOCUMENT loads can have a null loadingPrincipal
MOZ_ASSERT(mLoadingPrincipal ||
aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT);
@ -2416,4 +2419,18 @@ LoadInfo::SetWasSchemelessInput(bool aWasSchemelessInput) {
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetHttpsUpgradeTelemetry(
nsILoadInfo::HTTPSUpgradeTelemetryType* aOutHttpsUpgradeTelemetry) {
*aOutHttpsUpgradeTelemetry = mHttpsUpgradeTelemetry;
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::SetHttpsUpgradeTelemetry(
nsILoadInfo::HTTPSUpgradeTelemetryType aHttpsUpgradeTelemetry) {
mHttpsUpgradeTelemetry = aHttpsUpgradeTelemetry;
return NS_OK;
}
} // namespace mozilla::net

Просмотреть файл

@ -258,7 +258,9 @@ class LoadInfo final : public nsILoadInfo {
nsILoadInfo::CrossOriginEmbedderPolicy aLoadingEmbedderPolicy,
bool aIsOriginTrialCoepCredentiallessEnabledForTopLevel,
nsIURI* aUnstrippedURI, nsIInterceptionInfo* aInterceptionInfo,
bool aHasInjectedCookieForCookieBannerHandling, bool aWasSchemelessInput);
bool aHasInjectedCookieForCookieBannerHandling, bool aWasSchemelessInput,
nsILoadInfo::HTTPSUpgradeTelemetryType aHttpsUpgradeTelemetry);
LoadInfo(const LoadInfo& rhs);
NS_IMETHOD GetRedirects(JSContext* aCx,
@ -408,6 +410,9 @@ class LoadInfo final : public nsILoadInfo {
bool mHasInjectedCookieForCookieBannerHandling = false;
bool mWasSchemelessInput = false;
nsILoadInfo::HTTPSUpgradeTelemetryType mHttpsUpgradeTelemetry =
nsILoadInfo::NO_UPGRADE;
};
// This is exposed solely for testing purposes and should not be used outside of

Просмотреть файл

@ -870,5 +870,17 @@ TRRLoadInfo::SetWasSchemelessInput(bool aWasSchemelessInput) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::GetHttpsUpgradeTelemetry(
nsILoadInfo::HTTPSUpgradeTelemetryType* aOutHttpsTelemetry) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::SetHttpsUpgradeTelemetry(
nsILoadInfo::HTTPSUpgradeTelemetryType aHttpsTelemetry) {
return NS_ERROR_NOT_IMPLEMENTED;
}
} // namespace net
} // namespace mozilla

Просмотреть файл

@ -1544,4 +1544,23 @@ interface nsILoadInfo : nsISupports
* Whether the load has gone through the URL bar, where the fixup had to add * the protocol scheme.
*/
[infallible] attribute boolean wasSchemelessInput;
cenum HTTPSUpgradeTelemetryType : 32 {
NO_UPGRADE = 0,
ALREADY_HTTPS = (1 << 0),
HSTS = (1 << 1),
HTTPS_ONLY_UPGRADE = (1 << 2),
HTTPS_ONLY_UPGRADE_DOWNGRADE = (1 << 3),
HTTPS_FIRST_UPGRADE = (1 << 4),
HTTPS_FIRST_UPGRADE_DOWNGRADE = (1 << 5),
HTTPS_FIRST_SCHEMELESS_UPGRADE = (1 << 6),
HTTPS_FIRST_SCHEMELESS_UPGRADE_DOWNGRADE = (1 << 7),
HTTPS_RR = (1 << 8),
};
/**
* Solely for the use of collecting Telemetry for HTTPS upgrades.
*/
[infallible] attribute nsILoadInfo_HTTPSUpgradeTelemetryType httpsUpgradeTelemetry;
};

Просмотреть файл

@ -2931,15 +2931,8 @@ bool handleResultFunc(bool aAllowSTS, bool aIsStsHost) {
if (aIsStsHost) {
LOG(("nsHttpChannel::Connect() STS permissions found\n"));
if (aAllowSTS) {
Telemetry::AccumulateCategorical(
Telemetry::LABELS_HTTP_SCHEME_UPGRADE_TYPE::STS);
return true;
}
Telemetry::AccumulateCategorical(
Telemetry::LABELS_HTTP_SCHEME_UPGRADE_TYPE::PrefBlockedSTS);
} else {
Telemetry::AccumulateCategorical(
Telemetry::LABELS_HTTP_SCHEME_UPGRADE_TYPE::NoReasonToUpgrade);
}
return false;
};
@ -2966,8 +2959,6 @@ static bool ShouldSecureUpgradeNoHSTS(nsIURI* aURI, nsILoadInfo* aLoadInfo) {
nsIScriptError::warningFlag,
"upgradeInsecureRequest"_ns, innerWindowId,
aLoadInfo->GetOriginAttributes().IsPrivateBrowsing());
Telemetry::AccumulateCategorical(
Telemetry::LABELS_HTTP_SCHEME_UPGRADE_TYPE::CSP);
return true;
}
// 3. Mixed content auto upgrading
@ -2999,22 +2990,22 @@ static bool ShouldSecureUpgradeNoHSTS(nsIURI* aURI, nsILoadInfo* aLoadInfo) {
// Set this flag so we know we'll upgrade because of
// 'security.mixed_content.upgrade_display_content'.
aLoadInfo->SetBrowserDidUpgradeInsecureRequests(true);
Telemetry::AccumulateCategorical(
Telemetry::LABELS_HTTP_SCHEME_UPGRADE_TYPE::BrowserDisplay);
return true;
}
// 4. Https-Only
if (nsHTTPSOnlyUtils::ShouldUpgradeRequest(aURI, aLoadInfo)) {
Telemetry::AccumulateCategorical(
Telemetry::LABELS_HTTP_SCHEME_UPGRADE_TYPE::HTTPSOnly);
aLoadInfo->SetHttpsUpgradeTelemetry(nsILoadInfo::HTTPS_ONLY_UPGRADE);
return true;
}
// 4.a Https-First
if (nsHTTPSOnlyUtils::ShouldUpgradeHttpsFirstRequest(aURI, aLoadInfo)) {
Telemetry::AccumulateCategorical(
Telemetry::LABELS_HTTP_SCHEME_UPGRADE_TYPE::HTTPSFirst);
if (aLoadInfo->GetWasSchemelessInput()) {
aLoadInfo->SetHttpsUpgradeTelemetry(
nsILoadInfo::HTTPS_FIRST_SCHEMELESS_UPGRADE);
} else {
aLoadInfo->SetHttpsUpgradeTelemetry(nsILoadInfo::HTTPS_FIRST_UPGRADE);
}
return true;
}
return false;
@ -3047,8 +3038,7 @@ nsresult NS_ShouldSecureUpgrade(
// If request is https, then there is nothing to do here.
if (isHttps) {
Telemetry::AccumulateCategorical(
Telemetry::LABELS_HTTP_SCHEME_UPGRADE_TYPE::AlreadyHTTPS);
aLoadInfo->SetHttpsUpgradeTelemetry(nsILoadInfo::ALREADY_HTTPS);
aShouldUpgrade = false;
return NS_OK;
}
@ -3131,6 +3121,11 @@ nsresult NS_ShouldSecureUpgrade(
NS_ENSURE_SUCCESS(rv, rv);
aShouldUpgrade = handleResultFunc(aAllowSTS, isStsHost);
// we can't pass the loadinfo to handleResultFunc since it's not threadsafe
// hence we set the http telemetry information on the loadinfo here.
if (aShouldUpgrade) {
aLoadInfo->SetHttpsUpgradeTelemetry(nsILoadInfo::HSTS);
}
if (!aShouldUpgrade) {
// Check for CSP upgrade-insecure-requests, Mixed content auto upgrading
// and Https-Only / -First.

Просмотреть файл

@ -161,6 +161,7 @@ static auto CreateDocumentLoadInfo(CanonicalBrowsingContext* aBrowsingContext,
}
loadInfo->SetWasSchemelessInput(aLoadState->GetWasSchemelessInput());
loadInfo->SetHttpsUpgradeTelemetry(aLoadState->GetHttpsUpgradeTelemetry());
loadInfo->SetTriggeringSandboxFlags(aLoadState->TriggeringSandboxFlags());
loadInfo->SetTriggeringWindowId(aLoadState->TriggeringWindowId());

Просмотреть файл

@ -14,6 +14,7 @@ include PBackgroundSharedTypes;
include DOMTypes;
include ProtocolTypes;
include "mozilla/dom/DomSecurityIPCUtils.h";
include "mozilla/dom/FetchIPCTypes.h";
include "mozilla/dom/FeaturePolicyUtils.h";
include "mozilla/dom/PropertyBagUtils.h";
@ -39,6 +40,7 @@ using struct mozilla::dom::LoadingSessionHistoryInfo from "mozilla/dom/SessionHi
using mozilla::dom::RequestMode from "mozilla/dom/RequestBinding.h";
using mozilla::net::LinkHeader from "nsNetUtil.h";
using mozilla::dom::FeaturePolicyInfo from "mozilla/dom/FeaturePolicy.h";
using nsILoadInfo::HTTPSUpgradeTelemetryType from "nsILoadInfo.h";
namespace mozilla {
namespace net {
@ -137,6 +139,7 @@ struct LoadInfoArgs
RedirectHistoryEntryInfo[] redirectChain;
bool hasInjectedCookieForCookieBannerHandling;
bool wasSchemelessInput;
HTTPSUpgradeTelemetryType httpsUpgradeTelemetry;
/**
* ClientInfo structure representing the window or worker that triggered
@ -223,6 +226,10 @@ struct ParentLoadInfoForwarderArgs
uint32_t httpsOnlyStatus;
bool wasSchemelessInput;
HTTPSUpgradeTelemetryType httpsUpgradeTelemetry;
bool hstsStatus;
// Returns true if at the time of the loadinfo construction the document

Просмотреть файл

@ -964,22 +964,6 @@ networking:
- presented_with_http3
- none
https_upgrade_with_https_rr:
type: labeled_counter
description: >
Whether an HTTP request gets upgraded to HTTPS because of HTTPS RR
bugs:
- https://bugzilla.mozilla.org/1686421
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1686421
notification_emails:
- necko@mozilla.com
- kershaw@mozilla.com
expires: never
labels:
- https_rr
- others
http_channel_onstart_success_https_rr:
type: labeled_counter
description: >
@ -1136,6 +1120,33 @@ networking:
- kershaw@mozilla.com
expires: never
http_to_https_upgrade_reason:
type: labeled_counter
description: >
Whether a top-level HTTP request gets upgraded to HTTPS and the reason for it
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1883954
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1883954
notification_emails:
- ckerschb@mozilla.com
- freddyb@mozilla.com
- kershaw@mozilla.com
- necko@mozilla.com
- seceng-telemetry@mozilla.com
expires: never
labels:
- no_upgrade
- already_https
- hsts
- https_only_upgrade
- https_only_upgrade_downgrade
- https_first_upgrade
- https_first_upgrade_downgrade
- https_first_schemeless_upgrade
- https_first_schemeless_upgrade_downgrade
- https_rr
http_channel_sub_open_to_first_sent_https_rr:
type: timing_distribution
time_unit: millisecond

Просмотреть файл

@ -794,9 +794,12 @@ nsresult nsHttpChannel::ContinueOnBeforeConnect(bool aShouldUpgrade,
}
if (aShouldUpgrade && !mURI->SchemeIs("https")) {
mozilla::glean::networking::https_upgrade_with_https_rr
.Get(aUpgradeWithHTTPSRR ? "https_rr"_ns : "others"_ns)
.Add(1);
// only set HTTPS_RR to be responsbile for the upgrade in the loadinfo
// if it actually was responsible, otherwise the correct flag is
// already present in the loadinfo.
if (aUpgradeWithHTTPSRR) {
mLoadInfo->SetHttpsUpgradeTelemetry(nsILoadInfo::HTTPS_RR);
}
return AsyncCall(&nsHttpChannel::HandleAsyncRedirectChannelToHttps);
}
@ -7908,6 +7911,71 @@ nsresult nsHttpChannel::LogConsoleError(const char* aTag) {
return NS_OK;
}
static void RecordHTTPSUpgradeTelemetry(nsILoadInfo* aLoadInfo) {
// we record https telemetry only for top-level loads
if (aLoadInfo->GetExternalContentPolicyType() !=
ExtContentPolicy::TYPE_DOCUMENT) {
return;
}
nsILoadInfo::HTTPSUpgradeTelemetryType httpsTelemetry =
nsILoadInfo::NO_UPGRADE;
aLoadInfo->GetHttpsUpgradeTelemetry(&httpsTelemetry);
switch (httpsTelemetry) {
case nsILoadInfo::NO_UPGRADE:
mozilla::glean::networking::http_to_https_upgrade_reason
.Get("no_upgrade"_ns)
.Add(1);
break;
case nsILoadInfo::ALREADY_HTTPS:
mozilla::glean::networking::http_to_https_upgrade_reason
.Get("already_https"_ns)
.Add(1);
break;
case nsILoadInfo::HSTS:
mozilla::glean::networking::http_to_https_upgrade_reason.Get("hsts"_ns)
.Add(1);
break;
case nsILoadInfo::HTTPS_ONLY_UPGRADE:
mozilla::glean::networking::http_to_https_upgrade_reason
.Get("https_only_upgrade"_ns)
.Add(1);
break;
case nsILoadInfo::HTTPS_ONLY_UPGRADE_DOWNGRADE:
mozilla::glean::networking::http_to_https_upgrade_reason
.Get("https_only_upgrade_downgrade"_ns)
.Add(1);
break;
case nsILoadInfo::HTTPS_FIRST_UPGRADE:
mozilla::glean::networking::http_to_https_upgrade_reason
.Get("https_first_upgrade"_ns)
.Add(1);
break;
case nsILoadInfo::HTTPS_FIRST_UPGRADE_DOWNGRADE:
mozilla::glean::networking::http_to_https_upgrade_reason
.Get("https_first_upgrade_downgrade"_ns)
.Add(1);
break;
case nsILoadInfo::HTTPS_FIRST_SCHEMELESS_UPGRADE:
mozilla::glean::networking::http_to_https_upgrade_reason
.Get("https_first_schemeless_upgrade"_ns)
.Add(1);
break;
case nsILoadInfo::HTTPS_FIRST_SCHEMELESS_UPGRADE_DOWNGRADE:
mozilla::glean::networking::http_to_https_upgrade_reason
.Get("https_first_schemeless_upgrade_downgrade"_ns)
.Add(1);
break;
case nsILoadInfo::HTTPS_RR:
mozilla::glean::networking::http_to_https_upgrade_reason
.Get("https_rr"_ns)
.Add(1);
break;
default:
MOZ_ASSERT(false, "what telemetry flag is set to end up here?");
}
}
NS_IMETHODIMP
nsHttpChannel::OnStopRequest(nsIRequest* request, nsresult status) {
AUTO_PROFILER_LABEL("nsHttpChannel::OnStopRequest", NETWORK);
@ -8050,6 +8118,8 @@ nsHttpChannel::OnStopRequest(nsIRequest* request, nsresult status) {
mTransferSize = mTransaction->GetTransferSize();
mRequestSize = mTransaction->GetRequestSize();
RecordHTTPSUpgradeTelemetry(mLoadInfo);
// If we are using the transaction to serve content, we also save the
// time since async open in the cache entry so we can compare telemetry
// between cache and net response.

Просмотреть файл

@ -3026,26 +3026,6 @@
"kind": "boolean",
"description": "Whether or not a new alt-svc mapping would change the target hostname of the existing mapping"
},
"HTTP_SCHEME_UPGRADE_TYPE": {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec"],
"alert_emails": ["seceng-telemetry@mozilla.com", "freddyb@mozilla.com"],
"bug_numbers": [1340021, 1435733, 1722895],
"releaseChannelCollection": "opt-out",
"expires_in_version": "never",
"kind": "categorical",
"labels": [
"AlreadyHTTPS",
"NoReasonToUpgrade",
"PrefBlockedSTS",
"STS",
"CSP",
"BrowserDisplay",
"HTTPSOnly",
"HTTPSFirst"
],
"description": "Was the URL upgraded to HTTPS?"
},
"HTTP_RESPONSE_STATUS_CODE": {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec"],