Bug 1440701 - Adding in telemetry for upgrading display content. r=ckerschb,valentin

MozReview-Commit-ID: 7oEIith4Ehv

--HG--
extra : rebase_source : 454d56277aa5dc08bf8cfd7cd9c1e24d31014838
This commit is contained in:
Jonathan Kingston 2018-03-04 14:33:33 +00:00
parent 46575fad3b
commit 10ebc30d5d
10 changed files with 98 additions and 5 deletions

View File

@ -8826,8 +8826,7 @@ bool
nsContentUtils::IsUpgradableDisplayType(nsContentPolicyType aType)
{
MOZ_ASSERT(NS_IsMainThread());
return sIsUpgradableDisplayContentPrefEnabled &&
(aType == nsIContentPolicy::TYPE_IMAGE ||
return (aType == nsIContentPolicy::TYPE_IMAGE ||
aType == nsIContentPolicy::TYPE_MEDIA);
}

View File

@ -55,9 +55,12 @@ bool nsMixedContentBlocker::sBlockMixedScript = false;
bool nsMixedContentBlocker::sBlockMixedObjectSubrequest = false;
// Is mixed display content blocking (images, audio, video, <a ping>) enabled?
// Is mixed display content blocking (images, audio, video) enabled?
bool nsMixedContentBlocker::sBlockMixedDisplay = false;
// Is mixed display content upgrading (images, audio, video) enabled?
bool nsMixedContentBlocker::sUpgradeMixedDisplay = false;
enum MixedContentHSTSState {
MCB_HSTS_PASSIVE_NO_HSTS = 0,
MCB_HSTS_PASSIVE_WITH_HSTS = 1,
@ -214,6 +217,10 @@ nsMixedContentBlocker::nsMixedContentBlocker()
// Cache the pref for mixed display blocking
Preferences::AddBoolVarCache(&sBlockMixedDisplay,
"security.mixed_content.block_display_content");
// Cache the pref for mixed display upgrading
Preferences::AddBoolVarCache(&sUpgradeMixedDisplay,
"security.mixed_content.upgrade_display_content");
}
nsMixedContentBlocker::~nsMixedContentBlocker()
@ -777,7 +784,7 @@ nsMixedContentBlocker::ShouldLoad(bool aHadInsecureImageRedirect,
// pref "security.mixed_content.upgrade_display_content" is true.
// This behaves like GetUpgradeInsecureRequests above in that the channel will
// be upgraded to https before fetching any data from the netwerk.
bool isUpgradableDisplayType = nsContentUtils::IsUpgradableDisplayType(aContentType);
bool isUpgradableDisplayType = nsContentUtils::IsUpgradableDisplayType(aContentType) && ShouldUpgradeMixedDisplayContent();
if (isHttpScheme && isUpgradableDisplayType) {
*aDecision = ACCEPT;
return NS_OK;
@ -1128,3 +1135,9 @@ nsMixedContentBlocker::AccumulateMixedContentHSTS(
}
}
}
bool
nsMixedContentBlocker::ShouldUpgradeMixedDisplayContent()
{
return sUpgradeMixedDisplay;
}

View File

@ -72,9 +72,12 @@ public:
bool aActive,
const OriginAttributes& aOriginAttributes);
static bool ShouldUpgradeMixedDisplayContent();
static bool sBlockMixedScript;
static bool sBlockMixedObjectSubrequest;
static bool sBlockMixedDisplay;
static bool sUpgradeMixedDisplay;
};
#endif /* nsMixedContentBlocker_h___ */

View File

