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-05-21 15:12:37 +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/. */
|
2010-01-23 00:38:21 +03:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2018-07-19 03:43:29 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_security.h"
|
2010-01-23 00:38:21 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsCSPService.h"
|
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2010-08-05 06:15:55 +04:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
|
|
|
#include "nsAsyncRedirectVerifyHelper.h"
|
2011-12-05 21:42:08 +04:00
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsContentUtils.h"
|
2014-10-16 06:12:53 +04:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2018-04-11 22:52:47 +03:00
|
|
|
#include "nsNetUtil.h"
|
2011-05-29 03:42:57 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2010-01-23 00:38:21 +03:00
|
|
|
|
2015-11-23 22:09:25 +03:00
|
|
|
static LazyLogModule gCspPRLog("CSP");
|
2010-01-23 00:38:21 +03:00
|
|
|
|
|
|
|
CSPService::CSPService() {}
|
|
|
|
|
|
|
|
CSPService::~CSPService() {}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(CSPService, nsIContentPolicy, nsIChannelEventSink)
|
2010-01-23 00:38:21 +03:00
|
|
|
|
2016-03-25 06:09:00 +03:00
|
|
|
// Helper function to identify protocols and content types not subject to CSP.
|
2019-05-01 11:47:10 +03:00
|
|
|
bool subjectToCSP(nsIURI* aURI, nsContentPolicyType aContentType) {
|
2018-03-01 15:45:04 +03:00
|
|
|
nsContentPolicyType contentType =
|
|
|
|
nsContentUtils::InternalContentPolicyTypeToExternal(aContentType);
|
|
|
|
|
2016-03-25 06:09:00 +03:00
|
|
|
// These content types are not subject to CSP content policy checks:
|
|
|
|
// TYPE_CSP_REPORT -- csp can't block csp reports
|
|
|
|
// TYPE_REFRESH -- never passed to ShouldLoad (see nsIContentPolicy.idl)
|
|
|
|
// TYPE_DOCUMENT -- used for frame-ancestors
|
2018-03-01 15:45:04 +03:00
|
|
|
if (contentType == nsIContentPolicy::TYPE_CSP_REPORT ||
|
|
|
|
contentType == nsIContentPolicy::TYPE_REFRESH ||
|
|
|
|
contentType == nsIContentPolicy::TYPE_DOCUMENT) {
|
2016-03-25 06:09:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-21 01:59:53 +03:00
|
|
|
// The three protocols: data:, blob: and filesystem: share the same
|
2018-01-25 16:20:31 +03:00
|
|
|
// protocol flag (URI_IS_LOCAL_RESOURCE) with other protocols,
|
|
|
|
// but those three protocols get special attention in CSP and
|
|
|
|
// are subject to CSP, hence we have to make sure those
|
|
|
|
// protocols are subject to CSP, see:
|
2014-11-21 01:59:53 +03:00
|
|
|
// http://www.w3.org/TR/CSP2/#source-list-guid-matching
|
2019-07-30 10:23:18 +03:00
|
|
|
if (aURI->SchemeIs("data") || aURI->SchemeIs("blob") ||
|
|
|
|
aURI->SchemeIs("filesystem")) {
|
2014-11-21 01:59:53 +03:00
|
|
|
return true;
|
|
|
|
}
|
2017-01-12 11:42:23 +03:00
|
|
|
|
|
|
|
// Finally we have to whitelist "about:" which does not fall into
|
|
|
|
// the category underneath and also "javascript:" which is not
|
|
|
|
// subject to CSP content loading rules.
|
2019-07-30 10:23:18 +03:00
|
|
|
if (aURI->SchemeIs("about") || aURI->SchemeIs("javascript")) {
|
2017-01-12 11:42:23 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-11-21 01:59:53 +03:00
|
|
|
|
|
|
|
// Please note that it should be possible for websites to
|
|
|
|
// whitelist their own protocol handlers with respect to CSP,
|
2018-01-25 16:20:31 +03:00
|
|
|
// hence we use protocol flags to accomplish that, but we also
|
|
|
|
// want resource:, chrome: and moz-icon to be subject to CSP
|
|
|
|
// (which also use URI_IS_LOCAL_RESOURCE).
|
2018-10-22 15:50:58 +03:00
|
|
|
// Exception to the rule are images, styles, localization DTDs,
|
|
|
|
// and XBLs using a scheme of resource: or chrome:
|
|
|
|
bool isImgOrStyleOrDTDorXBL =
|
|
|
|
contentType == nsIContentPolicy::TYPE_IMAGE ||
|
|
|
|
contentType == nsIContentPolicy::TYPE_STYLESHEET ||
|
|
|
|
contentType == nsIContentPolicy::TYPE_DTD ||
|
|
|
|
contentType == nsIContentPolicy::TYPE_XBL;
|
2019-07-30 10:23:18 +03:00
|
|
|
if (aURI->SchemeIs("resource") && !isImgOrStyleOrDTDorXBL) {
|
2018-01-25 16:20:31 +03:00
|
|
|
return true;
|
|
|
|
}
|
2019-07-30 10:23:18 +03:00
|
|
|
if (aURI->SchemeIs("chrome") && !isImgOrStyleOrDTDorXBL) {
|
2018-01-25 16:20:31 +03:00
|
|
|
return true;
|
|
|
|
}
|
2019-07-30 10:23:18 +03:00
|
|
|
if (aURI->SchemeIs("moz-icon")) {
|
2018-01-25 16:20:31 +03:00
|
|
|
return true;
|
|
|
|
}
|
2019-07-30 10:23:18 +03:00
|
|
|
bool match;
|
|
|
|
nsresult rv = NS_URIChainHasFlags(
|
|
|
|
aURI, nsIProtocolHandler::URI_IS_LOCAL_RESOURCE, &match);
|
2014-11-21 01:59:53 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && match) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// all other protocols are subject To CSP.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-03 09:04:25 +03:00
|
|
|
/* static */ nsresult CSPService::ConsultCSP(nsIURI* aContentLocation,
|
|
|
|
nsILoadInfo* aLoadInfo,
|
|
|
|
const nsACString& aMimeTypeGuess,
|
|
|
|
int16_t* aDecision) {
|
2014-11-21 01:59:53 +03:00
|
|
|
if (!aContentLocation) {
|
2013-09-12 20:25:32 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-11-21 01:59:53 +03:00
|
|
|
}
|
2010-01-23 00:38:21 +03:00
|
|
|
|
2018-05-30 22:21:17 +03:00
|
|
|
uint32_t contentType = aLoadInfo->InternalContentPolicyType();
|
|
|
|
nsCOMPtr<nsISupports> requestContext = aLoadInfo->GetLoadingContext();
|
2018-03-29 13:16:23 +03:00
|
|
|
|
2018-10-23 09:17:13 +03:00
|
|
|
nsCOMPtr<nsICSPEventListener> cspEventListener;
|
|
|
|
nsresult rv =
|
|
|
|
aLoadInfo->GetCspEventListener(getter_AddRefs(cspEventListener));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gCspPRLog, LogLevel::Debug)) {
|
|
|
|
MOZ_LOG(gCspPRLog, LogLevel::Debug,
|
2016-08-26 09:02:31 +03:00
|
|
|
("CSPService::ShouldLoad called for %s",
|
|
|
|
aContentLocation->GetSpecOrDefault().get()));
|
2013-09-12 20:25:32 +04:00
|
|
|
}
|
2012-12-15 02:53:29 +04:00
|
|
|
|
2013-09-12 20:25:32 +04:00
|
|
|
// default decision, CSP can revise it if there's a policy to enforce
|
|
|
|
*aDecision = nsIContentPolicy::ACCEPT;
|
|
|
|
|
2014-11-21 01:59:53 +03:00
|
|
|
// No need to continue processing if CSP is disabled or if the protocol
|
2016-03-25 06:09:00 +03:00
|
|
|
// or type is *not* subject to CSP.
|
2014-11-21 01:59:53 +03:00
|
|
|
// Please note, the correct way to opt-out of CSP using a custom
|
|
|
|
// protocolHandler is to set one of the nsIProtocolHandler flags
|
|
|
|
// that are whitelistet in subjectToCSP()
|
2018-07-19 03:43:29 +03:00
|
|
|
if (!StaticPrefs::security_csp_enable() ||
|
|
|
|
!subjectToCSP(aContentLocation, contentType)) {
|
2013-09-12 20:25:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-02-13 22:45:29 +03:00
|
|
|
nsAutoString cspNonce;
|
|
|
|
rv = aLoadInfo->GetCspNonce(cspNonce);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-11-15 06:29:18 +03:00
|
|
|
// 1) Apply speculate CSP for preloads
|
2018-05-30 22:21:17 +03:00
|
|
|
bool isPreload = nsContentUtils::IsPreloadType(contentType);
|
2015-11-15 06:29:18 +03:00
|
|
|
|
|
|
|
if (isPreload) {
|
2019-05-22 02:14:27 +03:00
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> preloadCsp = aLoadInfo->GetPreloadCsp();
|
2015-11-15 06:29:18 +03:00
|
|
|
if (preloadCsp) {
|
2013-09-12 20:25:32 +04:00
|
|
|
// obtain the enforcement decision
|
2018-05-30 22:21:17 +03:00
|
|
|
rv = preloadCsp->ShouldLoad(
|
2019-09-30 13:38:32 +03:00
|
|
|
contentType, cspEventListener, aContentLocation, requestContext,
|
|
|
|
aMimeTypeGuess,
|
2018-07-19 14:25:50 +03:00
|
|
|
nullptr, // no redirect, aOriginal URL is null.
|
2019-02-13 22:45:29 +03:00
|
|
|
aLoadInfo->GetSendCSPViolationEvents(), cspNonce, aDecision);
|
2015-11-15 06:29:18 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// if the preload policy already denied the load, then there
|
|
|
|
// is no point in checking the real policy
|
|
|
|
if (NS_CP_REJECTED(*aDecision)) {
|
2019-04-26 13:59:41 +03:00
|
|
|
NS_SetRequestBlockingReason(
|
|
|
|
aLoadInfo, nsILoadInfo::BLOCKING_REASON_CONTENT_POLICY_PRELOAD);
|
|
|
|
|
2015-11-15 06:29:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-01-23 00:38:21 +03:00
|
|
|
}
|
2013-09-12 20:25:32 +04:00
|
|
|
}
|
2010-04-23 21:03:03 +04:00
|
|
|
|
2019-05-22 02:14:27 +03:00
|
|
|
// 2) Apply actual CSP to all loads. Please note that in case
|
|
|
|
// the csp should be overruled (e.g. by an ExpandedPrincipal)
|
|
|
|
// then loadinfo->GetCSP() returns that CSP instead of the
|
|
|
|
// document's CSP.
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp = aLoadInfo->GetCsp();
|
2015-11-15 06:29:18 +03:00
|
|
|
|
|
|
|
if (csp) {
|
|
|
|
// obtain the enforcement decision
|
2018-05-30 22:21:17 +03:00
|
|
|
rv = csp->ShouldLoad(contentType, cspEventListener, aContentLocation,
|
2019-09-30 13:38:32 +03:00
|
|
|
requestContext, aMimeTypeGuess,
|
2018-07-19 14:25:50 +03:00
|
|
|
nullptr, // no redirect, aOriginal URL is null.
|
2019-02-13 22:45:29 +03:00
|
|
|
aLoadInfo->GetSendCSPViolationEvents(), cspNonce,
|
|
|
|
aDecision);
|
2019-04-26 13:59:41 +03:00
|
|
|
|
|
|
|
if (NS_CP_REJECTED(*aDecision)) {
|
|
|
|
NS_SetRequestBlockingReason(
|
|
|
|
aLoadInfo, nsILoadInfo::BLOCKING_REASON_CONTENT_POLICY_GENERAL);
|
|
|
|
}
|
|
|
|
|
2015-11-15 06:29:18 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2013-09-12 20:25:32 +04:00
|
|
|
return NS_OK;
|
2010-01-23 00:38:21 +03:00
|
|
|
}
|
|
|
|
|
2019-06-03 09:04:25 +03:00
|
|
|
/* nsIContentPolicy implementation */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSPService::ShouldLoad(nsIURI* aContentLocation, nsILoadInfo* aLoadInfo,
|
|
|
|
const nsACString& aMimeTypeGuess, int16_t* aDecision) {
|
|
|
|
return ConsultCSP(aContentLocation, aLoadInfo, aMimeTypeGuess, aDecision);
|
|
|
|
}
|
|
|
|
|
2010-01-23 00:38:21 +03:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
CSPService::ShouldProcess(nsIURI* aContentLocation, nsILoadInfo* aLoadInfo,
|
|
|
|
const nsACString& aMimeTypeGuess,
|
|
|
|
int16_t* aDecision) {
|
2014-08-05 22:47:08 +04:00
|
|
|
if (!aContentLocation) {
|
2013-09-12 20:25:32 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-08-05 22:47:08 +04:00
|
|
|
}
|
2018-05-30 22:21:17 +03:00
|
|
|
uint32_t contentType = aLoadInfo->InternalContentPolicyType();
|
2013-09-12 20:25:32 +04:00
|
|
|
|
2014-08-05 22:47:08 +04:00
|
|
|
if (MOZ_LOG_TEST(gCspPRLog, LogLevel::Debug)) {
|
|
|
|
MOZ_LOG(gCspPRLog, LogLevel::Debug,
|
2016-08-26 09:02:31 +03:00
|
|
|
("CSPService::ShouldProcess called for %s",
|
|
|
|
aContentLocation->GetSpecOrDefault().get()));
|
2014-08-05 22:47:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ShouldProcess is only relevant to TYPE_OBJECT, so let's convert the
|
|
|
|
// internal contentPolicyType to the mapping external one.
|
|
|
|
// If it is not TYPE_OBJECT, we can return at this point.
|
|
|
|
// Note that we should still pass the internal contentPolicyType
|
2018-05-30 22:21:17 +03:00
|
|
|
// (contentType) to ShouldLoad().
|
2014-08-05 22:47:08 +04:00
|
|
|
uint32_t policyType =
|
2018-05-30 22:21:17 +03:00
|
|
|
nsContentUtils::InternalContentPolicyTypeToExternal(contentType);
|
2014-08-05 22:47:08 +04:00
|
|
|
|
|
|
|
if (policyType != nsIContentPolicy::TYPE_OBJECT) {
|
|
|
|
*aDecision = nsIContentPolicy::ACCEPT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-29 13:16:23 +03:00
|
|
|
return ShouldLoad(aContentLocation, aLoadInfo, aMimeTypeGuess, aDecision);
|
2010-01-23 00:38:21 +03:00
|
|
|
}
|
2010-04-23 21:03:03 +04:00
|
|
|
|
|
|
|
/* nsIChannelEventSink implementation */
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
CSPService::AsyncOnChannelRedirect(nsIChannel* oldChannel,
|
|
|
|
nsIChannel* newChannel, uint32_t flags,
|
|
|
|
nsIAsyncVerifyRedirectCallback* callback) {
|
2016-05-19 05:02:57 +03:00
|
|
|
net::nsAsyncRedirectAutoCallback autoCallback(callback);
|
2010-08-05 06:15:55 +04:00
|
|
|
|
2019-05-22 02:14:27 +03:00
|
|
|
if (XRE_IsE10sParentProcess()) {
|
|
|
|
nsCOMPtr<nsIParentChannel> parentChannel;
|
|
|
|
NS_QueryNotificationCallbacks(oldChannel, parentChannel);
|
|
|
|
// Since this is an IPC'd channel we do not have access to the request
|
|
|
|
// context. In turn, we do not have an event target for policy violations.
|
|
|
|
// Enforce the CSP check in the content process where we have that info.
|
|
|
|
if (parentChannel) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 01:19:25 +03:00
|
|
|
nsCOMPtr<nsIURI> newUri;
|
|
|
|
nsresult rv = newChannel->GetURI(getter_AddRefs(newUri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2019-02-20 15:27:25 +03:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = oldChannel->LoadInfo();
|
2019-01-10 12:52:13 +03:00
|
|
|
|
2010-04-23 21:03:03 +04:00
|
|
|
/* Since redirecting channels don't call into nsIContentPolicy, we call our
|
2014-10-16 06:12:53 +04:00
|
|
|
* Content Policy implementation directly when redirects occur using the
|
|
|
|
* information set in the LoadInfo when channels are created.
|
|
|
|
*
|
|
|
|
* We check if the CSP permits this host for this type of load, if not,
|
|
|
|
* we cancel the load now.
|
2010-04-23 21:03:03 +04:00
|
|
|
*/
|
2012-07-10 11:44:05 +04:00
|
|
|
nsCOMPtr<nsIURI> originalUri;
|
2014-10-16 06:12:53 +04:00
|
|
|
rv = oldChannel->GetOriginalURI(getter_AddRefs(originalUri));
|
2017-02-14 18:06:38 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
autoCallback.DontCallback();
|
|
|
|
oldChannel->Cancel(NS_ERROR_DOM_BAD_URI);
|
|
|
|
return rv;
|
|
|
|
}
|
2015-11-15 06:29:18 +03:00
|
|
|
|
2019-09-25 11:25:22 +03:00
|
|
|
Maybe<nsresult> cancelCode;
|
|
|
|
rv = ConsultCSPForRedirect(originalUri, newUri, loadInfo, cancelCode);
|
|
|
|
if (cancelCode) {
|
|
|
|
oldChannel->Cancel(*cancelCode);
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
2019-08-06 10:41:42 +03:00
|
|
|
autoCallback.DontCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult CSPService::ConsultCSPForRedirect(nsIURI* aOriginalURI,
|
|
|
|
nsIURI* aNewURI,
|
|
|
|
nsILoadInfo* aLoadInfo,
|
2019-09-25 11:25:22 +03:00
|
|
|
Maybe<nsresult>& aCancelCode) {
|
2019-09-25 11:25:42 +03:00
|
|
|
// Check CSP navigate-to
|
|
|
|
// We need to enforce the CSP of the document that initiated the load,
|
|
|
|
// which is the CSP to inherit.
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> cspToInherit =
|
|
|
|
aLoadInfo->GetCspToInherit();
|
|
|
|
if (cspToInherit) {
|
|
|
|
bool allowsNavigateTo = false;
|
|
|
|
nsresult rv = cspToInherit->GetAllowsNavigateTo(
|
|
|
|
aNewURI, aLoadInfo, true, /* aWasRedirected */
|
|
|
|
false, /* aEnforceWhitelist */
|
|
|
|
&allowsNavigateTo);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!allowsNavigateTo) {
|
|
|
|
aCancelCode = Some(NS_ERROR_CSP_NAVIGATE_TO_VIOLATION);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No need to continue processing if CSP is disabled or if the protocol
|
|
|
|
// is *not* subject to CSP.
|
|
|
|
// Please note, the correct way to opt-out of CSP using a custom
|
|
|
|
// protocolHandler is to set one of the nsIProtocolHandler flags
|
|
|
|
// that are whitelistet in subjectToCSP()
|
|
|
|
nsContentPolicyType policyType = aLoadInfo->InternalContentPolicyType();
|
|
|
|
if (!StaticPrefs::security_csp_enable() ||
|
|
|
|
!subjectToCSP(aNewURI, policyType)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-08-06 10:41:42 +03:00
|
|
|
nsCOMPtr<nsICSPEventListener> cspEventListener;
|
|
|
|
nsresult rv =
|
|
|
|
aLoadInfo->GetCspEventListener(getter_AddRefs(cspEventListener));
|
2019-09-25 11:25:22 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(rv);
|
2019-08-06 10:41:42 +03:00
|
|
|
|
2019-02-13 22:45:29 +03:00
|
|
|
nsAutoString cspNonce;
|
2019-08-06 10:41:42 +03:00
|
|
|
rv = aLoadInfo->GetCspNonce(cspNonce);
|
2019-09-25 11:25:22 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(rv);
|
2019-02-13 22:45:29 +03:00
|
|
|
|
2015-11-15 06:29:18 +03:00
|
|
|
bool isPreload = nsContentUtils::IsPreloadType(policyType);
|
|
|
|
|
2015-10-29 02:32:27 +03:00
|
|
|
/* On redirect, if the content policy is a preload type, rejecting the preload
|
|
|
|
* results in the load silently failing, so we convert preloads to the actual
|
|
|
|
* type. See Bug 1219453.
|
|
|
|
*/
|
2015-11-15 06:29:18 +03:00
|
|
|
policyType =
|
|
|
|
nsContentUtils::InternalContentPolicyTypeToExternalOrWorker(policyType);
|
2014-10-16 06:12:53 +04:00
|
|
|
|
2019-09-25 11:25:22 +03:00
|
|
|
int16_t decision = nsIContentPolicy::ACCEPT;
|
2019-08-06 10:41:42 +03:00
|
|
|
nsCOMPtr<nsISupports> requestContext = aLoadInfo->GetLoadingContext();
|
2015-11-15 06:29:18 +03:00
|
|
|
// 1) Apply speculative CSP for preloads
|
|
|
|
if (isPreload) {
|
2019-08-06 10:41:42 +03:00
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> preloadCsp = aLoadInfo->GetPreloadCsp();
|
2015-11-15 06:29:18 +03:00
|
|
|
if (preloadCsp) {
|
2018-07-19 14:25:50 +03:00
|
|
|
// Pass originalURI to indicate the redirect
|
2015-11-15 06:29:18 +03:00
|
|
|
preloadCsp->ShouldLoad(
|
|
|
|
policyType, // load type per nsIContentPolicy (uint32_t)
|
2018-10-23 09:17:13 +03:00
|
|
|
cspEventListener,
|
2019-08-06 10:41:42 +03:00
|
|
|
aNewURI, // nsIURI
|
2018-06-22 20:35:14 +03:00
|
|
|
requestContext, // nsISupports
|
2015-11-15 06:29:18 +03:00
|
|
|
EmptyCString(), // ACString - MIME guess
|
2019-08-06 10:41:42 +03:00
|
|
|
aOriginalURI, // Original nsIURI
|
2018-08-01 07:35:24 +03:00
|
|
|
true, // aSendViolationReports
|
2019-02-13 22:45:29 +03:00
|
|
|
cspNonce, // nonce
|
2019-09-25 11:25:22 +03:00
|
|
|
&decision);
|
2015-11-15 06:29:18 +03:00
|
|
|
|
|
|
|
// if the preload policy already denied the load, then there
|
|
|
|
// is no point in checking the real policy
|
2019-09-25 11:25:22 +03:00
|
|
|
if (NS_CP_REJECTED(decision)) {
|
|
|
|
aCancelCode = Some(NS_ERROR_DOM_BAD_URI);
|
|
|
|
return NS_BINDING_FAILED;
|
2015-11-15 06:29:18 +03:00
|
|
|
}
|
|
|
|
}
|
2014-12-18 01:19:25 +03:00
|
|
|
}
|
2015-11-15 06:29:18 +03:00
|
|
|
|
|
|
|
// 2) Apply actual CSP to all loads
|
2019-08-06 10:41:42 +03:00
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp = aLoadInfo->GetCsp();
|
2015-11-15 06:29:18 +03:00
|
|
|
if (csp) {
|
2018-07-19 14:25:50 +03:00
|
|
|
// Pass originalURI to indicate the redirect
|
2015-11-15 06:29:18 +03:00
|
|
|
csp->ShouldLoad(policyType, // load type per nsIContentPolicy (uint32_t)
|
2018-10-23 09:17:13 +03:00
|
|
|
cspEventListener,
|
2019-08-06 10:41:42 +03:00
|
|
|
aNewURI, // nsIURI
|
2018-06-22 20:35:14 +03:00
|
|
|
requestContext, // nsISupports
|
2015-11-15 06:29:18 +03:00
|
|
|
EmptyCString(), // ACString - MIME guess
|
2019-08-06 10:41:42 +03:00
|
|
|
aOriginalURI, // Original nsIURI
|
2018-08-01 07:35:24 +03:00
|
|
|
true, // aSendViolationReports
|
2019-02-13 22:45:29 +03:00
|
|
|
cspNonce, // nonce
|
2019-09-25 11:25:22 +03:00
|
|
|
&decision);
|
|
|
|
if (NS_CP_REJECTED(decision)) {
|
|
|
|
aCancelCode = Some(NS_ERROR_DOM_BAD_URI);
|
|
|
|
return NS_BINDING_FAILED;
|
|
|
|
}
|
2014-12-18 01:19:25 +03:00
|
|
|
}
|
2010-04-23 21:03:03 +04:00
|
|
|
|
2014-10-16 06:12:53 +04:00
|
|
|
return NS_OK;
|
2010-04-23 21:03:03 +04:00
|
|
|
}
|