2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-09-17 07:49:43 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "nsMixedContentBlocker.h"
|
|
|
|
|
2013-03-17 11:55:16 +04:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2015-07-10 19:14:42 +03:00
|
|
|
#include "nsCSPContext.h"
|
2013-03-17 11:55:16 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2012-09-17 07:49:43 +04:00
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsISecurityEventSink.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
#include "nsContentUtils.h"
|
2012-12-14 02:53:06 +04:00
|
|
|
#include "nsIRequest.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIHttpChannel.h"
|
2015-02-20 04:01:04 +03:00
|
|
|
#include "nsIParentChannel.h"
|
2012-09-17 07:49:43 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-12-14 02:53:06 +04:00
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
2013-01-30 12:04:31 +04:00
|
|
|
#include "nsISecureBrowserUI.h"
|
|
|
|
#include "nsIDocumentLoader.h"
|
2013-03-28 09:11:55 +04:00
|
|
|
#include "nsIWebNavigation.h"
|
2013-01-30 12:04:31 +04:00
|
|
|
#include "nsLoadGroup.h"
|
2013-04-23 05:08:18 +04:00
|
|
|
#include "nsIScriptError.h"
|
2014-10-19 00:21:06 +04:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIChannelEventSink.h"
|
2017-01-24 01:01:43 +03:00
|
|
|
#include "nsNetUtil.h"
|
2014-10-19 00:21:06 +04:00
|
|
|
#include "nsAsyncRedirectVerifyHelper.h"
|
|
|
|
#include "mozilla/LoadInfo.h"
|
2015-09-09 22:14:27 +03:00
|
|
|
#include "nsISiteSecurityService.h"
|
2017-01-24 01:01:43 +03:00
|
|
|
#include "prnetdb.h"
|
2012-09-17 07:49:43 +04:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2015-09-09 22:14:27 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
|
2012-09-17 07:49:43 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-08-26 19:27:00 +04:00
|
|
|
enum nsMixedContentBlockerMessageType {
|
|
|
|
eBlocked = 0x00,
|
|
|
|
eUserOverride = 0x01
|
|
|
|
};
|
|
|
|
|
2012-09-17 07:49:43 +04:00
|
|
|
// Is mixed script blocking (fonts, plugin content, scripts, stylesheets,
|
|
|
|
// iframes, websockets, XHR) enabled?
|
|
|
|
bool nsMixedContentBlocker::sBlockMixedScript = false;
|
|
|
|
|
|
|
|
// Is mixed display content blocking (images, audio, video, <a ping>) enabled?
|
|
|
|
bool nsMixedContentBlocker::sBlockMixedDisplay = false;
|
|
|
|
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
// Do we move HSTS before mixed-content
|
|
|
|
bool nsMixedContentBlocker::sUseHSTS = false;
|
|
|
|
// Do we send an HSTS priming request
|
|
|
|
bool nsMixedContentBlocker::sSendHSTSPriming = false;
|
2016-11-10 08:30:00 +03:00
|
|
|
// Default HSTS Priming failure timeout to 7 days, in seconds
|
2017-02-16 04:48:59 +03:00
|
|
|
uint32_t nsMixedContentBlocker::sHSTSPrimingCacheTimeout = (60 * 60 * 24 * 7);
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
|
2017-01-24 01:01:43 +03:00
|
|
|
bool
|
|
|
|
IsEligibleForHSTSPriming(nsIURI* aContentLocation) {
|
|
|
|
bool isHttpScheme = false;
|
|
|
|
nsresult rv = aContentLocation->SchemeIs("http", &isHttpScheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
if (!isHttpScheme) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t port = -1;
|
|
|
|
rv = aContentLocation->GetPort(&port);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
int32_t defaultPort = NS_GetDefaultPort("https");
|
|
|
|
|
|
|
|
if (port != -1 && port != defaultPort) {
|
|
|
|
// HSTS priming requests are only sent if the port is the default port
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString hostname;
|
|
|
|
rv = aContentLocation->GetHost(hostname);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
PRNetAddr hostAddr;
|
|
|
|
return (PR_StringToNetAddr(hostname.get(), &hostAddr) != PR_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2017-05-10 01:36:07 +03:00
|
|
|
enum MixedContentHSTSState {
|
|
|
|
MCB_HSTS_PASSIVE_NO_HSTS = 0,
|
|
|
|
MCB_HSTS_PASSIVE_WITH_HSTS = 1,
|
|
|
|
MCB_HSTS_ACTIVE_NO_HSTS = 2,
|
|
|
|
MCB_HSTS_ACTIVE_WITH_HSTS = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
// Similar to the existing mixed-content HSTS, except MCB_HSTS_*_NO_HSTS is
|
|
|
|
// broken into two distinct states, indicating whether we plan to send a priming
|
|
|
|
// request or not. If we decided not go send a priming request, it could be
|
|
|
|
// because it is a type we do not support, or because we cached a previous
|
|
|
|
// negative response.
|
|
|
|
enum MixedContentHSTSPrimingState {
|
|
|
|
eMCB_HSTS_PASSIVE_WITH_HSTS = 0,
|
|
|
|
eMCB_HSTS_ACTIVE_WITH_HSTS = 1,
|
|
|
|
eMCB_HSTS_PASSIVE_NO_PRIMING = 2,
|
|
|
|
eMCB_HSTS_PASSIVE_DO_PRIMING = 3,
|
|
|
|
eMCB_HSTS_ACTIVE_NO_PRIMING = 4,
|
|
|
|
eMCB_HSTS_ACTIVE_DO_PRIMING = 5,
|
|
|
|
eMCB_HSTS_PASSIVE_UPGRADE = 6,
|
|
|
|
eMCB_HSTS_ACTIVE_UPGRADE = 7,
|
|
|
|
};
|
|
|
|
|
2012-09-17 07:49:43 +04:00
|
|
|
// Fired at the document that attempted to load mixed content. The UI could
|
|
|
|
// handle this event, for example, by displaying an info bar that offers the
|
|
|
|
// choice to reload the page with mixed content permitted.
|
2016-04-26 03:23:21 +03:00
|
|
|
class nsMixedContentEvent : public Runnable
|
2012-09-17 07:49:43 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
nsMixedContentEvent(nsISupports* aContext,
|
|
|
|
MixedContentTypes aType,
|
|
|
|
bool aRootHasSecureConnection)
|
|
|
|
: mozilla::Runnable("nsMixedContentEvent")
|
|
|
|
, mContext(aContext)
|
|
|
|
, mType(aType)
|
|
|
|
, mRootHasSecureConnection(aRootHasSecureConnection)
|
2012-09-17 07:49:43 +04:00
|
|
|
{}
|
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override
|
2012-09-17 07:49:43 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mContext,
|
|
|
|
"You can't call this runnable without a requesting context");
|
|
|
|
|
|
|
|
// To update the security UI in the tab with the blocked mixed content, call
|
|
|
|
// nsISecurityEventSink::OnSecurityChange. You can get to the event sink by
|
|
|
|
// calling NS_CP_GetDocShellFromContext on the context, and QI'ing to
|
|
|
|
// nsISecurityEventSink.
|
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
|
|
|
|
// Mixed content was allowed and is about to load; get the document and
|
|
|
|
// set the approriate flag to true if we are about to load Mixed Active
|
|
|
|
// Content.
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = NS_CP_GetDocShellFromContext(mContext);
|
2013-02-13 02:02:51 +04:00
|
|
|
if (!docShell) {
|
2012-12-14 02:53:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
|
2013-02-13 02:02:51 +04:00
|
|
|
docShell->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
|
2012-12-14 02:53:06 +04:00
|
|
|
NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!");
|
|
|
|
|
|
|
|
// now get the document from sameTypeRoot
|
2016-04-12 10:40:36 +03:00
|
|
|
nsCOMPtr<nsIDocument> rootDoc = sameTypeRoot->GetDocument();
|
2012-12-14 02:53:06 +04:00
|
|
|
NS_ASSERTION(rootDoc, "No root document from document shell root tree item.");
|
|
|
|
|
2015-08-14 03:13:43 +03:00
|
|
|
// Get eventSink and the current security state from the docShell
|
|
|
|
nsCOMPtr<nsISecurityEventSink> eventSink = do_QueryInterface(docShell);
|
|
|
|
NS_ASSERTION(eventSink, "No eventSink from docShell.");
|
|
|
|
nsCOMPtr<nsIDocShell> rootShell = do_GetInterface(sameTypeRoot);
|
|
|
|
NS_ASSERTION(rootShell, "No root docshell from document shell root tree item.");
|
|
|
|
uint32_t state = nsIWebProgressListener::STATE_IS_BROKEN;
|
|
|
|
nsCOMPtr<nsISecureBrowserUI> securityUI;
|
|
|
|
rootShell->GetSecurityUI(getter_AddRefs(securityUI));
|
|
|
|
// If there is no securityUI, document doesn't have a security state to
|
|
|
|
// update. But we still want to set the document flags, so we don't return
|
|
|
|
// early.
|
2016-10-13 15:33:07 +03:00
|
|
|
nsresult stateRV = NS_ERROR_FAILURE;
|
2015-08-14 03:13:43 +03:00
|
|
|
if (securityUI) {
|
|
|
|
stateRV = securityUI->GetState(&state);
|
|
|
|
}
|
2012-12-14 02:53:06 +04:00
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
if (mType == eMixedScript) {
|
2013-01-30 12:04:37 +04:00
|
|
|
// See if the pref will change here. If it will, only then do we need to call OnSecurityChange() to update the UI.
|
|
|
|
if (rootDoc->GetHasMixedActiveContentLoaded()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
rootDoc->SetHasMixedActiveContentLoaded(true);
|
2012-12-14 02:53:06 +04:00
|
|
|
|
2013-01-30 12:04:41 +04:00
|
|
|
// Update the security UI in the tab with the allowed mixed active content
|
2015-08-14 03:13:43 +03:00
|
|
|
if (securityUI) {
|
|
|
|
// Bug 1182551 - before changing the security state to broken, check
|
|
|
|
// that the root is actually secure.
|
|
|
|
if (mRootHasSecureConnection) {
|
2016-04-27 11:38:26 +03:00
|
|
|
// reset state security flag
|
|
|
|
state = state >> 4 << 4;
|
|
|
|
// set state security flag to broken, since there is mixed content
|
|
|
|
state |= nsIWebProgressListener::STATE_IS_BROKEN;
|
|
|
|
|
2015-08-14 03:13:43 +03:00
|
|
|
// If mixed display content is loaded, make sure to include that in the state.
|
|
|
|
if (rootDoc->GetHasMixedDisplayContentLoaded()) {
|
2016-04-27 11:38:26 +03:00
|
|
|
state |= nsIWebProgressListener::STATE_LOADED_MIXED_DISPLAY_CONTENT;
|
2015-08-14 03:13:43 +03:00
|
|
|
}
|
2016-04-27 11:38:26 +03:00
|
|
|
|
|
|
|
eventSink->OnSecurityChange(mContext,
|
|
|
|
(state | nsIWebProgressListener::STATE_LOADED_MIXED_ACTIVE_CONTENT));
|
2013-02-01 07:27:04 +04:00
|
|
|
} else {
|
2015-08-14 03:13:43 +03:00
|
|
|
// root not secure, mixed active content loaded in an https subframe
|
|
|
|
if (NS_SUCCEEDED(stateRV)) {
|
|
|
|
eventSink->OnSecurityChange(mContext, (state | nsIWebProgressListener::STATE_LOADED_MIXED_ACTIVE_CONTENT));
|
|
|
|
}
|
2013-02-01 07:27:04 +04:00
|
|
|
}
|
2012-12-14 02:53:06 +04:00
|
|
|
}
|
|
|
|
|
2013-01-30 12:04:41 +04:00
|
|
|
} else if (mType == eMixedDisplay) {
|
|
|
|
// See if the pref will change here. If it will, only then do we need to call OnSecurityChange() to update the UI.
|
|
|
|
if (rootDoc->GetHasMixedDisplayContentLoaded()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
rootDoc->SetHasMixedDisplayContentLoaded(true);
|
|
|
|
|
|
|
|
// Update the security UI in the tab with the allowed mixed display content.
|
2015-08-14 03:13:43 +03:00
|
|
|
if (securityUI) {
|
|
|
|
// Bug 1182551 - before changing the security state to broken, check
|
|
|
|
// that the root is actually secure.
|
|
|
|
if (mRootHasSecureConnection) {
|
2016-04-27 11:38:26 +03:00
|
|
|
// reset state security flag
|
|
|
|
state = state >> 4 << 4;
|
|
|
|
// set state security flag to broken, since there is mixed content
|
|
|
|
state |= nsIWebProgressListener::STATE_IS_BROKEN;
|
|
|
|
|
|
|
|
// If mixed active content is loaded, make sure to include that in the state.
|
2015-08-14 03:13:43 +03:00
|
|
|
if (rootDoc->GetHasMixedActiveContentLoaded()) {
|
2016-04-27 11:38:26 +03:00
|
|
|
state |= nsIWebProgressListener::STATE_LOADED_MIXED_ACTIVE_CONTENT;
|
2015-08-14 03:13:43 +03:00
|
|
|
}
|
2016-04-27 11:38:26 +03:00
|
|
|
|
|
|
|
eventSink->OnSecurityChange(mContext,
|
|
|
|
(state | nsIWebProgressListener::STATE_LOADED_MIXED_DISPLAY_CONTENT));
|
2013-02-01 07:27:04 +04:00
|
|
|
} else {
|
2015-08-14 03:13:43 +03:00
|
|
|
// root not secure, mixed display content loaded in an https subframe
|
|
|
|
if (NS_SUCCEEDED(stateRV)) {
|
|
|
|
eventSink->OnSecurityChange(mContext, (state | nsIWebProgressListener::STATE_LOADED_MIXED_DISPLAY_CONTENT));
|
|
|
|
}
|
2013-02-01 07:27:04 +04:00
|
|
|
}
|
2013-01-30 12:04:41 +04:00
|
|
|
}
|
2012-12-14 02:53:06 +04:00
|
|
|
}
|
|
|
|
|
2012-09-17 07:49:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
// The requesting context for the content load. Generally, a DOM node from
|
|
|
|
// the document that caused the load.
|
|
|
|
nsCOMPtr<nsISupports> mContext;
|
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
// The type of mixed content detected, e.g. active or display
|
|
|
|
const MixedContentTypes mType;
|
2015-08-14 03:13:43 +03:00
|
|
|
|
|
|
|
// Indicates whether the top level load is https or not.
|
|
|
|
bool mRootHasSecureConnection;
|
2012-09-17 07:49:43 +04:00
|
|
|
};
|
2012-12-14 02:53:06 +04:00
|
|
|
|
2012-09-17 07:49:43 +04:00
|
|
|
|
|
|
|
nsMixedContentBlocker::nsMixedContentBlocker()
|
|
|
|
{
|
|
|
|
// Cache the pref for mixed script blocking
|
|
|
|
Preferences::AddBoolVarCache(&sBlockMixedScript,
|
|
|
|
"security.mixed_content.block_active_content");
|
|
|
|
|
|
|
|
// Cache the pref for mixed display blocking
|
|
|
|
Preferences::AddBoolVarCache(&sBlockMixedDisplay,
|
|
|
|
"security.mixed_content.block_display_content");
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
|
|
|
|
// Cache the pref for HSTS
|
|
|
|
Preferences::AddBoolVarCache(&sUseHSTS,
|
|
|
|
"security.mixed_content.use_hsts");
|
|
|
|
|
|
|
|
// Cache the pref for sending HSTS priming
|
|
|
|
Preferences::AddBoolVarCache(&sSendHSTSPriming,
|
|
|
|
"security.mixed_content.send_hsts_priming");
|
2016-11-10 08:30:00 +03:00
|
|
|
|
|
|
|
// Cache the pref for HSTS priming failure cache time
|
|
|
|
Preferences::AddUintVarCache(&sHSTSPrimingCacheTimeout,
|
|
|
|
"security.mixed_content.hsts_priming_cache_timeout");
|
2012-09-17 07:49:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMixedContentBlocker::~nsMixedContentBlocker()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-19 00:21:06 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsMixedContentBlocker, nsIContentPolicy, nsIChannelEventSink)
|
2012-09-17 07:49:43 +04:00
|
|
|
|
2013-08-26 19:27:00 +04:00
|
|
|
static void
|
|
|
|
LogMixedContentMessage(MixedContentTypes aClassification,
|
|
|
|
nsIURI* aContentLocation,
|
|
|
|
nsIDocument* aRootDoc,
|
|
|
|
nsMixedContentBlockerMessageType aMessageType)
|
2013-04-23 05:08:18 +04:00
|
|
|
{
|
2013-08-26 19:27:00 +04:00
|
|
|
nsAutoCString messageCategory;
|
|
|
|
uint32_t severityFlag;
|
|
|
|
nsAutoCString messageLookupKey;
|
|
|
|
|
|
|
|
if (aMessageType == eBlocked) {
|
|
|
|
severityFlag = nsIScriptError::errorFlag;
|
|
|
|
messageCategory.AssignLiteral("Mixed Content Blocker");
|
|
|
|
if (aClassification == eMixedDisplay) {
|
|
|
|
messageLookupKey.AssignLiteral("BlockMixedDisplayContent");
|
|
|
|
} else {
|
|
|
|
messageLookupKey.AssignLiteral("BlockMixedActiveContent");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
severityFlag = nsIScriptError::warningFlag;
|
|
|
|
messageCategory.AssignLiteral("Mixed Content Message");
|
|
|
|
if (aClassification == eMixedDisplay) {
|
2014-12-30 17:09:33 +03:00
|
|
|
messageLookupKey.AssignLiteral("LoadingMixedDisplayContent2");
|
2013-08-26 19:27:00 +04:00
|
|
|
} else {
|
2014-12-30 17:09:33 +03:00
|
|
|
messageLookupKey.AssignLiteral("LoadingMixedActiveContent2");
|
2013-08-26 19:27:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:02:31 +03:00
|
|
|
NS_ConvertUTF8toUTF16 locationSpecUTF16(aContentLocation->GetSpecOrDefault());
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* strings[] = { locationSpecUTF16.get() };
|
2013-08-26 19:27:00 +04:00
|
|
|
nsContentUtils::ReportToConsole(severityFlag, messageCategory, aRootDoc,
|
2013-04-23 05:08:18 +04:00
|
|
|
nsContentUtils::eSECURITY_PROPERTIES,
|
2013-08-26 19:27:00 +04:00
|
|
|
messageLookupKey.get(), strings, ArrayLength(strings));
|
2013-04-23 05:08:18 +04:00
|
|
|
}
|
|
|
|
|
2014-10-19 00:21:06 +04:00
|
|
|
/* nsIChannelEventSink implementation
|
|
|
|
* This code is called when a request is redirected.
|
|
|
|
* We check the channel associated with the new uri is allowed to load
|
|
|
|
* in the current context
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMixedContentBlocker::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
|
|
|
|
nsIChannel* aNewChannel,
|
|
|
|
uint32_t aFlags,
|
|
|
|
nsIAsyncVerifyRedirectCallback* aCallback)
|
|
|
|
{
|
|
|
|
nsAsyncRedirectAutoCallback autoCallback(aCallback);
|
|
|
|
|
|
|
|
if (!aOldChannel) {
|
|
|
|
NS_ERROR("No channel when evaluating mixed content!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:01:04 +03:00
|
|
|
// If we are in the parent process in e10s, we don't have access to the
|
|
|
|
// document node, and hence ShouldLoad will fail when we try to get
|
|
|
|
// the docShell. If that's the case, ignore mixed content checks
|
|
|
|
// on redirects in the parent. Let the child check for mixed content.
|
|
|
|
nsCOMPtr<nsIParentChannel> is_ipc_channel;
|
|
|
|
NS_QueryNotificationCallbacks(aNewChannel, is_ipc_channel);
|
|
|
|
if (is_ipc_channel) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-19 00:21:06 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> oldUri;
|
|
|
|
rv = aOldChannel->GetURI(getter_AddRefs(oldUri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> newUri;
|
|
|
|
rv = aNewChannel->GetURI(getter_AddRefs(newUri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Get the loading Info from the old channel
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
rv = aOldChannel->GetLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!loadInfo) {
|
|
|
|
// XXX: We want to have a loadInfo on all channels, but we don't yet.
|
|
|
|
// If an addon creates a channel, they may not set loadinfo. If that
|
|
|
|
// channel redirects from one page to another page, we would get caught
|
|
|
|
// in this code path. Hence, we have to return NS_OK. Once we have more
|
|
|
|
// confidence that all channels have loadinfo, we can change this to
|
|
|
|
// a failure. See bug 1077201.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-12 01:48:43 +03:00
|
|
|
nsContentPolicyType contentPolicyType = loadInfo->InternalContentPolicyType();
|
2014-10-19 00:21:06 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> requestingPrincipal = loadInfo->LoadingPrincipal();
|
|
|
|
|
|
|
|
// Since we are calling shouldLoad() directly on redirects, we don't go through the code
|
|
|
|
// in nsContentPolicyUtils::NS_CheckContentLoadPolicy(). Hence, we have to
|
|
|
|
// duplicate parts of it here.
|
|
|
|
nsCOMPtr<nsIURI> requestingLocation;
|
|
|
|
if (requestingPrincipal) {
|
|
|
|
// We check to see if the loadingPrincipal is systemPrincipal and return
|
|
|
|
// early if it is
|
|
|
|
if (nsContentUtils::IsSystemPrincipal(requestingPrincipal)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// We set the requestingLocation from the RequestingPrincipal.
|
|
|
|
rv = requestingPrincipal->GetURI(getter_AddRefs(requestingLocation));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
nsCOMPtr<nsISupports> requestingContext = loadInfo->LoadingNode();
|
|
|
|
|
2014-10-19 00:21:06 +04:00
|
|
|
int16_t decision = REJECT_REQUEST;
|
2016-01-19 20:10:50 +03:00
|
|
|
rv = ShouldLoad(contentPolicyType,
|
2014-10-19 00:21:06 +04:00
|
|
|
newUri,
|
|
|
|
requestingLocation,
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
requestingContext,
|
2014-10-19 00:21:06 +04:00
|
|
|
EmptyCString(), // aMimeGuess
|
|
|
|
nullptr, // aExtra
|
|
|
|
requestingPrincipal,
|
|
|
|
&decision);
|
2017-10-02 10:11:57 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
autoCallback.DontCallback();
|
|
|
|
aOldChannel->Cancel(NS_ERROR_DOM_BAD_URI);
|
|
|
|
return NS_BINDING_FAILED;
|
|
|
|
}
|
2014-10-19 00:21:06 +04:00
|
|
|
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
if (nsMixedContentBlocker::sSendHSTSPriming) {
|
|
|
|
// The LoadInfo passed in is for the original channel, HSTS priming needs to
|
|
|
|
// be set on the new channel, if required. If the redirect changes
|
|
|
|
// http->https, or vice-versa, the need for priming may change.
|
|
|
|
nsCOMPtr<nsILoadInfo> newLoadInfo;
|
|
|
|
rv = aNewChannel->GetLoadInfo(getter_AddRefs(newLoadInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-02-07 06:49:34 +03:00
|
|
|
if (newLoadInfo) {
|
|
|
|
rv = nsMixedContentBlocker::MarkLoadInfoForPriming(newUri,
|
|
|
|
requestingContext,
|
|
|
|
newLoadInfo);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
decision = REJECT_REQUEST;
|
|
|
|
newLoadInfo->ClearHSTSPriming();
|
|
|
|
}
|
|
|
|
} else {
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
decision = REJECT_REQUEST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-19 00:21:06 +04:00
|
|
|
// If the channel is about to load mixed content, abort the channel
|
|
|
|
if (!NS_CP_ACCEPTED(decision)) {
|
|
|
|
autoCallback.DontCallback();
|
2017-10-02 10:11:57 +03:00
|
|
|
aOldChannel->Cancel(NS_ERROR_DOM_BAD_URI);
|
2014-10-19 00:21:06 +04:00
|
|
|
return NS_BINDING_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:18:48 +03:00
|
|
|
/* This version of ShouldLoad() is non-static and called by the Content Policy
|
|
|
|
* API and AsyncOnChannelRedirect(). See nsIContentPolicy::ShouldLoad()
|
|
|
|
* for detailed description of the parameters.
|
|
|
|
*/
|
2015-03-24 20:51:15 +03:00
|
|
|
NS_IMETHODIMP
|
2012-10-02 00:04:09 +04:00
|
|
|
nsMixedContentBlocker::ShouldLoad(uint32_t aContentType,
|
2012-09-17 07:49:43 +04:00
|
|
|
nsIURI* aContentLocation,
|
|
|
|
nsIURI* aRequestingLocation,
|
|
|
|
nsISupports* aRequestingContext,
|
|
|
|
const nsACString& aMimeGuess,
|
|
|
|
nsISupports* aExtra,
|
|
|
|
nsIPrincipal* aRequestPrincipal,
|
2012-10-02 00:04:09 +04:00
|
|
|
int16_t* aDecision)
|
2015-03-24 19:18:48 +03:00
|
|
|
{
|
|
|
|
// We pass in false as the first parameter to ShouldLoad(), because the
|
|
|
|
// callers of this method don't know whether the load went through cached
|
|
|
|
// image redirects. This is handled by direct callers of the static
|
|
|
|
// ShouldLoad.
|
2015-09-09 22:14:27 +03:00
|
|
|
nsresult rv = ShouldLoad(false, // aHadInsecureImageRedirect
|
2015-03-24 19:18:48 +03:00
|
|
|
aContentType,
|
|
|
|
aContentLocation,
|
|
|
|
aRequestingLocation,
|
|
|
|
aRequestingContext,
|
|
|
|
aMimeGuess,
|
|
|
|
aExtra,
|
|
|
|
aRequestPrincipal,
|
|
|
|
aDecision);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:50:00 +03:00
|
|
|
bool
|
|
|
|
nsMixedContentBlocker::IsPotentiallyTrustworthyLoopbackURL(nsIURI* aURL) {
|
|
|
|
nsAutoCString host;
|
|
|
|
nsresult rv = aURL->GetHost(host);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
// We could also allow 'localhost' (if we can guarantee that it resolves
|
|
|
|
// to a loopback address), but Chrome doesn't support it as of writing. For
|
|
|
|
// web compat, lets only allow what Chrome allows.
|
2017-09-06 11:13:45 +03:00
|
|
|
return host.EqualsLiteral("127.0.0.1") || host.EqualsLiteral("::1");
|
2017-05-10 20:50:00 +03:00
|
|
|
}
|
|
|
|
|
2015-03-24 19:18:48 +03:00
|
|
|
/* Static version of ShouldLoad() that contains all the Mixed Content Blocker
|
|
|
|
* logic. Called from non-static ShouldLoad().
|
|
|
|
*/
|
2015-03-24 20:51:15 +03:00
|
|
|
nsresult
|
2015-03-24 19:18:48 +03:00
|
|
|
nsMixedContentBlocker::ShouldLoad(bool aHadInsecureImageRedirect,
|
|
|
|
uint32_t aContentType,
|
|
|
|
nsIURI* aContentLocation,
|
|
|
|
nsIURI* aRequestingLocation,
|
|
|
|
nsISupports* aRequestingContext,
|
|
|
|
const nsACString& aMimeGuess,
|
|
|
|
nsISupports* aExtra,
|
|
|
|
nsIPrincipal* aRequestPrincipal,
|
|
|
|
int16_t* aDecision)
|
2012-09-17 07:49:43 +04:00
|
|
|
{
|
2012-12-14 02:53:06 +04:00
|
|
|
// Asserting that we are on the main thread here and hence do not have to lock
|
|
|
|
// and unlock sBlockMixedScript and sBlockMixedDisplay before reading/writing
|
|
|
|
// to them.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-01-19 20:10:50 +03:00
|
|
|
bool isPreload = nsContentUtils::IsPreloadType(aContentType);
|
2016-01-14 23:38:15 +03:00
|
|
|
|
2015-09-12 01:48:43 +03:00
|
|
|
// The content policy type that we receive may be an internal type for
|
|
|
|
// scripts. Let's remember if we have seen a worker type, and reset it to the
|
|
|
|
// external type in all cases right now.
|
|
|
|
bool isWorkerType = aContentType == nsIContentPolicy::TYPE_INTERNAL_WORKER ||
|
|
|
|
aContentType == nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER ||
|
|
|
|
aContentType == nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER;
|
|
|
|
aContentType = nsContentUtils::InternalContentPolicyTypeToExternal(aContentType);
|
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
// Assume active (high risk) content and blocked by default
|
|
|
|
MixedContentTypes classification = eMixedScript;
|
2014-08-29 23:57:08 +04:00
|
|
|
// Make decision to block/reject by default
|
|
|
|
*aDecision = REJECT_REQUEST;
|
2012-12-14 02:53:06 +04:00
|
|
|
|
|
|
|
// Notes on non-obvious decisions:
|
|
|
|
//
|
|
|
|
// TYPE_DTD: A DTD can contain entity definitions that expand to scripts.
|
|
|
|
//
|
|
|
|
// TYPE_FONT: The TrueType hinting mechanism is basically a scripting
|
|
|
|
// language that gets interpreted by the operating system's font rasterizer.
|
|
|
|
// Mixed content web fonts are relatively uncommon, and we can can fall back
|
|
|
|
// to built-in fonts with minimal disruption in almost all cases.
|
|
|
|
//
|
|
|
|
// TYPE_OBJECT_SUBREQUEST could actually be either active content (e.g. a
|
|
|
|
// script that a plugin will execute) or display content (e.g. Flash video
|
2013-02-01 07:33:13 +04:00
|
|
|
// content). Until we have a way to determine active vs passive content
|
|
|
|
// from plugin requests (bug 836352), we will treat this as passive content.
|
|
|
|
// This is to prevent false positives from causing users to become
|
|
|
|
// desensitized to the mixed content blocker.
|
2012-12-14 02:53:06 +04:00
|
|
|
//
|
|
|
|
// TYPE_CSP_REPORT: High-risk because they directly leak information about
|
|
|
|
// the content of the page, and because blocking them does not have any
|
|
|
|
// negative effect on the page loading.
|
|
|
|
//
|
|
|
|
// TYPE_PING: Ping requests are POSTS, not GETs like images and media.
|
|
|
|
// Also, PING requests have no bearing on the rendering or operation of
|
|
|
|
// the page when used as designed, so even though they are lower risk than
|
|
|
|
// scripts, blocking them is basically risk-free as far as compatibility is
|
2015-08-04 01:25:21 +03:00
|
|
|
// concerned.
|
2012-12-14 02:53:06 +04:00
|
|
|
//
|
|
|
|
// TYPE_STYLESHEET: XSLT stylesheets can insert scripts. CSS positioning
|
|
|
|
// and other advanced CSS features can possibly be exploited to cause
|
|
|
|
// spoofing attacks (e.g. make a "grant permission" button look like a
|
|
|
|
// "refuse permission" button).
|
|
|
|
//
|
2015-08-04 01:25:21 +03:00
|
|
|
// TYPE_BEACON: Beacon requests are similar to TYPE_PING, and are blocked by
|
|
|
|
// default.
|
2014-03-06 19:51:23 +04:00
|
|
|
//
|
2012-12-14 02:53:06 +04:00
|
|
|
// TYPE_WEBSOCKET: The Websockets API requires browsers to
|
|
|
|
// reject mixed-content websockets: "If secure is false but the origin of
|
|
|
|
// the entry script has a scheme component that is itself a secure protocol,
|
|
|
|
// e.g. HTTPS, then throw a SecurityError exception." We already block mixed
|
|
|
|
// content websockets within the websockets implementation, so we don't need
|
|
|
|
// to do any blocking here, nor do we need to provide a way to undo or
|
|
|
|
// override the blocking. Websockets without TLS are very flaky anyway in the
|
2016-03-20 07:28:19 +03:00
|
|
|
// face of many HTTP-aware proxies. Compared to passive content, there is
|
2012-12-14 02:53:06 +04:00
|
|
|
// additional risk that the script using WebSockets will disclose sensitive
|
|
|
|
// information from the HTTPS page and/or eval (directly or indirectly)
|
|
|
|
// received data.
|
|
|
|
//
|
|
|
|
// TYPE_XMLHTTPREQUEST: XHR requires either same origin or CORS, so most
|
|
|
|
// mixed-content XHR will already be blocked by that check. This will also
|
|
|
|
// block HTTPS-to-HTTP XHR with CORS. The same security concerns mentioned
|
|
|
|
// above for WebSockets apply to XHR, and XHR should have the same security
|
|
|
|
// properties as WebSockets w.r.t. mixed content. XHR's handling of redirects
|
|
|
|
// amplifies these concerns.
|
|
|
|
|
|
|
|
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(TYPE_DATAREQUEST == TYPE_XMLHTTPREQUEST,
|
|
|
|
"TYPE_DATAREQUEST is not a synonym for "
|
|
|
|
"TYPE_XMLHTTPREQUEST");
|
2012-09-17 07:49:43 +04:00
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
switch (aContentType) {
|
|
|
|
// The top-level document cannot be mixed content by definition
|
|
|
|
case TYPE_DOCUMENT:
|
|
|
|
*aDecision = ACCEPT;
|
|
|
|
return NS_OK;
|
|
|
|
// Creating insecure websocket connections in a secure page is blocked already
|
|
|
|
// in the websocket constructor. We don't need to check the blocking here
|
|
|
|
// and we don't want to un-block
|
|
|
|
case TYPE_WEBSOCKET:
|
|
|
|
*aDecision = ACCEPT;
|
|
|
|
return NS_OK;
|
2012-09-17 07:49:43 +04:00
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
// Static display content is considered moderate risk for mixed content so
|
|
|
|
// these will be blocked according to the mixed display preference
|
|
|
|
case TYPE_IMAGE:
|
|
|
|
case TYPE_MEDIA:
|
2013-02-01 07:33:13 +04:00
|
|
|
case TYPE_OBJECT_SUBREQUEST:
|
2012-12-14 02:53:06 +04:00
|
|
|
classification = eMixedDisplay;
|
|
|
|
break;
|
2012-09-17 07:49:43 +04:00
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
// Active content (or content with a low value/risk-of-blocking ratio)
|
|
|
|
// that has been explicitly evaluated; listed here for documentation
|
|
|
|
// purposes and to avoid the assertion and warning for the default case.
|
2015-08-04 01:25:21 +03:00
|
|
|
case TYPE_BEACON:
|
2012-12-14 02:53:06 +04:00
|
|
|
case TYPE_CSP_REPORT:
|
|
|
|
case TYPE_DTD:
|
2014-10-14 02:09:58 +04:00
|
|
|
case TYPE_FETCH:
|
2012-12-14 02:53:06 +04:00
|
|
|
case TYPE_FONT:
|
2015-08-04 01:25:21 +03:00
|
|
|
case TYPE_IMAGESET:
|
2012-12-14 02:53:06 +04:00
|
|
|
case TYPE_OBJECT:
|
|
|
|
case TYPE_SCRIPT:
|
|
|
|
case TYPE_STYLESHEET:
|
|
|
|
case TYPE_SUBDOCUMENT:
|
2015-08-04 01:25:21 +03:00
|
|
|
case TYPE_PING:
|
2015-06-02 22:42:19 +03:00
|
|
|
case TYPE_WEB_MANIFEST:
|
2012-12-14 02:53:06 +04:00
|
|
|
case TYPE_XBL:
|
|
|
|
case TYPE_XMLHTTPREQUEST:
|
2013-09-12 01:11:49 +04:00
|
|
|
case TYPE_XSLT:
|
2012-12-14 02:53:06 +04:00
|
|
|
case TYPE_OTHER:
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// This content policy works as a whitelist.
|
|
|
|
default:
|
2013-02-06 22:23:09 +04:00
|
|
|
MOZ_ASSERT(false, "Mixed content of unknown type");
|
2012-09-17 07:49:43 +04:00
|
|
|
}
|
|
|
|
|
2016-03-29 08:03:26 +03:00
|
|
|
// Make sure to get the URI the load started with. No need to check
|
|
|
|
// outer schemes because all the wrapping pseudo protocols inherit the
|
|
|
|
// security properties of the actual network request represented
|
|
|
|
// by the innerMost URL.
|
|
|
|
nsCOMPtr<nsIURI> innerContentLocation = NS_GetInnermostURI(aContentLocation);
|
|
|
|
if (!innerContentLocation) {
|
|
|
|
NS_ERROR("Can't get innerURI from aContentLocation");
|
|
|
|
*aDecision = REJECT_REQUEST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-17 00:40:07 +04:00
|
|
|
/* Get the scheme of the sub-document resource to be requested. If it is
|
|
|
|
* a safe to load in an https context then mixed content doesn't apply.
|
|
|
|
*
|
|
|
|
* Check Protocol Flags to determine if scheme is safe to load:
|
|
|
|
* URI_DOES_NOT_RETURN_DATA - e.g.
|
|
|
|
* "mailto"
|
|
|
|
* URI_IS_LOCAL_RESOURCE - e.g.
|
|
|
|
* "data",
|
|
|
|
* "resource",
|
|
|
|
* "moz-icon"
|
|
|
|
* URI_INHERITS_SECURITY_CONTEXT - e.g.
|
|
|
|
* "javascript"
|
|
|
|
* URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT - e.g.
|
|
|
|
* "https",
|
|
|
|
* "moz-safe-about"
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool schemeLocal = false;
|
|
|
|
bool schemeNoReturnData = false;
|
|
|
|
bool schemeInherits = false;
|
|
|
|
bool schemeSecure = false;
|
2016-03-29 08:03:26 +03:00
|
|
|
if (NS_FAILED(NS_URIChainHasFlags(innerContentLocation, nsIProtocolHandler::URI_IS_LOCAL_RESOURCE , &schemeLocal)) ||
|
|
|
|
NS_FAILED(NS_URIChainHasFlags(innerContentLocation, nsIProtocolHandler::URI_DOES_NOT_RETURN_DATA, &schemeNoReturnData)) ||
|
|
|
|
NS_FAILED(NS_URIChainHasFlags(innerContentLocation, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT, &schemeInherits)) ||
|
|
|
|
NS_FAILED(NS_URIChainHasFlags(innerContentLocation, nsIProtocolHandler::URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT, &schemeSecure))) {
|
2014-08-29 23:57:08 +04:00
|
|
|
*aDecision = REJECT_REQUEST;
|
2012-11-17 00:40:07 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2015-03-24 19:18:48 +03:00
|
|
|
// TYPE_IMAGE redirects are cached based on the original URI, not the final
|
|
|
|
// destination and hence cache hits for images may not have the correct
|
2016-03-29 08:03:26 +03:00
|
|
|
// innerContentLocation. Check if the cached hit went through an http redirect,
|
2015-03-24 19:18:48 +03:00
|
|
|
// and if it did, we can't treat this as a secure subresource.
|
|
|
|
if (!aHadInsecureImageRedirect &&
|
|
|
|
(schemeLocal || schemeNoReturnData || schemeInherits || schemeSecure)) {
|
2014-08-29 23:57:08 +04:00
|
|
|
*aDecision = ACCEPT;
|
2012-11-17 00:40:07 +04:00
|
|
|
return NS_OK;
|
2012-09-17 07:49:43 +04:00
|
|
|
}
|
|
|
|
|
2013-09-21 00:42:32 +04:00
|
|
|
// Since there are cases where aRequestingLocation and aRequestPrincipal are
|
|
|
|
// definitely not the owning document, we try to ignore them by extracting the
|
|
|
|
// requestingLocation in the following order:
|
|
|
|
// 1) from the aRequestingContext, either extracting
|
|
|
|
// a) the node's principal, or the
|
|
|
|
// b) script object's principal.
|
|
|
|
// 2) if aRequestingContext yields a principal but no location, we check
|
|
|
|
// if its the system principal. If it is, allow the load.
|
|
|
|
// 3) Special case handling for:
|
|
|
|
// a) speculative loads, where shouldLoad is called twice (bug 839235)
|
|
|
|
// and the first speculative load does not include a context.
|
|
|
|
// In this case we use aRequestingLocation to set requestingLocation.
|
|
|
|
// b) TYPE_CSP_REPORT which does not provide a context. In this case we
|
|
|
|
// use aRequestingLocation to set requestingLocation.
|
|
|
|
// c) content scripts from addon code that do not provide aRequestingContext
|
|
|
|
// or aRequestingLocation, but do provide aRequestPrincipal.
|
|
|
|
// If aRequestPrincipal is an expanded principal, we allow the load.
|
|
|
|
// 4) If we still end up not having a requestingLocation, we reject the load.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
// 1a) Try to get the principal if aRequestingContext is a node.
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aRequestingContext);
|
|
|
|
if (node) {
|
|
|
|
principal = node->NodePrincipal();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1b) Try using the window's script object principal if it's not a node.
|
|
|
|
if (!principal) {
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> scriptObjPrin = do_QueryInterface(aRequestingContext);
|
|
|
|
if (scriptObjPrin) {
|
|
|
|
principal = scriptObjPrin->GetPrincipal();
|
2012-12-14 02:53:06 +04:00
|
|
|
}
|
2013-09-21 00:42:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> requestingLocation;
|
|
|
|
if (principal) {
|
|
|
|
principal->GetURI(getter_AddRefs(requestingLocation));
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2) if aRequestingContext yields a principal but no location, we check if its a system principal.
|
|
|
|
if (principal && !requestingLocation) {
|
|
|
|
if (nsContentUtils::IsSystemPrincipal(principal)) {
|
|
|
|
*aDecision = ACCEPT;
|
|
|
|
return NS_OK;
|
2012-12-14 02:53:06 +04:00
|
|
|
}
|
2013-09-21 00:42:32 +04:00
|
|
|
}
|
2012-12-14 02:53:06 +04:00
|
|
|
|
2013-09-21 00:42:32 +04:00
|
|
|
// 3a,b) Special case handling for speculative loads and TYPE_CSP_REPORT. In
|
|
|
|
// such cases, aRequestingContext doesn't exist, so we use aRequestingLocation.
|
|
|
|
// Unfortunately we can not distinguish between speculative and normal loads here,
|
|
|
|
// otherwise we could special case this assignment.
|
|
|
|
if (!requestingLocation) {
|
|
|
|
requestingLocation = aRequestingLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3c) Special case handling for content scripts from addons code, which only
|
|
|
|
// provide a aRequestPrincipal; aRequestingContext and aRequestingLocation are
|
|
|
|
// both null; if the aRequestPrincipal is an expandedPrincipal, we allow the load.
|
|
|
|
if (!principal && !requestingLocation && aRequestPrincipal) {
|
|
|
|
nsCOMPtr<nsIExpandedPrincipal> expanded = do_QueryInterface(aRequestPrincipal);
|
|
|
|
if (expanded) {
|
|
|
|
*aDecision = ACCEPT;
|
|
|
|
return NS_OK;
|
2012-12-14 02:53:06 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-17 07:49:43 +04:00
|
|
|
|
2013-09-21 00:42:32 +04:00
|
|
|
// 4) Giving up. We still don't have a requesting location, therefore we can't tell
|
|
|
|
// if this is a mixed content load. Deny to be safe.
|
|
|
|
if (!requestingLocation) {
|
|
|
|
*aDecision = REJECT_REQUEST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
// Check the parent scheme. If it is not an HTTPS page then mixed content
|
|
|
|
// restrictions do not apply.
|
|
|
|
bool parentIsHttps;
|
2016-03-29 08:03:26 +03:00
|
|
|
nsCOMPtr<nsIURI> innerRequestingLocation = NS_GetInnermostURI(requestingLocation);
|
|
|
|
if (!innerRequestingLocation) {
|
2015-04-15 20:18:27 +03:00
|
|
|
NS_ERROR("Can't get innerURI from requestingLocation");
|
|
|
|
*aDecision = REJECT_REQUEST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-29 08:03:26 +03:00
|
|
|
nsresult rv = innerRequestingLocation->SchemeIs("https", &parentIsHttps);
|
2012-12-14 02:53:06 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-21 00:42:32 +04:00
|
|
|
NS_ERROR("requestingLocation->SchemeIs failed");
|
2012-12-14 02:53:06 +04:00
|
|
|
*aDecision = REJECT_REQUEST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (!parentIsHttps) {
|
|
|
|
*aDecision = ACCEPT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-09-17 07:49:43 +04:00
|
|
|
|
2016-01-14 07:58:16 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = NS_CP_GetDocShellFromContext(aRequestingContext);
|
|
|
|
NS_ENSURE_TRUE(docShell, NS_OK);
|
|
|
|
|
2015-09-12 01:48:43 +03:00
|
|
|
// Disallow mixed content loads for workers, shared workers and service
|
|
|
|
// workers.
|
|
|
|
if (isWorkerType) {
|
|
|
|
// For workers, we can assume that we're mixed content at this point, since
|
2016-03-29 08:03:26 +03:00
|
|
|
// the parent is https, and the protocol associated with innerContentLocation
|
2015-09-12 01:48:43 +03:00
|
|
|
// doesn't map to the secure URI flags checked above. Assert this for
|
|
|
|
// sanity's sake
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool isHttpsScheme = false;
|
2016-03-29 08:03:26 +03:00
|
|
|
rv = innerContentLocation->SchemeIs("https", &isHttpsScheme);
|
2015-09-12 01:48:43 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
MOZ_ASSERT(!isHttpsScheme);
|
|
|
|
#endif
|
|
|
|
*aDecision = REJECT_REQUEST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:50:00 +03:00
|
|
|
bool isHttpScheme = false;
|
|
|
|
rv = innerContentLocation->SchemeIs("http", &isHttpScheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Loopback origins are not considered mixed content even over HTTP. See:
|
|
|
|
// https://w3c.github.io/webappsec-mixed-content/#should-block-fetch
|
|
|
|
if (isHttpScheme &&
|
|
|
|
IsPotentiallyTrustworthyLoopbackURL(innerContentLocation)) {
|
|
|
|
*aDecision = ACCEPT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-10 19:14:42 +03:00
|
|
|
// The page might have set the CSP directive 'upgrade-insecure-requests'. In such
|
|
|
|
// a case allow the http: load to succeed with the promise that the channel will
|
|
|
|
// get upgraded to https before fetching any data from the netwerk.
|
|
|
|
// Please see: nsHttpChannel::Connect()
|
|
|
|
//
|
|
|
|
// Please note that the CSP directive 'upgrade-insecure-requests' only applies to
|
|
|
|
// http: and ws: (for websockets). Websockets are not subject to mixed content
|
|
|
|
// blocking since insecure websockets are not allowed within secure pages. Hence,
|
|
|
|
// we only have to check against http: here. Skip mixed content blocking if the
|
|
|
|
// subresource load uses http: and the CSP directive 'upgrade-insecure-requests'
|
|
|
|
// is present on the page.
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
nsIDocument* document = docShell->GetDocument();
|
|
|
|
MOZ_ASSERT(document, "Expected a document");
|
|
|
|
if (isHttpScheme && document->GetUpgradeInsecureRequests(isPreload)) {
|
2015-07-10 19:14:42 +03:00
|
|
|
*aDecision = ACCEPT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-21 20:35:45 +03:00
|
|
|
// The page might have set the CSP directive 'block-all-mixed-content' which
|
|
|
|
// should block not only active mixed content loads but in fact all mixed content
|
|
|
|
// loads, see https://www.w3.org/TR/mixed-content/#strict-checking
|
|
|
|
// Block all non secure loads in case the CSP directive is present. Please note
|
|
|
|
// that at this point we already know, based on |schemeSecure| that the load is
|
|
|
|
// not secure, so we can bail out early at this point.
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
if (document->GetBlockAllMixedContent(isPreload)) {
|
2016-05-21 20:35:45 +03:00
|
|
|
// log a message to the console before returning.
|
|
|
|
nsAutoCString spec;
|
|
|
|
rv = aContentLocation->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ConvertUTF8toUTF16 reportSpec(spec);
|
|
|
|
|
|
|
|
const char16_t* params[] = { reportSpec.get()};
|
2017-07-12 08:13:37 +03:00
|
|
|
CSP_LogLocalizedStr("blockAllMixedContent",
|
2016-05-21 20:35:45 +03:00
|
|
|
params, ArrayLength(params),
|
|
|
|
EmptyString(), // aSourceFile
|
|
|
|
EmptyString(), // aScriptSample
|
|
|
|
0, // aLineNumber
|
|
|
|
0, // aColumnNumber
|
|
|
|
nsIScriptError::errorFlag, "CSP",
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
document->InnerWindowID());
|
2016-05-21 20:35:45 +03:00
|
|
|
*aDecision = REJECT_REQUEST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 07:58:16 +03:00
|
|
|
// Determine if the rootDoc is https and if the user decided to allow Mixed Content
|
2013-01-30 12:04:31 +04:00
|
|
|
bool rootHasSecureConnection = false;
|
|
|
|
bool allowMixedContent = false;
|
2013-01-30 12:04:34 +04:00
|
|
|
bool isRootDocShell = false;
|
|
|
|
rv = docShell->GetAllowMixedContentAndConnectionData(&rootHasSecureConnection, &allowMixedContent, &isRootDocShell);
|
2013-01-30 12:04:31 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-08-29 23:57:08 +04:00
|
|
|
*aDecision = REJECT_REQUEST;
|
2015-03-24 19:18:48 +03:00
|
|
|
return rv;
|
2013-01-30 12:04:31 +04:00
|
|
|
}
|
|
|
|
|
2013-03-28 09:11:55 +04:00
|
|
|
// Get the sameTypeRoot tree item from the docshell
|
2013-01-30 12:04:31 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
|
2013-02-13 02:02:51 +04:00
|
|
|
docShell->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
|
2013-03-28 09:11:55 +04:00
|
|
|
NS_ASSERTION(sameTypeRoot, "No root tree item from docshell!");
|
|
|
|
|
|
|
|
// When navigating an iframe, the iframe may be https
|
|
|
|
// but its parents may not be. Check the parents to see if any of them are https.
|
|
|
|
// If none of the parents are https, allow the load.
|
|
|
|
if (aContentType == TYPE_SUBDOCUMENT && !rootHasSecureConnection) {
|
|
|
|
|
|
|
|
bool httpsParentExists = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentTreeItem;
|
|
|
|
parentTreeItem = docShell;
|
|
|
|
|
|
|
|
while(!httpsParentExists && parentTreeItem) {
|
|
|
|
nsCOMPtr<nsIWebNavigation> parentAsNav(do_QueryInterface(parentTreeItem));
|
|
|
|
NS_ASSERTION(parentAsNav, "No web navigation object from parent's docshell tree item");
|
|
|
|
nsCOMPtr<nsIURI> parentURI;
|
|
|
|
|
|
|
|
parentAsNav->GetCurrentURI(getter_AddRefs(parentURI));
|
2016-05-23 07:11:02 +03:00
|
|
|
if (!parentURI) {
|
|
|
|
// if getting the URI fails, assume there is a https parent and break.
|
|
|
|
httpsParentExists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> innerParentURI = NS_GetInnermostURI(parentURI);
|
|
|
|
if (!innerParentURI) {
|
|
|
|
NS_ERROR("Can't get innerURI from parentURI");
|
|
|
|
*aDecision = REJECT_REQUEST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(innerParentURI->SchemeIs("https", &httpsParentExists))) {
|
|
|
|
// if getting the scheme fails, assume there is a https parent and break.
|
2013-03-28 09:11:55 +04:00
|
|
|
httpsParentExists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the parent and the root are the same, we have traversed all the way up
|
|
|
|
// the same type docshell tree. Break out of the while loop.
|
|
|
|
if(sameTypeRoot == parentTreeItem) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the parent to the grandparent.
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> newParentTreeItem;
|
|
|
|
parentTreeItem->GetSameTypeParent(getter_AddRefs(newParentTreeItem));
|
|
|
|
parentTreeItem = newParentTreeItem;
|
|
|
|
} // end while loop.
|
|
|
|
|
|
|
|
if (!httpsParentExists) {
|
|
|
|
*aDecision = nsIContentPolicy::ACCEPT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the root document from the sameTypeRoot
|
2016-04-12 10:40:36 +03:00
|
|
|
nsCOMPtr<nsIDocument> rootDoc = sameTypeRoot->GetDocument();
|
2013-01-30 12:04:31 +04:00
|
|
|
NS_ASSERTION(rootDoc, "No root document from document shell root tree item.");
|
|
|
|
|
2013-01-30 12:04:41 +04:00
|
|
|
// Get eventSink and the current security state from the docShell
|
|
|
|
nsCOMPtr<nsISecurityEventSink> eventSink = do_QueryInterface(docShell);
|
|
|
|
NS_ASSERTION(eventSink, "No eventSink from docShell.");
|
|
|
|
nsCOMPtr<nsIDocShell> rootShell = do_GetInterface(sameTypeRoot);
|
|
|
|
NS_ASSERTION(rootShell, "No root docshell from document shell root tree item.");
|
2015-08-14 03:13:43 +03:00
|
|
|
uint32_t state = nsIWebProgressListener::STATE_IS_BROKEN;
|
2013-02-01 07:23:37 +04:00
|
|
|
nsCOMPtr<nsISecureBrowserUI> securityUI;
|
|
|
|
rootShell->GetSecurityUI(getter_AddRefs(securityUI));
|
|
|
|
// If there is no securityUI, document doesn't have a security state.
|
|
|
|
// Allow load and return early.
|
|
|
|
if (!securityUI) {
|
|
|
|
*aDecision = nsIContentPolicy::ACCEPT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-08-14 03:13:43 +03:00
|
|
|
nsresult stateRV = securityUI->GetState(&state);
|
2013-01-30 12:04:41 +04:00
|
|
|
|
2017-02-14 05:29:24 +03:00
|
|
|
OriginAttributes originAttributes;
|
|
|
|
if (principal) {
|
2017-03-08 09:41:51 +03:00
|
|
|
originAttributes = principal->OriginAttributesRef();
|
2017-02-14 05:29:24 +03:00
|
|
|
} else if (aRequestPrincipal) {
|
2017-03-08 09:41:51 +03:00
|
|
|
originAttributes = aRequestPrincipal->OriginAttributesRef();
|
2017-02-14 05:29:24 +03:00
|
|
|
}
|
|
|
|
|
2017-05-10 01:36:07 +03:00
|
|
|
bool active = (classification == eMixedScript);
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
bool doHSTSPriming = false;
|
2017-01-24 01:01:43 +03:00
|
|
|
if (IsEligibleForHSTSPriming(aContentLocation)) {
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
bool hsts = false;
|
|
|
|
bool cached = false;
|
|
|
|
nsCOMPtr<nsISiteSecurityService> sss =
|
|
|
|
do_GetService(NS_SSSERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = sss->IsSecureURI(nsISiteSecurityService::HEADER_HSTS, aContentLocation,
|
2017-05-24 01:31:37 +03:00
|
|
|
0, originAttributes, &cached, nullptr, &hsts);
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (hsts && sUseHSTS) {
|
|
|
|
// assume we will be upgraded later
|
2017-05-10 01:36:07 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS_PRIMING_2,
|
|
|
|
(active) ? MixedContentHSTSPrimingState::eMCB_HSTS_ACTIVE_UPGRADE
|
|
|
|
: MixedContentHSTSPrimingState::eMCB_HSTS_PASSIVE_UPGRADE);
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
*aDecision = ACCEPT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send a priming request if the result is not already cached and priming
|
|
|
|
// requests are allowed
|
|
|
|
if (!cached && sSendHSTSPriming) {
|
|
|
|
// add this URI as a priming location
|
|
|
|
doHSTSPriming = true;
|
|
|
|
document->AddHSTSPrimingLocation(innerContentLocation,
|
|
|
|
HSTSPrimingState::eHSTS_PRIMING_ALLOW);
|
|
|
|
*aDecision = ACCEPT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-09 22:14:27 +03:00
|
|
|
// At this point we know that the request is mixed content, and the only
|
|
|
|
// question is whether we block it. Record telemetry at this point as to
|
|
|
|
// whether HSTS would have fixed things by making the content location
|
|
|
|
// into an HTTPS URL.
|
|
|
|
//
|
|
|
|
// Note that we count this for redirects as well as primary requests. This
|
|
|
|
// will cause some degree of double-counting, especially when mixed content
|
|
|
|
// is not blocked (e.g., for images). For more detail, see:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1198572#c19
|
|
|
|
//
|
|
|
|
// We do not count requests aHadInsecureImageRedirect=true, since these are
|
|
|
|
// just an artifact of the image caching system.
|
|
|
|
if (!aHadInsecureImageRedirect) {
|
|
|
|
if (XRE_IsParentProcess()) {
|
2017-02-14 05:29:24 +03:00
|
|
|
AccumulateMixedContentHSTS(innerContentLocation, active, doHSTSPriming,
|
|
|
|
originAttributes);
|
2015-09-09 22:14:27 +03:00
|
|
|
} else {
|
|
|
|
// Ask the parent process to do the same call
|
|
|
|
mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
if (cc) {
|
|
|
|
mozilla::ipc::URIParams uri;
|
2016-03-29 08:03:26 +03:00
|
|
|
SerializeURI(innerContentLocation, uri);
|
2017-02-14 05:29:24 +03:00
|
|
|
cc->SendAccumulateMixedContentHSTS(uri, active, doHSTSPriming,
|
|
|
|
originAttributes);
|
2015-09-09 22:14:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-16 17:46:36 +03:00
|
|
|
// set hasMixedContentObjectSubrequest on this object if necessary
|
|
|
|
if (aContentType == TYPE_OBJECT_SUBREQUEST) {
|
|
|
|
rootDoc->SetHasMixedContentObjectSubrequest(true);
|
|
|
|
}
|
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
// If the content is display content, and the pref says display content should be blocked, block it.
|
2013-01-30 12:04:31 +04:00
|
|
|
if (sBlockMixedDisplay && classification == eMixedDisplay) {
|
2013-01-30 12:04:41 +04:00
|
|
|
if (allowMixedContent) {
|
2013-08-26 19:27:00 +04:00
|
|
|
LogMixedContentMessage(classification, aContentLocation, rootDoc, eUserOverride);
|
2013-01-30 12:04:41 +04:00
|
|
|
*aDecision = nsIContentPolicy::ACCEPT;
|
2015-03-25 21:23:42 +03:00
|
|
|
// See if mixed display content has already loaded on the page or if the state needs to be updated here.
|
|
|
|
// If mixed display hasn't loaded previously, then we need to call OnSecurityChange() to update the UI.
|
|
|
|
if (rootDoc->GetHasMixedDisplayContentLoaded()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
rootDoc->SetHasMixedDisplayContentLoaded(true);
|
|
|
|
|
|
|
|
if (rootHasSecureConnection) {
|
2016-04-27 11:38:26 +03:00
|
|
|
// reset state security flag
|
|
|
|
state = state >> 4 << 4;
|
|
|
|
// set state security flag to broken, since there is mixed content
|
|
|
|
state |= nsIWebProgressListener::STATE_IS_BROKEN;
|
|
|
|
|
|
|
|
// If mixed active content is loaded, make sure to include that in the state.
|
2015-03-25 21:23:42 +03:00
|
|
|
if (rootDoc->GetHasMixedActiveContentLoaded()) {
|
2016-04-27 11:38:26 +03:00
|
|
|
state |= nsIWebProgressListener::STATE_LOADED_MIXED_ACTIVE_CONTENT;
|
2015-03-25 21:23:42 +03:00
|
|
|
}
|
2016-04-27 11:38:26 +03:00
|
|
|
|
|
|
|
eventSink->OnSecurityChange(aRequestingContext,
|
|
|
|
(state | nsIWebProgressListener::STATE_LOADED_MIXED_DISPLAY_CONTENT));
|
2015-03-25 21:23:42 +03:00
|
|
|
} else {
|
|
|
|
// User has overriden the pref and the root is not https;
|
|
|
|
// mixed display content was allowed on an https subframe.
|
|
|
|
if (NS_SUCCEEDED(stateRV)) {
|
2015-08-14 03:13:43 +03:00
|
|
|
eventSink->OnSecurityChange(aRequestingContext, (state | nsIWebProgressListener::STATE_LOADED_MIXED_DISPLAY_CONTENT));
|
2016-04-27 11:38:26 +03:00
|
|
|
}
|
2013-01-30 12:04:41 +04:00
|
|
|
}
|
|
|
|
} else {
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
if (doHSTSPriming) {
|
|
|
|
document->AddHSTSPrimingLocation(innerContentLocation,
|
|
|
|
HSTSPrimingState::eHSTS_PRIMING_BLOCK);
|
|
|
|
*aDecision = nsIContentPolicy::ACCEPT;
|
|
|
|
} else {
|
|
|
|
*aDecision = nsIContentPolicy::REJECT_REQUEST;
|
|
|
|
}
|
2013-08-26 19:27:00 +04:00
|
|
|
LogMixedContentMessage(classification, aContentLocation, rootDoc, eBlocked);
|
2013-01-30 12:04:41 +04:00
|
|
|
if (!rootDoc->GetHasMixedDisplayContentBlocked() && NS_SUCCEEDED(stateRV)) {
|
2013-08-30 00:46:25 +04:00
|
|
|
rootDoc->SetHasMixedDisplayContentBlocked(true);
|
2015-08-14 03:13:43 +03:00
|
|
|
eventSink->OnSecurityChange(aRequestingContext, (state | nsIWebProgressListener::STATE_BLOCKED_MIXED_DISPLAY_CONTENT));
|
2013-01-30 12:04:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-01-30 12:04:31 +04:00
|
|
|
} else if (sBlockMixedScript && classification == eMixedScript) {
|
|
|
|
// If the content is active content, and the pref says active content should be blocked, block it
|
|
|
|
// unless the user has choosen to override the pref
|
|
|
|
if (allowMixedContent) {
|
2015-03-25 21:23:42 +03:00
|
|
|
LogMixedContentMessage(classification, aContentLocation, rootDoc, eUserOverride);
|
|
|
|
*aDecision = nsIContentPolicy::ACCEPT;
|
|
|
|
// See if the state will change here. If it will, only then do we need to call OnSecurityChange() to update the UI.
|
|
|
|
if (rootDoc->GetHasMixedActiveContentLoaded()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
rootDoc->SetHasMixedActiveContentLoaded(true);
|
2013-01-30 12:04:41 +04:00
|
|
|
|
2015-03-25 21:23:42 +03:00
|
|
|
if (rootHasSecureConnection) {
|
2016-04-27 11:38:26 +03:00
|
|
|
// reset state security flag
|
|
|
|
state = state >> 4 << 4;
|
|
|
|
// set state security flag to broken, since there is mixed content
|
|
|
|
state |= nsIWebProgressListener::STATE_IS_BROKEN;
|
|
|
|
|
|
|
|
// If mixed display content is loaded, make sure to include that in the state.
|
2015-03-25 21:23:42 +03:00
|
|
|
if (rootDoc->GetHasMixedDisplayContentLoaded()) {
|
2016-04-27 11:38:26 +03:00
|
|
|
state |= nsIWebProgressListener::STATE_LOADED_MIXED_DISPLAY_CONTENT;
|
2015-03-25 21:23:42 +03:00
|
|
|
}
|
2016-04-27 11:38:26 +03:00
|
|
|
|
|
|
|
eventSink->OnSecurityChange(aRequestingContext,
|
|
|
|
(state | nsIWebProgressListener::STATE_LOADED_MIXED_ACTIVE_CONTENT));
|
|
|
|
|
2015-03-25 21:23:42 +03:00
|
|
|
return NS_OK;
|
|
|
|
} else {
|
|
|
|
// User has already overriden the pref and the root is not https;
|
|
|
|
// mixed active content was allowed on an https subframe.
|
|
|
|
if (NS_SUCCEEDED(stateRV)) {
|
2015-08-14 03:13:43 +03:00
|
|
|
eventSink->OnSecurityChange(aRequestingContext, (state | nsIWebProgressListener::STATE_LOADED_MIXED_ACTIVE_CONTENT));
|
2015-03-25 21:23:42 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-30 12:04:31 +04:00
|
|
|
} else {
|
2015-03-25 21:23:42 +03:00
|
|
|
//User has not overriden the pref by Disabling protection. Reject the request and update the security state.
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
if (doHSTSPriming) {
|
|
|
|
document->AddHSTSPrimingLocation(innerContentLocation,
|
|
|
|
HSTSPrimingState::eHSTS_PRIMING_BLOCK);
|
|
|
|
*aDecision = nsIContentPolicy::ACCEPT;
|
|
|
|
} else {
|
|
|
|
*aDecision = nsIContentPolicy::REJECT_REQUEST;
|
|
|
|
}
|
2015-03-25 21:23:42 +03:00
|
|
|
LogMixedContentMessage(classification, aContentLocation, rootDoc, eBlocked);
|
|
|
|
// See if the pref will change here. If it will, only then do we need to call OnSecurityChange() to update the UI.
|
|
|
|
if (rootDoc->GetHasMixedActiveContentBlocked()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
rootDoc->SetHasMixedActiveContentBlocked(true);
|
2013-01-30 12:04:31 +04:00
|
|
|
|
2015-03-25 21:23:42 +03:00
|
|
|
// The user has not overriden the pref, so make sure they still have an option by calling eventSink
|
|
|
|
// which will invoke the doorhanger
|
|
|
|
if (NS_SUCCEEDED(stateRV)) {
|
2015-08-14 03:13:43 +03:00
|
|
|
eventSink->OnSecurityChange(aRequestingContext, (state | nsIWebProgressListener::STATE_BLOCKED_MIXED_ACTIVE_CONTENT));
|
2015-03-25 21:23:42 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2013-01-30 12:04:31 +04:00
|
|
|
}
|
2012-12-14 02:53:06 +04:00
|
|
|
} else {
|
|
|
|
// The content is not blocked by the mixed content prefs.
|
2012-09-17 07:49:43 +04:00
|
|
|
|
2013-08-26 19:27:00 +04:00
|
|
|
// Log a message that we are loading mixed content.
|
|
|
|
LogMixedContentMessage(classification, aContentLocation, rootDoc, eUserOverride);
|
|
|
|
|
2012-12-14 02:53:06 +04:00
|
|
|
// Fire the event from a script runner as it is unsafe to run script
|
|
|
|
// from within ShouldLoad
|
|
|
|
nsContentUtils::AddScriptRunner(
|
2015-08-14 03:13:43 +03:00
|
|
|
new nsMixedContentEvent(aRequestingContext, classification, rootHasSecureConnection));
|
2014-08-29 23:57:08 +04:00
|
|
|
*aDecision = ACCEPT;
|
2012-12-14 02:53:06 +04:00
|
|
|
return NS_OK;
|
2012-09-17 07:49:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-02 00:04:09 +04:00
|
|
|
nsMixedContentBlocker::ShouldProcess(uint32_t aContentType,
|
2012-09-17 07:49:43 +04:00
|
|
|
nsIURI* aContentLocation,
|
|
|
|
nsIURI* aRequestingLocation,
|
|
|
|
nsISupports* aRequestingContext,
|
|
|
|
const nsACString& aMimeGuess,
|
|
|
|
nsISupports* aExtra,
|
|
|
|
nsIPrincipal* aRequestPrincipal,
|
2012-10-02 00:04:09 +04:00
|
|
|
int16_t* aDecision)
|
2012-09-17 07:49:43 +04:00
|
|
|
{
|
2016-01-19 20:10:50 +03:00
|
|
|
aContentType = nsContentUtils::InternalContentPolicyTypeToExternal(aContentType);
|
2015-06-16 16:24:35 +03:00
|
|
|
|
2012-11-17 00:40:07 +04:00
|
|
|
if (!aContentLocation) {
|
2012-09-25 21:51:51 +04:00
|
|
|
// aContentLocation may be null when a plugin is loading without an associated URI resource
|
2012-11-17 00:40:07 +04:00
|
|
|
if (aContentType == TYPE_OBJECT) {
|
2014-08-29 23:57:08 +04:00
|
|
|
*aDecision = ACCEPT;
|
2012-09-25 21:51:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
} else {
|
2014-08-29 23:57:08 +04:00
|
|
|
*aDecision = REJECT_REQUEST;
|
2012-09-25 21:51:51 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-17 07:49:43 +04:00
|
|
|
return ShouldLoad(aContentType, aContentLocation, aRequestingLocation,
|
|
|
|
aRequestingContext, aMimeGuess, aExtra, aRequestPrincipal,
|
|
|
|
aDecision);
|
|
|
|
}
|
2015-09-09 22:14:27 +03:00
|
|
|
|
|
|
|
// Record information on when HSTS would have made mixed content not mixed
|
|
|
|
// content (regardless of whether it was actually blocked)
|
|
|
|
void
|
2017-02-14 05:29:24 +03:00
|
|
|
nsMixedContentBlocker::AccumulateMixedContentHSTS(
|
|
|
|
nsIURI* aURI, bool aActive, bool aHasHSTSPriming,
|
|
|
|
const OriginAttributes& aOriginAttributes)
|
2015-09-09 22:14:27 +03:00
|
|
|
{
|
|
|
|
// This method must only be called in the parent, because
|
|
|
|
// nsSiteSecurityService is only available in the parent
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hsts;
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISiteSecurityService> sss = do_GetService(NS_SSSERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-14 05:29:24 +03:00
|
|
|
rv = sss->IsSecureURI(nsISiteSecurityService::HEADER_HSTS, aURI, 0,
|
2017-05-24 01:31:37 +03:00
|
|
|
aOriginAttributes, nullptr, nullptr, &hsts);
|
2015-09-09 22:14:27 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
// states: would upgrade, would prime, hsts info cached
|
|
|
|
// active, passive
|
|
|
|
//
|
2015-09-09 22:14:27 +03:00
|
|
|
if (!aActive) {
|
|
|
|
if (!hsts) {
|
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS,
|
|
|
|
MCB_HSTS_PASSIVE_NO_HSTS);
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
if (aHasHSTSPriming) {
|
2017-05-10 01:36:07 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS_PRIMING_2,
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
eMCB_HSTS_PASSIVE_DO_PRIMING);
|
|
|
|
} else {
|
2017-05-10 01:36:07 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS_PRIMING_2,
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
eMCB_HSTS_PASSIVE_NO_PRIMING);
|
|
|
|
}
|
2015-09-09 22:14:27 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS,
|
|
|
|
MCB_HSTS_PASSIVE_WITH_HSTS);
|
2017-05-10 01:36:07 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS_PRIMING_2,
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
eMCB_HSTS_PASSIVE_WITH_HSTS);
|
2015-09-09 22:14:27 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!hsts) {
|
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS,
|
|
|
|
MCB_HSTS_ACTIVE_NO_HSTS);
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
if (aHasHSTSPriming) {
|
2017-05-10 01:36:07 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS_PRIMING_2,
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
eMCB_HSTS_ACTIVE_DO_PRIMING);
|
|
|
|
} else {
|
2017-05-10 01:36:07 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS_PRIMING_2,
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
eMCB_HSTS_ACTIVE_NO_PRIMING);
|
|
|
|
}
|
2015-09-09 22:14:27 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS,
|
|
|
|
MCB_HSTS_ACTIVE_WITH_HSTS);
|
2017-05-10 01:36:07 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::MIXED_CONTENT_HSTS_PRIMING_2,
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
eMCB_HSTS_ACTIVE_WITH_HSTS);
|
2015-09-09 22:14:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
|
|
|
|
//static
|
|
|
|
nsresult
|
|
|
|
nsMixedContentBlocker::MarkLoadInfoForPriming(nsIURI* aURI,
|
|
|
|
nsISupports* aRequestingContext,
|
|
|
|
nsILoadInfo* aLoadInfo)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
bool sendPriming = false;
|
|
|
|
bool mixedContentWouldBlock = false;
|
|
|
|
rv = GetHSTSPrimingFromRequestingContext(aURI,
|
|
|
|
aRequestingContext,
|
|
|
|
&sendPriming,
|
|
|
|
&mixedContentWouldBlock);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (sendPriming) {
|
|
|
|
aLoadInfo->SetHSTSPriming(mixedContentWouldBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
nsresult
|
|
|
|
nsMixedContentBlocker::GetHSTSPrimingFromRequestingContext(nsIURI* aURI,
|
|
|
|
nsISupports* aRequestingContext,
|
|
|
|
bool* aSendPrimingRequest,
|
|
|
|
bool* aMixedContentWouldBlock)
|
|
|
|
{
|
|
|
|
*aSendPrimingRequest = false;
|
|
|
|
*aMixedContentWouldBlock = false;
|
|
|
|
// If we marked for priming, we used the innermost URI, so get that
|
|
|
|
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI);
|
|
|
|
if (!innerURI) {
|
|
|
|
NS_ERROR("Can't get innerURI from aContentLocation");
|
|
|
|
return NS_ERROR_CONTENT_BLOCKED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isHttp = false;
|
|
|
|
innerURI->SchemeIs("http", &isHttp);
|
|
|
|
if (!isHttp) {
|
|
|
|
// there is nothign to do
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the DocShell was marked for HSTS priming, propagate that to the LoadInfo
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = NS_CP_GetDocShellFromContext(aRequestingContext);
|
|
|
|
if (!docShell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDocument> document = docShell->GetDocument();
|
|
|
|
if (!document) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HSTSPrimingState status = document->GetHSTSPrimingStateForLocation(innerURI);
|
|
|
|
if (status != HSTSPrimingState::eNO_HSTS_PRIMING) {
|
|
|
|
*aSendPrimingRequest = (status != HSTSPrimingState::eNO_HSTS_PRIMING);
|
|
|
|
*aMixedContentWouldBlock = (status == HSTSPrimingState::eHSTS_PRIMING_BLOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|