Bug 1225641 - Change default security flags within NetUtil.newChannel (r=sicking)

This commit is contained in:
Christoph Kerschbaumer 2015-11-17 17:35:30 -08:00
parent d71322c036
commit 053758c154
16 changed files with 65 additions and 33 deletions

View File

@ -1346,8 +1346,7 @@ nsContextMenu.prototype = {
// checks after redirects, see bug: 1136055 // checks after redirects, see bug: 1136055
var channel = NetUtil.newChannel({ var channel = NetUtil.newChannel({
uri: makeURI(linkURL), uri: makeURI(linkURL),
loadUsingSystemPrincipal: true, loadUsingSystemPrincipal: true
securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
}); });
if (linkDownload) if (linkDownload)

View File

@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsContentUtils.h"
#include "nsIconChannel.h" #include "nsIconChannel.h"
#include "mozilla/Endian.h" #include "mozilla/Endian.h"
#include "nsIIconURI.h" #include "nsIIconURI.h"
@ -225,8 +226,11 @@ NS_IMETHODIMP
nsIconChannel::AsyncOpen(nsIStreamListener* aListener, nsIconChannel::AsyncOpen(nsIStreamListener* aListener,
nsISupports* ctxt) nsISupports* ctxt)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetInitialSecurityCheckDone(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
nsCOMPtr<nsIInputStream> inStream; nsCOMPtr<nsIInputStream> inStream;

View File

@ -27,6 +27,7 @@
#include "nsDirectoryServiceDefs.h" #include "nsDirectoryServiceDefs.h"
#include "nsProxyRelease.h" #include "nsProxyRelease.h"
#include "nsContentSecurityManager.h" #include "nsContentSecurityManager.h"
#include "nsContentUtils.h"
#ifdef _WIN32_WINNT #ifdef _WIN32_WINNT
#undef _WIN32_WINNT #undef _WIN32_WINNT
@ -239,8 +240,11 @@ NS_IMETHODIMP
nsIconChannel::AsyncOpen(nsIStreamListener* aListener, nsIconChannel::AsyncOpen(nsIStreamListener* aListener,
nsISupports* ctxt) nsISupports* ctxt)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetInitialSecurityCheckDone(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
nsCOMPtr<nsIInputStream> inStream; nsCOMPtr<nsIInputStream> inStream;

View File

@ -937,8 +937,11 @@ nsJARChannel::OverrideWithSynthesizedResponse(nsIInputStream* aSynthesizedInput,
NS_IMETHODIMP NS_IMETHODIMP
nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx) nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetEnforceSecurity(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
LOG(("nsJARChannel::AsyncOpen [this=%x]\n", this)); LOG(("nsJARChannel::AsyncOpen [this=%x]\n", this));

View File

@ -356,7 +356,9 @@ this.NetUtil = {
} }
if (securityFlags === undefined) { if (securityFlags === undefined) {
securityFlags = Ci.nsILoadInfo.SEC_NORMAL; securityFlags = loadUsingSystemPrincipal
? Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
: Ci.nsILoadInfo.SEC_NORMAL;
} }
if (contentPolicyType === undefined) { if (contentPolicyType === undefined) {

View File

@ -632,8 +632,11 @@ nsBaseChannel::Open2(nsIInputStream** aStream)
NS_IMETHODIMP NS_IMETHODIMP
nsBaseChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) nsBaseChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetInitialSecurityCheckDone(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_INITIALIZED);

View File

@ -111,8 +111,11 @@ DummyChannel::Open2(nsIInputStream** aStream)
NS_IMETHODIMP DummyChannel::AsyncOpen(nsIStreamListener* aListener, nsISupports* aContext) NS_IMETHODIMP DummyChannel::AsyncOpen(nsIStreamListener* aListener, nsISupports* aContext)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetInitialSecurityCheckDone(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
mListener = aListener; mListener = aListener;

View File

@ -1679,8 +1679,11 @@ HttpChannelChild::GetSecurityInfo(nsISupports **aSecurityInfo)
NS_IMETHODIMP NS_IMETHODIMP
HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext) HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetInitialSecurityCheckDone(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
LOG(("HttpChannelChild::AsyncOpen [this=%p uri=%s]\n", this, mSpec.get())); LOG(("HttpChannelChild::AsyncOpen [this=%p uri=%s]\n", this, mSpec.get()));

View File

@ -4991,8 +4991,11 @@ nsHttpChannel::GetSecurityInfo(nsISupports **securityInfo)
NS_IMETHODIMP NS_IMETHODIMP
nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context) nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetInitialSecurityCheckDone(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
LOG(("nsHttpChannel::AsyncOpen [this=%p]\n", this)); LOG(("nsHttpChannel::AsyncOpen [this=%p]\n", this));

View File

@ -107,8 +107,11 @@ private:
NS_IMETHODIMP NS_IMETHODIMP
RtspChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext) RtspChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetInitialSecurityCheckDone(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
// Precondition checks. // Precondition checks.

View File

@ -626,8 +626,11 @@ GetTabChild(nsIChannel* aChannel)
NS_IMETHODIMP NS_IMETHODIMP
WyciwygChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext) WyciwygChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetInitialSecurityCheckDone(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
LOG(("WyciwygChannelChild::AsyncOpen [this=%p]\n", this)); LOG(("WyciwygChannelChild::AsyncOpen [this=%p]\n", this));

View File

@ -431,8 +431,11 @@ nsWyciwygChannel::Open2(nsIInputStream** aStream)
NS_IMETHODIMP NS_IMETHODIMP
nsWyciwygChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx) nsWyciwygChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetInitialSecurityCheckDone(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
LOG(("nsWyciwygChannel::AsyncOpen [this=%p]\n", this)); LOG(("nsWyciwygChannel::AsyncOpen [this=%p]\n", this));

View File

@ -409,8 +409,7 @@ function promiseStartExternalHelperAppServiceDownload(aSourceUrl) {
let channel = NetUtil.newChannel({ let channel = NetUtil.newChannel({
uri: sourceURI, uri: sourceURI,
loadUsingSystemPrincipal: true, loadUsingSystemPrincipal: true
securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
}); });
// Start the actual download process. // Start the actual download process.

View File

@ -166,8 +166,7 @@ function promiseEntityID(aUrl) {
let entityID = ""; let entityID = "";
let channel = NetUtil.newChannel({ let channel = NetUtil.newChannel({
uri: NetUtil.newURI(aUrl), uri: NetUtil.newURI(aUrl),
loadUsingSystemPrincipal: true, loadUsingSystemPrincipal: true
securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
}); });
channel.asyncOpen2({ channel.asyncOpen2({

View File

@ -2451,8 +2451,7 @@ this.XPIProvider = {
try { try {
chan = NetUtil.newChannel({ chan = NetUtil.newChannel({
uri: aURI, uri: aURI,
loadUsingSystemPrincipal: true, loadUsingSystemPrincipal: true
securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
}); });
} }
catch (ex) { catch (ex) {
@ -5545,8 +5544,7 @@ AddonInstall.prototype = {
this.channel = NetUtil.newChannel({ this.channel = NetUtil.newChannel({
uri: this.sourceURI, uri: this.sourceURI,
loadUsingSystemPrincipal: true, loadUsingSystemPrincipal: true
securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
}); });
this.channel.notificationCallbacks = this; this.channel.notificationCallbacks = this;
if (this.channel instanceof Ci.nsIHttpChannel) { if (this.channel instanceof Ci.nsIHttpChannel) {

View File

@ -186,8 +186,11 @@ NS_IMETHODIMP nsExtProtocolChannel::Open2(nsIInputStream** aStream)
NS_IMETHODIMP nsExtProtocolChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) NS_IMETHODIMP nsExtProtocolChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
{ {
MOZ_ASSERT(!mLoadInfo || mLoadInfo->GetSecurityMode() == 0 || MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetInitialSecurityCheckDone(), mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called"); "security flags in loadInfo but asyncOpen2() not called");
NS_ENSURE_ARG_POINTER(listener); NS_ENSURE_ARG_POINTER(listener);