@ -404,6 +404,7 @@ LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo,
static_cast<uint32_t>(aLoadInfo->GetTainting()),
aLoadInfo->GetUpgradeInsecureRequests(),
aLoadInfo->GetBrowserUpgradeInsecureRequests(),
aLoadInfo->GetBrowserWouldUpgradeInsecureRequests(),
aLoadInfo->GetVerifySignedContent(),
aLoadInfo->GetEnforceSRI(),
aLoadInfo->GetAllowDocumentToBeAgnosticToCSP(),
@ -551,6 +552,7 @@ LoadInfoArgsToLoadInfo(const OptionalLoadInfoArgs& aOptionalLoadInfoArgs,
static_cast<LoadTainting>(loadInfoArgs.tainting()),
loadInfoArgs.upgradeInsecureRequests(),
loadInfoArgs.browserUpgradeInsecureRequests(),
loadInfoArgs.browserWouldUpgradeInsecureRequests(),
loadInfoArgs.verifySignedContent(),
loadInfoArgs.enforceSRI(),
loadInfoArgs.allowDocumentToBeAgnosticToCSP(),

View File

@ -25,6 +25,7 @@
#include "nsContentUtils.h"
#include "nsDocShell.h"
#include "nsGlobalWindow.h"
#include "nsMixedContentBlocker.h"
#include "NullPrincipal.h"
#include "nsRedirectHistoryEntry.h"
#include "LoadInfo.h"
@ -65,6 +66,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
, mTainting(LoadTainting::Basic)
, mUpgradeInsecureRequests(false)
, mBrowserUpgradeInsecureRequests(false)
, mBrowserWouldUpgradeInsecureRequests(false)
, mVerifySignedContent(false)
, mEnforceSRI(false)
, mAllowDocumentToBeAgnosticToCSP(false)
@ -195,7 +197,11 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
bool isHttpsScheme;
nsresult rv = uri->SchemeIs("https", &isHttpsScheme);
if (NS_SUCCEEDED(rv) && isHttpsScheme) {
mBrowserUpgradeInsecureRequests = true;
if (nsMixedContentBlocker::ShouldUpgradeMixedDisplayContent()) {
mBrowserUpgradeInsecureRequests = true;
} else {
mBrowserWouldUpgradeInsecureRequests = true;
}
}
}
}
@ -286,6 +292,7 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
, mTainting(LoadTainting::Basic)
, mUpgradeInsecureRequests(false)
, mBrowserUpgradeInsecureRequests(false)
, mBrowserWouldUpgradeInsecureRequests(false)
, mVerifySignedContent(false)
, mEnforceSRI(false)
, mAllowDocumentToBeAgnosticToCSP(false)
@ -363,6 +370,7 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
, mTainting(rhs.mTainting)
, mUpgradeInsecureRequests(rhs.mUpgradeInsecureRequests)
, mBrowserUpgradeInsecureRequests(rhs.mBrowserUpgradeInsecureRequests)
, mBrowserWouldUpgradeInsecureRequests(rhs.mBrowserWouldUpgradeInsecureRequests)
, mVerifySignedContent(rhs.mVerifySignedContent)
, mEnforceSRI(rhs.mEnforceSRI)
, mAllowDocumentToBeAgnosticToCSP(rhs.mAllowDocumentToBeAgnosticToCSP)
@ -407,6 +415,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
LoadTainting aTainting,
bool aUpgradeInsecureRequests,
bool aBrowserUpgradeInsecureRequests,
bool aBrowserWouldUpgradeInsecureRequests,
bool aVerifySignedContent,
bool aEnforceSRI,
bool aAllowDocumentToBeAgnosticToCSP,
@ -445,6 +454,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
, mTainting(aTainting)
, mUpgradeInsecureRequests(aUpgradeInsecureRequests)
, mBrowserUpgradeInsecureRequests(aBrowserUpgradeInsecureRequests)
, mBrowserWouldUpgradeInsecureRequests(aBrowserWouldUpgradeInsecureRequests)
, mVerifySignedContent(aVerifySignedContent)
, mEnforceSRI(aEnforceSRI)
, mAllowDocumentToBeAgnosticToCSP(aAllowDocumentToBeAgnosticToCSP)
@ -809,6 +819,13 @@ LoadInfo::GetBrowserUpgradeInsecureRequests(bool* aResult)
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetBrowserWouldUpgradeInsecureRequests(bool* aResult)
{
*aResult = mBrowserWouldUpgradeInsecureRequests;
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::SetVerifySignedContent(bool aVerifySignedContent)
{
@ -1159,6 +1176,12 @@ LoadInfo::SetBrowserUpgradeInsecureRequests()
mBrowserUpgradeInsecureRequests = true;
}
void
LoadInfo::SetBrowserWouldUpgradeInsecureRequests()
{
mBrowserWouldUpgradeInsecureRequests = true;
}
NS_IMETHODIMP
LoadInfo::GetIsPreflight(bool* aIsPreflight)
{

View File

@ -94,6 +94,7 @@ public:
void SetIsPreflight();
void SetUpgradeInsecureRequests();
void SetBrowserUpgradeInsecureRequests();
void SetBrowserWouldUpgradeInsecureRequests();
private:
// private constructor that is only allowed to be called from within
@ -114,6 +115,7 @@ private:
LoadTainting aTainting,
bool aUpgradeInsecureRequests,
bool aBrowserUpgradeInsecureRequests,
bool aBrowserWouldUpgradeInsecureRequests,
bool aVerifySignedContent,
bool aEnforceSRI,
bool aAllowDocumentToBeAgnosticToCSP,
@ -181,6 +183,7 @@ private:
LoadTainting mTainting;
bool mUpgradeInsecureRequests;
bool mBrowserUpgradeInsecureRequests;
bool mBrowserWouldUpgradeInsecureRequests;
bool mVerifySignedContent;
bool mEnforceSRI;
bool mAllowDocumentToBeAgnosticToCSP;

View File

@ -515,6 +515,14 @@ interface nsILoadInfo : nsISupports
* This is very similar in implementation to upgradeInsecureRequests but browser set.
*/
[infallible] readonly attribute boolean browserUpgradeInsecureRequests;
/**
* Returns true if the the page is https and the content is upgradable from http
* requires 'security.mixed_content.upgrade_display_content' pref to be false.
* See browserUpgradeInsecureRequests for more details, this only happens
* when *not* upgrading purely for telemetry.
*/
[infallible] readonly attribute boolean browserWouldUpgradeInsecureRequests;
/**
* If true, the content of the channel is queued up and checked
* if it matches a content signature. Note, setting this flag

View File

@ -48,6 +48,7 @@ struct LoadInfoArgs
uint32_t tainting;
bool upgradeInsecureRequests;
bool browserUpgradeInsecureRequests;
bool browserWouldUpgradeInsecureRequests;
bool verifySignedContent;
bool enforceSRI;
bool allowDocumentToBeAgnosticToCSP;

View File

@ -7265,27 +7265,57 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st
kHttpsNetEarlyFail = 11,
kHttpsNetLateFail = 12
} chanDisposition = kHttpCanceled;
// HTTP_CHANNEL_DISPOSITION_UPGRADE TELEMETRY
Telemetry::LABELS_HTTP_CHANNEL_DISPOSITION_UPGRADE upgradeChanDisposition = Telemetry::LABELS_HTTP_CHANNEL_DISPOSITION_UPGRADE::cancel;
// HTTP 0.9 is more likely to be an error than really 0.9, so count it that way
if (mCanceled) {
chanDisposition = kHttpCanceled;
upgradeChanDisposition = Telemetry::LABELS_HTTP_CHANNEL_DISPOSITION_UPGRADE::cancel;
} else if (!mUsedNetwork ||
(mRaceCacheWithNetwork &&
mFirstResponseSource == RESPONSE_FROM_CACHE)) {
chanDisposition = kHttpDisk;
upgradeChanDisposition = Telemetry::LABELS_HTTP_CHANNEL_DISPOSITION_UPGRADE::disk;
} else if (NS_SUCCEEDED(status) &&
mResponseHead &&
mResponseHead->Version() != NS_HTTP_VERSION_0_9) {
chanDisposition = kHttpNetOK;
upgradeChanDisposition = Telemetry::LABELS_HTTP_CHANNEL_DISPOSITION_UPGRADE::netOk;
} else if (!mTransferSize) {
chanDisposition = kHttpNetEarlyFail;
upgradeChanDisposition = Telemetry::LABELS_HTTP_CHANNEL_DISPOSITION_UPGRADE::netEarlyFail;
} else {
chanDisposition = kHttpNetLateFail;
upgradeChanDisposition = Telemetry::LABELS_HTTP_CHANNEL_DISPOSITION_UPGRADE::netLateFail;
}
// Browser upgrading only happens on HTTPS pages for mixed passive content when upgrading is enabled.
nsCString upgradeKey;
if (IsHTTPS()) {
// Browser upgrading is disabled and the content is already HTTPS
upgradeKey = NS_LITERAL_CSTRING("disabledNoReason");
// Checks "security.mixed_content.upgrade_display_content" is true
if (nsMixedContentBlocker::ShouldUpgradeMixedDisplayContent()) {
if (mLoadInfo && mLoadInfo->GetBrowserUpgradeInsecureRequests()) {
// HTTP content the browser has upgraded to HTTPS
upgradeKey = NS_LITERAL_CSTRING("enabledUpgrade");
} else {
// Content wasn't upgraded but is already HTTPS
upgradeKey = NS_LITERAL_CSTRING("enabledNoReason");
}
}
// shift http to https disposition enums
chanDisposition = static_cast<ChannelDisposition>(chanDisposition + kHttpsCanceled);
} else if (mLoadInfo->GetBrowserWouldUpgradeInsecureRequests()) {
// HTTP content the browser would upgrade to HTTPS if upgrading was enabled
upgradeKey = NS_LITERAL_CSTRING("disabledUpgrade");
} else {
// HTTP content that wouldn't upgrade
upgradeKey = nsMixedContentBlocker::ShouldUpgradeMixedDisplayContent() ?
NS_LITERAL_CSTRING("enabledWont") :
NS_LITERAL_CSTRING("disabledWont");
}
Telemetry::AccumulateCategoricalKeyed(upgradeKey, upgradeChanDisposition);
LOG((" nsHttpChannel::OnStopRequest ChannelDisposition %d\n", chanDisposition));
Telemetry::Accumulate(Telemetry::HTTP_CHANNEL_DISPOSITION, chanDisposition);

View File

@ -2630,6 +2630,17 @@
"releaseChannelCollection": "opt-out",
"description": "Channel Disposition: 0=Cancel, 1=Disk, 2=NetOK, 3=NetEarlyFail, 4=NetlateFail, +8 for HTTPS"
},
"HTTP_CHANNEL_DISPOSITION_UPGRADE" : {
"record_in_processes": ["main"],
"alert_emails": ["necko@mozilla.com", "seceng-telemetry@mozilla.com", "jkt@mozilla.com"],
"bug_numbers": [1440701],
"expires_in_version": "70",
"kind": "categorical",
"keyed": true,
"releaseChannelCollection": "opt-out",
"description": "Upgrading display content Channel Disposition",
"labels": ["cancel", "disk", "netOk", "netEarlyFail", "netLateFail"]
},
"HTTP_CONNECTION_ENTRY_CACHE_HIT_1" : {
"record_in_processes": ["main", "content"],
"expires_in_version": "never",