2016-05-28 00:54:31 +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: */
|
2014-07-07 22:13:04 +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 "BackgroundUtils.h"
|
|
|
|
|
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
2015-08-17 12:03:19 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2018-07-17 22:38:48 +03:00
|
|
|
#include "mozilla/ContentPrincipal.h"
|
2018-07-17 22:37:48 +03:00
|
|
|
#include "mozilla/NullPrincipal.h"
|
2014-07-07 22:13:04 +04:00
|
|
|
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
2017-05-25 20:42:00 +03:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2015-06-19 01:37:20 +03:00
|
|
|
#include "mozilla/net/NeckoChannelParams.h"
|
2017-03-22 13:38:17 +03:00
|
|
|
#include "ExpandedPrincipal.h"
|
2014-07-07 22:13:04 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsNetUtil.h"
|
2015-07-06 08:55:00 +03:00
|
|
|
#include "mozilla/LoadInfo.h"
|
2017-04-15 23:26:06 +03:00
|
|
|
#include "nsContentUtils.h"
|
2014-07-07 22:13:04 +04:00
|
|
|
#include "nsString.h"
|
2015-07-20 05:11:03 +03:00
|
|
|
#include "nsTArray.h"
|
2017-05-25 20:42:00 +03:00
|
|
|
#include "mozilla/nsRedirectHistoryEntry.h"
|
2017-05-30 19:07:59 +03:00
|
|
|
#include "URIUtils.h"
|
2014-07-07 22:13:04 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-07-14 08:43:13 +03:00
|
|
|
namespace net {
|
|
|
|
class OptionalLoadInfoArgs;
|
|
|
|
}
|
|
|
|
|
2015-08-17 12:03:19 +03:00
|
|
|
using mozilla::BasePrincipal;
|
2018-01-23 18:38:52 +03:00
|
|
|
using mozilla::Maybe;
|
|
|
|
using mozilla::dom::ServiceWorkerDescriptor;
|
2015-07-14 08:43:13 +03:00
|
|
|
using namespace mozilla::net;
|
|
|
|
|
2014-07-07 22:13:04 +04:00
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
already_AddRefed<nsIPrincipal>
|
|
|
|
PrincipalInfoToPrincipal(const PrincipalInfo& aPrincipalInfo,
|
|
|
|
nsresult* aOptionalResult)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::T__None);
|
|
|
|
|
|
|
|
nsresult stackResult;
|
|
|
|
nsresult& rv = aOptionalResult ? *aOptionalResult : stackResult;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager> secMan =
|
2017-04-15 23:26:06 +03:00
|
|
|
nsContentUtils::GetSecurityManager();
|
|
|
|
if (!secMan) {
|
2014-07-07 22:13:04 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
|
|
|
|
switch (aPrincipalInfo.type()) {
|
|
|
|
case PrincipalInfo::TSystemPrincipalInfo: {
|
|
|
|
rv = secMan->GetSystemPrincipal(getter_AddRefs(principal));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return principal.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
case PrincipalInfo::TNullPrincipalInfo: {
|
2016-04-21 11:30:03 +03:00
|
|
|
const NullPrincipalInfo& info =
|
|
|
|
aPrincipalInfo.get_NullPrincipalInfo();
|
2014-07-07 22:13:04 +04:00
|
|
|
|
2016-11-30 17:13:27 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), info.spec());
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-03-22 13:38:40 +03:00
|
|
|
principal = NullPrincipal::Create(info.attrs(), uri);
|
2014-07-07 22:13:04 +04:00
|
|
|
return principal.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
case PrincipalInfo::TContentPrincipalInfo: {
|
|
|
|
const ContentPrincipalInfo& info =
|
|
|
|
aPrincipalInfo.get_ContentPrincipalInfo();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), info.spec());
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
OriginAttributes attrs;
|
2016-05-24 13:01:34 +03:00
|
|
|
if (info.attrs().mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
|
|
|
|
attrs = info.attrs();
|
2014-07-07 22:13:04 +04:00
|
|
|
}
|
2016-05-24 13:01:34 +03:00
|
|
|
principal = BasePrincipal::CreateCodebasePrincipal(uri, attrs);
|
2017-03-29 09:24:01 +03:00
|
|
|
if (NS_WARN_IF(!principal)) {
|
2014-07-07 22:13:04 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-15 13:19:26 +03:00
|
|
|
// Origin must match what the_new_principal.getOrigin returns.
|
|
|
|
nsAutoCString originNoSuffix;
|
|
|
|
rv = principal->GetOriginNoSuffix(originNoSuffix);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)) ||
|
|
|
|
!info.originNoSuffix().Equals(originNoSuffix)) {
|
|
|
|
MOZ_CRASH("Origin must be available when deserialized");
|
2017-03-20 18:03:45 +03:00
|
|
|
}
|
|
|
|
|
2014-07-07 22:13:04 +04:00
|
|
|
return principal.forget();
|
|
|
|
}
|
|
|
|
|
2015-04-07 01:44:04 +03:00
|
|
|
case PrincipalInfo::TExpandedPrincipalInfo: {
|
|
|
|
const ExpandedPrincipalInfo& info = aPrincipalInfo.get_ExpandedPrincipalInfo();
|
|
|
|
|
2016-09-10 01:52:55 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIPrincipal>> whitelist;
|
2015-04-07 01:44:04 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> wlPrincipal;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < info.whitelist().Length(); i++) {
|
|
|
|
wlPrincipal = PrincipalInfoToPrincipal(info.whitelist()[i], &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
// append that principal to the whitelist
|
|
|
|
whitelist.AppendElement(wlPrincipal);
|
|
|
|
}
|
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
RefPtr<ExpandedPrincipal> expandedPrincipal =
|
|
|
|
ExpandedPrincipal::Create(whitelist, info.attrs());
|
2015-04-07 01:44:04 +03:00
|
|
|
if (!expandedPrincipal) {
|
|
|
|
NS_WARNING("could not instantiate expanded principal");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
principal = expandedPrincipal;
|
|
|
|
return principal.forget();
|
|
|
|
}
|
|
|
|
|
2014-07-07 22:13:04 +04:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown PrincipalInfo type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
|
|
|
|
PrincipalInfo* aPrincipalInfo)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aPrincipal);
|
|
|
|
MOZ_ASSERT(aPrincipalInfo);
|
|
|
|
|
2016-08-12 08:19:29 +03:00
|
|
|
if (aPrincipal->GetIsNullPrincipal()) {
|
2016-11-30 17:13:27 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = aPrincipal->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!uri)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString spec;
|
|
|
|
rv = uri->GetSpec(spec);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aPrincipalInfo =
|
2016-12-19 13:30:29 +03:00
|
|
|
NullPrincipalInfo(aPrincipal->OriginAttributesRef(), spec);
|
2014-07-07 22:13:04 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager> secMan =
|
2017-04-15 23:26:06 +03:00
|
|
|
nsContentUtils::GetSecurityManager();
|
|
|
|
if (!secMan) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2014-07-07 22:13:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isSystemPrincipal;
|
2017-04-15 23:26:06 +03:00
|
|
|
nsresult rv = secMan->IsSystemPrincipal(aPrincipal, &isSystemPrincipal);
|
2014-07-07 22:13:04 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSystemPrincipal) {
|
|
|
|
*aPrincipalInfo = SystemPrincipalInfo();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-07 01:44:04 +03:00
|
|
|
// might be an expanded principal
|
2017-10-11 01:00:16 +03:00
|
|
|
auto* basePrin = BasePrincipal::Cast(aPrincipal);
|
|
|
|
if (basePrin->Is<ExpandedPrincipal>()) {
|
|
|
|
auto* expanded = basePrin->As<ExpandedPrincipal>();
|
2015-04-07 01:44:04 +03:00
|
|
|
|
|
|
|
nsTArray<PrincipalInfo> whitelistInfo;
|
|
|
|
PrincipalInfo info;
|
|
|
|
|
2017-10-11 01:00:16 +03:00
|
|
|
for (auto& prin : expanded->WhiteList()) {
|
|
|
|
rv = PrincipalToPrincipalInfo(prin, &info);
|
2015-04-07 01:44:04 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
// append that spec to the whitelist
|
|
|
|
whitelistInfo.AppendElement(info);
|
|
|
|
}
|
|
|
|
|
2016-09-10 01:52:55 +03:00
|
|
|
*aPrincipalInfo =
|
2016-12-19 13:30:29 +03:00
|
|
|
ExpandedPrincipalInfo(aPrincipal->OriginAttributesRef(),
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(whitelistInfo));
|
2015-04-07 01:44:04 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// must be a content principal
|
|
|
|
|
2014-07-07 22:13:04 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = aPrincipal->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-12-04 21:12:47 +03:00
|
|
|
if (NS_WARN_IF(!uri)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-11-30 17:13:27 +03:00
|
|
|
nsAutoCString spec;
|
2014-07-07 22:13:04 +04:00
|
|
|
rv = uri->GetSpec(spec);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-03-20 18:03:45 +03:00
|
|
|
nsCString originNoSuffix;
|
|
|
|
rv = aPrincipal->GetOriginNoSuffix(originNoSuffix);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2017-11-15 13:19:26 +03:00
|
|
|
return rv;
|
2017-03-20 18:03:45 +03:00
|
|
|
}
|
|
|
|
|
2016-12-19 13:30:29 +03:00
|
|
|
*aPrincipalInfo = ContentPrincipalInfo(aPrincipal->OriginAttributesRef(),
|
2017-11-15 13:19:26 +03:00
|
|
|
originNoSuffix, spec);
|
2014-07-07 22:13:04 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-01-28 20:29:13 +03:00
|
|
|
bool
|
|
|
|
IsPincipalInfoPrivate(const PrincipalInfo& aPrincipalInfo)
|
|
|
|
{
|
|
|
|
if (aPrincipalInfo.type() != ipc::PrincipalInfo::TContentPrincipalInfo) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ContentPrincipalInfo& info = aPrincipalInfo.get_ContentPrincipalInfo();
|
|
|
|
return !!info.attrs().mPrivateBrowsingId;
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:42:00 +03:00
|
|
|
already_AddRefed<nsIRedirectHistoryEntry>
|
|
|
|
RHEntryInfoToRHEntry(const RedirectHistoryEntryInfo& aRHEntryInfo)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPrincipal> principal =
|
|
|
|
PrincipalInfoToPrincipal(aRHEntryInfo.principalInfo(), &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> referrerUri = DeserializeURI(aRHEntryInfo.referrerUri());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRedirectHistoryEntry> entry =
|
|
|
|
new nsRedirectHistoryEntry(principal, referrerUri, aRHEntryInfo.remoteAddress());
|
|
|
|
|
|
|
|
return entry.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
RHEntryToRHEntryInfo(nsIRedirectHistoryEntry* aRHEntry,
|
|
|
|
RedirectHistoryEntryInfo* aRHEntryInfo)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRHEntry);
|
|
|
|
MOZ_ASSERT(aRHEntryInfo);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
aRHEntry->GetRemoteAddress(aRHEntryInfo->remoteAddress());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> referrerUri;
|
|
|
|
rv = aRHEntry->GetReferrerURI(getter_AddRefs(referrerUri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
SerializeURI(referrerUri, aRHEntryInfo->referrerUri());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
rv = aRHEntry->GetPrincipal(getter_AddRefs(principal));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return PrincipalToPrincipalInfo(principal, &aRHEntryInfo->principalInfo());
|
|
|
|
}
|
|
|
|
|
2015-06-19 01:37:20 +03:00
|
|
|
nsresult
|
|
|
|
LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo,
|
2015-07-14 08:43:13 +03:00
|
|
|
OptionalLoadInfoArgs* aOptionalLoadInfoArgs)
|
2015-06-19 01:37:20 +03:00
|
|
|
{
|
2015-07-14 08:43:13 +03:00
|
|
|
if (!aLoadInfo) {
|
|
|
|
// if there is no loadInfo, then there is nothing to serialize
|
|
|
|
*aOptionalLoadInfoArgs = void_t();
|
2015-06-19 01:37:20 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-14 08:43:13 +03:00
|
|
|
nsresult rv = NS_OK;
|
2016-04-14 02:30:16 +03:00
|
|
|
OptionalPrincipalInfo loadingPrincipalInfo = mozilla::void_t();
|
|
|
|
if (aLoadInfo->LoadingPrincipal()) {
|
|
|
|
PrincipalInfo loadingPrincipalInfoTemp;
|
|
|
|
rv = PrincipalToPrincipalInfo(aLoadInfo->LoadingPrincipal(),
|
|
|
|
&loadingPrincipalInfoTemp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
loadingPrincipalInfo = loadingPrincipalInfoTemp;
|
|
|
|
}
|
2015-07-14 08:43:13 +03:00
|
|
|
|
|
|
|
PrincipalInfo triggeringPrincipalInfo;
|
|
|
|
rv = PrincipalToPrincipalInfo(aLoadInfo->TriggeringPrincipal(),
|
|
|
|
&triggeringPrincipalInfo);
|
2018-05-10 18:18:05 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-07-14 08:43:13 +03:00
|
|
|
|
2016-11-08 09:23:12 +03:00
|
|
|
OptionalPrincipalInfo principalToInheritInfo = mozilla::void_t();
|
|
|
|
if (aLoadInfo->PrincipalToInherit()) {
|
|
|
|
PrincipalInfo principalToInheritInfoTemp;
|
|
|
|
rv = PrincipalToPrincipalInfo(aLoadInfo->PrincipalToInherit(),
|
|
|
|
&principalToInheritInfoTemp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
principalToInheritInfo = principalToInheritInfoTemp;
|
|
|
|
}
|
2016-09-20 09:35:45 +03:00
|
|
|
|
2017-02-01 01:56:15 +03:00
|
|
|
OptionalPrincipalInfo sandboxedLoadingPrincipalInfo = mozilla::void_t();
|
|
|
|
if (aLoadInfo->GetLoadingSandboxed()) {
|
|
|
|
PrincipalInfo sandboxedLoadingPrincipalInfoTemp;
|
|
|
|
nsCOMPtr<nsIPrincipal> sandboxedLoadingPrincipal;
|
|
|
|
rv = aLoadInfo->GetSandboxedLoadingPrincipal(
|
|
|
|
getter_AddRefs(sandboxedLoadingPrincipal));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = PrincipalToPrincipalInfo(sandboxedLoadingPrincipal,
|
|
|
|
&sandboxedLoadingPrincipalInfoTemp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
sandboxedLoadingPrincipalInfo = sandboxedLoadingPrincipalInfoTemp;
|
|
|
|
}
|
|
|
|
|
2018-08-10 21:55:27 +03:00
|
|
|
OptionalPrincipalInfo topLevelPrincipalInfo = mozilla::void_t();
|
|
|
|
if (aLoadInfo->TopLevelPrincipal()) {
|
|
|
|
PrincipalInfo topLevelPrincipalInfoTemp;
|
|
|
|
rv = PrincipalToPrincipalInfo(aLoadInfo->TopLevelPrincipal(),
|
|
|
|
&topLevelPrincipalInfoTemp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
topLevelPrincipalInfo = topLevelPrincipalInfoTemp;
|
|
|
|
}
|
|
|
|
|
2018-07-13 13:02:19 +03:00
|
|
|
OptionalPrincipalInfo topLevelStorageAreaPrincipalInfo = mozilla::void_t();
|
|
|
|
if (aLoadInfo->TopLevelStorageAreaPrincipal()) {
|
|
|
|
PrincipalInfo topLevelStorageAreaPrincipalInfoTemp;
|
|
|
|
rv = PrincipalToPrincipalInfo(aLoadInfo->TopLevelStorageAreaPrincipal(),
|
|
|
|
&topLevelStorageAreaPrincipalInfoTemp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
topLevelStorageAreaPrincipalInfo = topLevelStorageAreaPrincipalInfoTemp;
|
|
|
|
}
|
|
|
|
|
2017-05-30 19:07:59 +03:00
|
|
|
OptionalURIParams optionalResultPrincipalURI = mozilla::void_t();
|
|
|
|
nsCOMPtr<nsIURI> resultPrincipalURI;
|
|
|
|
Unused << aLoadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
|
|
|
|
if (resultPrincipalURI) {
|
|
|
|
SerializeURI(resultPrincipalURI, optionalResultPrincipalURI);
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:42:00 +03:00
|
|
|
nsTArray<RedirectHistoryEntryInfo> redirectChainIncludingInternalRedirects;
|
|
|
|
for (const nsCOMPtr<nsIRedirectHistoryEntry>& redirectEntry :
|
|
|
|
aLoadInfo->RedirectChainIncludingInternalRedirects()) {
|
|
|
|
RedirectHistoryEntryInfo* entry = redirectChainIncludingInternalRedirects.AppendElement();
|
|
|
|
rv = RHEntryToRHEntryInfo(redirectEntry, entry);
|
2015-11-01 01:18:59 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:42:00 +03:00
|
|
|
nsTArray<RedirectHistoryEntryInfo> redirectChain;
|
|
|
|
for (const nsCOMPtr<nsIRedirectHistoryEntry>& redirectEntry :
|
|
|
|
aLoadInfo->RedirectChain()) {
|
|
|
|
RedirectHistoryEntryInfo* entry = redirectChain.AppendElement();
|
|
|
|
rv = RHEntryToRHEntryInfo(redirectEntry, entry);
|
2015-07-20 05:11:03 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2017-10-10 19:54:00 +03:00
|
|
|
nsTArray<PrincipalInfo> ancestorPrincipals;
|
|
|
|
ancestorPrincipals.SetCapacity(aLoadInfo->AncestorPrincipals().Length());
|
|
|
|
for (const auto& principal : aLoadInfo->AncestorPrincipals()) {
|
|
|
|
rv = PrincipalToPrincipalInfo(principal, ancestorPrincipals.AppendElement());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2018-01-23 18:38:52 +03:00
|
|
|
OptionalIPCClientInfo ipcClientInfo = mozilla::void_t();
|
|
|
|
const Maybe<ClientInfo>& clientInfo = aLoadInfo->GetClientInfo();
|
|
|
|
if (clientInfo.isSome()) {
|
|
|
|
ipcClientInfo = clientInfo.ref().ToIPC();
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionalIPCClientInfo ipcReservedClientInfo = mozilla::void_t();
|
|
|
|
const Maybe<ClientInfo>& reservedClientInfo = aLoadInfo->GetReservedClientInfo();
|
|
|
|
if (reservedClientInfo.isSome()) {
|
|
|
|
ipcReservedClientInfo = reservedClientInfo.ref().ToIPC();
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionalIPCClientInfo ipcInitialClientInfo = mozilla::void_t();
|
|
|
|
const Maybe<ClientInfo>& initialClientInfo = aLoadInfo->GetInitialClientInfo();
|
|
|
|
if (initialClientInfo.isSome()) {
|
|
|
|
ipcInitialClientInfo = initialClientInfo.ref().ToIPC();
|
|
|
|
}
|
|
|
|
|
2018-01-23 18:38:52 +03:00
|
|
|
OptionalIPCServiceWorkerDescriptor ipcController = mozilla::void_t();
|
|
|
|
const Maybe<ServiceWorkerDescriptor>& controller = aLoadInfo->GetController();
|
|
|
|
if (controller.isSome()) {
|
|
|
|
ipcController = controller.ref().ToIPC();
|
|
|
|
}
|
|
|
|
|
2015-07-14 08:43:13 +03:00
|
|
|
*aOptionalLoadInfoArgs =
|
|
|
|
LoadInfoArgs(
|
2016-04-14 02:30:16 +03:00
|
|
|
loadingPrincipalInfo,
|
2015-07-14 08:43:13 +03:00
|
|
|
triggeringPrincipalInfo,
|
2016-09-20 09:35:45 +03:00
|
|
|
principalToInheritInfo,
|
2017-02-01 01:56:15 +03:00
|
|
|
sandboxedLoadingPrincipalInfo,
|
2018-08-10 21:55:27 +03:00
|
|
|
topLevelPrincipalInfo,
|
2018-07-13 13:02:19 +03:00
|
|
|
topLevelStorageAreaPrincipalInfo,
|
2017-05-30 19:07:59 +03:00
|
|
|
optionalResultPrincipalURI,
|
2015-07-14 08:43:13 +03:00
|
|
|
aLoadInfo->GetSecurityFlags(),
|
2015-10-19 21:14:54 +03:00
|
|
|
aLoadInfo->InternalContentPolicyType(),
|
2015-12-07 02:33:15 +03:00
|
|
|
static_cast<uint32_t>(aLoadInfo->GetTainting()),
|
2015-07-14 08:43:13 +03:00
|
|
|
aLoadInfo->GetUpgradeInsecureRequests(),
|
2018-02-05 18:37:27 +03:00
|
|
|
aLoadInfo->GetBrowserUpgradeInsecureRequests(),
|
2018-03-04 17:33:33 +03:00
|
|
|
aLoadInfo->GetBrowserWouldUpgradeInsecureRequests(),
|
2016-03-14 13:56:52 +03:00
|
|
|
aLoadInfo->GetVerifySignedContent(),
|
2016-03-16 06:13:26 +03:00
|
|
|
aLoadInfo->GetEnforceSRI(),
|
2017-11-08 22:01:41 +03:00
|
|
|
aLoadInfo->GetForceAllowDataURI(),
|
2018-02-18 21:52:52 +03:00
|
|
|
aLoadInfo->GetAllowInsecureRedirectToDataURI(),
|
2018-03-29 12:14:35 +03:00
|
|
|
aLoadInfo->GetSkipContentPolicyCheckForWebRequest(),
|
2016-07-18 09:35:13 +03:00
|
|
|
aLoadInfo->GetForceInheritPrincipalDropped(),
|
2015-07-14 08:43:13 +03:00
|
|
|
aLoadInfo->GetInnerWindowID(),
|
|
|
|
aLoadInfo->GetOuterWindowID(),
|
2015-07-20 05:11:03 +03:00
|
|
|
aLoadInfo->GetParentOuterWindowID(),
|
2017-09-07 00:25:23 +03:00
|
|
|
aLoadInfo->GetTopOuterWindowID(),
|
2016-06-27 03:42:00 +03:00
|
|
|
aLoadInfo->GetFrameOuterWindowID(),
|
2015-07-20 05:11:57 +03:00
|
|
|
aLoadInfo->GetEnforceSecurity(),
|
|
|
|
aLoadInfo->GetInitialSecurityCheckDone(),
|
2015-12-01 00:25:29 +03:00
|
|
|
aLoadInfo->GetIsInThirdPartyContext(),
|
2018-01-23 18:38:51 +03:00
|
|
|
aLoadInfo->GetIsDocshellReload(),
|
2018-08-01 07:35:24 +03:00
|
|
|
aLoadInfo->GetSendCSPViolationEvents(),
|
2015-10-22 00:47:00 +03:00
|
|
|
aLoadInfo->GetOriginAttributes(),
|
2015-11-01 01:18:59 +03:00
|
|
|
redirectChainIncludingInternalRedirects,
|
2015-12-07 02:33:14 +03:00
|
|
|
redirectChain,
|
2017-10-10 19:54:00 +03:00
|
|
|
ancestorPrincipals,
|
|
|
|
aLoadInfo->AncestorOuterWindowIDs(),
|
2018-01-23 18:38:52 +03:00
|
|
|
ipcClientInfo,
|
|
|
|
ipcReservedClientInfo,
|
|
|
|
ipcInitialClientInfo,
|
2018-01-23 18:38:52 +03:00
|
|
|
ipcController,
|
2015-12-07 02:33:14 +03:00
|
|
|
aLoadInfo->CorsUnsafeHeaders(),
|
|
|
|
aLoadInfo->GetForcePreflight(),
|
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
|
|
|
aLoadInfo->GetIsPreflight(),
|
2017-11-03 15:23:11 +03:00
|
|
|
aLoadInfo->GetLoadTriggeredFromExternal(),
|
2018-08-31 14:21:17 +03:00
|
|
|
aLoadInfo->GetServiceWorkerTaintingSynthesized(),
|
|
|
|
aLoadInfo->GetDocumentHasUserInteracted()
|
2017-05-10 01:36:07 +03:00
|
|
|
);
|
2015-07-14 08:43:13 +03:00
|
|
|
|
2015-06-19 01:37:20 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-07-14 08:43:13 +03:00
|
|
|
LoadInfoArgsToLoadInfo(const OptionalLoadInfoArgs& aOptionalLoadInfoArgs,
|
2015-06-19 01:37:20 +03:00
|
|
|
nsILoadInfo** outLoadInfo)
|
|
|
|
{
|
2015-07-14 08:43:13 +03:00
|
|
|
if (aOptionalLoadInfoArgs.type() == OptionalLoadInfoArgs::Tvoid_t) {
|
|
|
|
*outLoadInfo = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LoadInfoArgs& loadInfoArgs =
|
|
|
|
aOptionalLoadInfoArgs.get_LoadInfoArgs();
|
|
|
|
|
2015-06-19 01:37:20 +03:00
|
|
|
nsresult rv = NS_OK;
|
2016-04-14 02:30:16 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> loadingPrincipal;
|
|
|
|
if (loadInfoArgs.requestingPrincipalInfo().type() != OptionalPrincipalInfo::Tvoid_t) {
|
|
|
|
loadingPrincipal = PrincipalInfoToPrincipal(loadInfoArgs.requestingPrincipalInfo(), &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2015-06-19 01:37:20 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsIPrincipal> triggeringPrincipal =
|
2015-07-14 08:43:13 +03:00
|
|
|
PrincipalInfoToPrincipal(loadInfoArgs.triggeringPrincipalInfo(), &rv);
|
2015-06-19 01:37:20 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2016-11-08 09:23:12 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principalToInherit;
|
|
|
|
if (loadInfoArgs.principalToInheritInfo().type() != OptionalPrincipalInfo::Tvoid_t) {
|
|
|
|
principalToInherit = PrincipalInfoToPrincipal(loadInfoArgs.principalToInheritInfo(), &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2016-09-20 09:35:45 +03:00
|
|
|
|
2017-02-01 01:56:15 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> sandboxedLoadingPrincipal;
|
|
|
|
if (loadInfoArgs.sandboxedLoadingPrincipalInfo().type() != OptionalPrincipalInfo::Tvoid_t) {
|
|
|
|
sandboxedLoadingPrincipal =
|
|
|
|
PrincipalInfoToPrincipal(loadInfoArgs.sandboxedLoadingPrincipalInfo(), &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2018-08-10 21:55:27 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> topLevelPrincipal;
|
|
|
|
if (loadInfoArgs.topLevelPrincipalInfo().type() != OptionalPrincipalInfo::Tvoid_t) {
|
|
|
|
topLevelPrincipal =
|
|
|
|
PrincipalInfoToPrincipal(loadInfoArgs.topLevelPrincipalInfo(), &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2018-07-13 13:02:19 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> topLevelStorageAreaPrincipal;
|
|
|
|
if (loadInfoArgs.topLevelStorageAreaPrincipalInfo().type() != OptionalPrincipalInfo::Tvoid_t) {
|
|
|
|
topLevelStorageAreaPrincipal =
|
|
|
|
PrincipalInfoToPrincipal(loadInfoArgs.topLevelStorageAreaPrincipalInfo(), &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2017-05-30 19:07:59 +03:00
|
|
|
nsCOMPtr<nsIURI> resultPrincipalURI;
|
|
|
|
if (loadInfoArgs.resultPrincipalURI().type() != OptionalURIParams::Tvoid_t) {
|
|
|
|
resultPrincipalURI = DeserializeURI(loadInfoArgs.resultPrincipalURI());
|
|
|
|
NS_ENSURE_TRUE(resultPrincipalURI, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:42:00 +03:00
|
|
|
RedirectHistoryArray redirectChainIncludingInternalRedirects;
|
|
|
|
for (const RedirectHistoryEntryInfo& entryInfo :
|
|
|
|
loadInfoArgs.redirectChainIncludingInternalRedirects()) {
|
|
|
|
nsCOMPtr<nsIRedirectHistoryEntry> redirectHistoryEntry =
|
|
|
|
RHEntryInfoToRHEntry(entryInfo);
|
2015-11-01 01:18:59 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-05-25 20:42:00 +03:00
|
|
|
redirectChainIncludingInternalRedirects.AppendElement(redirectHistoryEntry.forget());
|
2015-11-01 01:18:59 +03:00
|
|
|
}
|
|
|
|
|
2017-05-25 20:42:00 +03:00
|
|
|
RedirectHistoryArray redirectChain;
|
|
|
|
for (const RedirectHistoryEntryInfo& entryInfo : loadInfoArgs.redirectChain()) {
|
|
|
|
nsCOMPtr<nsIRedirectHistoryEntry> redirectHistoryEntry =
|
|
|
|
RHEntryInfoToRHEntry(entryInfo);
|
2015-07-20 05:11:03 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-05-25 20:42:00 +03:00
|
|
|
redirectChain.AppendElement(redirectHistoryEntry.forget());
|
2015-07-20 05:11:03 +03:00
|
|
|
}
|
|
|
|
|
2017-10-10 19:54:00 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIPrincipal>> ancestorPrincipals;
|
|
|
|
ancestorPrincipals.SetCapacity(loadInfoArgs.ancestorPrincipals().Length());
|
|
|
|
for (const PrincipalInfo& principalInfo : loadInfoArgs.ancestorPrincipals()) {
|
|
|
|
nsCOMPtr<nsIPrincipal> ancestorPrincipal =
|
|
|
|
PrincipalInfoToPrincipal(principalInfo, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
ancestorPrincipals.AppendElement(ancestorPrincipal.forget());
|
|
|
|
}
|
|
|
|
|
2018-01-23 18:38:52 +03:00
|
|
|
Maybe<ClientInfo> clientInfo;
|
|
|
|
if (loadInfoArgs.clientInfo().type() != OptionalIPCClientInfo::Tvoid_t) {
|
|
|
|
clientInfo.emplace(ClientInfo(loadInfoArgs.clientInfo().get_IPCClientInfo()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<ClientInfo> reservedClientInfo;
|
|
|
|
if (loadInfoArgs.reservedClientInfo().type() != OptionalIPCClientInfo::Tvoid_t) {
|
|
|
|
reservedClientInfo.emplace(
|
|
|
|
ClientInfo(loadInfoArgs.reservedClientInfo().get_IPCClientInfo()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<ClientInfo> initialClientInfo;
|
|
|
|
if (loadInfoArgs.initialClientInfo().type() != OptionalIPCClientInfo::Tvoid_t) {
|
|
|
|
initialClientInfo.emplace(
|
|
|
|
ClientInfo(loadInfoArgs.initialClientInfo().get_IPCClientInfo()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can have an initial client info or a reserved client info, but not both.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(reservedClientInfo.isNothing() ||
|
|
|
|
initialClientInfo.isNothing());
|
|
|
|
NS_ENSURE_TRUE(reservedClientInfo.isNothing() ||
|
|
|
|
initialClientInfo.isNothing(), NS_ERROR_UNEXPECTED);
|
|
|
|
|
2018-01-23 18:38:52 +03:00
|
|
|
Maybe<ServiceWorkerDescriptor> controller;
|
|
|
|
if (loadInfoArgs.controller().type() != OptionalIPCServiceWorkerDescriptor::Tvoid_t) {
|
|
|
|
controller.emplace(ServiceWorkerDescriptor(
|
|
|
|
loadInfoArgs.controller().get_IPCServiceWorkerDescriptor()));
|
|
|
|
}
|
|
|
|
|
2015-06-19 01:37:20 +03:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo =
|
2016-04-14 02:30:16 +03:00
|
|
|
new mozilla::LoadInfo(loadingPrincipal,
|
2015-06-19 01:37:20 +03:00
|
|
|
triggeringPrincipal,
|
2016-09-20 09:35:45 +03:00
|
|
|
principalToInherit,
|
2017-02-01 01:56:15 +03:00
|
|
|
sandboxedLoadingPrincipal,
|
2018-08-10 21:55:27 +03:00
|
|
|
topLevelPrincipal,
|
2018-07-13 13:02:19 +03:00
|
|
|
topLevelStorageAreaPrincipal,
|
2017-05-30 19:07:59 +03:00
|
|
|
resultPrincipalURI,
|
2018-01-23 18:38:52 +03:00
|
|
|
clientInfo,
|
|
|
|
reservedClientInfo,
|
|
|
|
initialClientInfo,
|
2018-01-23 18:38:52 +03:00
|
|
|
controller,
|
2015-07-14 08:43:13 +03:00
|
|
|
loadInfoArgs.securityFlags(),
|
|
|
|
loadInfoArgs.contentPolicyType(),
|
2015-12-07 02:33:15 +03:00
|
|
|
static_cast<LoadTainting>(loadInfoArgs.tainting()),
|
2015-07-14 08:43:13 +03:00
|
|
|
loadInfoArgs.upgradeInsecureRequests(),
|
2018-02-05 18:37:27 +03:00
|
|
|
loadInfoArgs.browserUpgradeInsecureRequests(),
|
2018-03-04 17:33:33 +03:00
|
|
|
loadInfoArgs.browserWouldUpgradeInsecureRequests(),
|
2016-03-14 13:56:52 +03:00
|
|
|
loadInfoArgs.verifySignedContent(),
|
2016-03-16 06:13:26 +03:00
|
|
|
loadInfoArgs.enforceSRI(),
|
2017-11-08 22:01:41 +03:00
|
|
|
loadInfoArgs.forceAllowDataURI(),
|
2018-02-18 21:52:52 +03:00
|
|
|
loadInfoArgs.allowInsecureRedirectToDataURI(),
|
2018-03-29 12:14:35 +03:00
|
|
|
loadInfoArgs.skipContentPolicyCheckForWebRequest(),
|
2016-07-18 09:35:13 +03:00
|
|
|
loadInfoArgs.forceInheritPrincipalDropped(),
|
2015-07-14 08:43:13 +03:00
|
|
|
loadInfoArgs.innerWindowID(),
|
|
|
|
loadInfoArgs.outerWindowID(),
|
2015-07-20 05:11:03 +03:00
|
|
|
loadInfoArgs.parentOuterWindowID(),
|
2017-09-07 00:25:23 +03:00
|
|
|
loadInfoArgs.topOuterWindowID(),
|
2016-06-27 03:42:00 +03:00
|
|
|
loadInfoArgs.frameOuterWindowID(),
|
2015-07-20 05:11:57 +03:00
|
|
|
loadInfoArgs.enforceSecurity(),
|
|
|
|
loadInfoArgs.initialSecurityCheckDone(),
|
2015-12-01 00:25:29 +03:00
|
|
|
loadInfoArgs.isInThirdPartyContext(),
|
2018-01-23 18:38:51 +03:00
|
|
|
loadInfoArgs.isDocshellReload(),
|
2018-08-01 07:35:24 +03:00
|
|
|
loadInfoArgs.sendCSPViolationEvents(),
|
2015-10-22 00:47:00 +03:00
|
|
|
loadInfoArgs.originAttributes(),
|
2015-11-01 01:18:59 +03:00
|
|
|
redirectChainIncludingInternalRedirects,
|
2015-12-07 02:33:14 +03:00
|
|
|
redirectChain,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(ancestorPrincipals),
|
2017-10-10 19:54:00 +03:00
|
|
|
loadInfoArgs.ancestorOuterWindowIDs(),
|
2015-12-07 02:33:14 +03:00
|
|
|
loadInfoArgs.corsUnsafeHeaders(),
|
|
|
|
loadInfoArgs.forcePreflight(),
|
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
|
|
|
loadInfoArgs.isPreflight(),
|
2017-11-03 15:23:11 +03:00
|
|
|
loadInfoArgs.loadTriggeredFromExternal(),
|
2018-08-31 14:21:17 +03:00
|
|
|
loadInfoArgs.serviceWorkerTaintingSynthesized(),
|
|
|
|
loadInfoArgs.documentHasUserInteracted()
|
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
|
|
|
);
|
2015-07-14 08:43:13 +03:00
|
|
|
|
|
|
|
loadInfo.forget(outLoadInfo);
|
|
|
|
return NS_OK;
|
2015-06-19 01:37:20 +03:00
|
|
|
}
|
|
|
|
|
2018-03-06 09:07:00 +03:00
|
|
|
void
|
|
|
|
LoadInfoToParentLoadInfoForwarder(nsILoadInfo* aLoadInfo,
|
2018-06-04 19:26:50 +03:00
|
|
|
ParentLoadInfoForwarderArgs* aForwarderArgsOut)
|
2018-03-06 09:07:00 +03:00
|
|
|
{
|
|
|
|
if (!aLoadInfo) {
|
2018-06-11 22:54:22 +03:00
|
|
|
*aForwarderArgsOut = ParentLoadInfoForwarderArgs(false, void_t(),
|
|
|
|
nsILoadInfo::TAINTING_BASIC,
|
2018-08-31 14:21:17 +03:00
|
|
|
false, // serviceWorkerTaintingSynthesized
|
|
|
|
false, // isTracker
|
|
|
|
false, // isTrackerBlocked
|
2018-09-07 21:43:11 +03:00
|
|
|
mozilla::Telemetry::LABELS_DOCUMENT_ANALYTICS_TRACKER_FASTBLOCKED::all, // trackerBlockedReason
|
2018-08-31 14:21:17 +03:00
|
|
|
false // documentHasUserInteracted
|
|
|
|
);
|
2018-03-06 09:07:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-04 19:26:50 +03:00
|
|
|
OptionalIPCServiceWorkerDescriptor ipcController = void_t();
|
|
|
|
Maybe<ServiceWorkerDescriptor> controller(aLoadInfo->GetController());
|
|
|
|
if (controller.isSome()) {
|
|
|
|
ipcController = controller.ref().ToIPC();
|
|
|
|
}
|
|
|
|
|
2018-06-11 22:54:22 +03:00
|
|
|
uint32_t tainting = nsILoadInfo::TAINTING_BASIC;
|
|
|
|
Unused << aLoadInfo->GetTainting(&tainting);
|
|
|
|
|
2018-09-07 21:43:11 +03:00
|
|
|
mozilla::Telemetry::LABELS_DOCUMENT_ANALYTICS_TRACKER_FASTBLOCKED label =
|
|
|
|
mozilla::Telemetry::LABELS_DOCUMENT_ANALYTICS_TRACKER_FASTBLOCKED::all;
|
|
|
|
Unused << aLoadInfo->GetTrackerBlockedReason(&label);
|
|
|
|
|
2018-06-04 19:26:50 +03:00
|
|
|
*aForwarderArgsOut = ParentLoadInfoForwarderArgs(
|
|
|
|
aLoadInfo->GetAllowInsecureRedirectToDataURI(),
|
2018-06-11 22:54:22 +03:00
|
|
|
ipcController,
|
|
|
|
tainting,
|
2018-08-16 18:29:22 +03:00
|
|
|
aLoadInfo->GetServiceWorkerTaintingSynthesized(),
|
2018-08-31 14:21:17 +03:00
|
|
|
aLoadInfo->GetIsTracker(),
|
|
|
|
aLoadInfo->GetIsTrackerBlocked(),
|
2018-09-07 21:43:11 +03:00
|
|
|
label,
|
2018-08-31 14:21:17 +03:00
|
|
|
aLoadInfo->GetDocumentHasUserInteracted()
|
2018-03-06 09:07:00 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-04 19:26:50 +03:00
|
|
|
MergeParentLoadInfoForwarder(ParentLoadInfoForwarderArgs const& aForwarderArgs,
|
2018-03-06 09:07:00 +03:00
|
|
|
nsILoadInfo* aLoadInfo)
|
|
|
|
{
|
|
|
|
if (!aLoadInfo) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = aLoadInfo->SetAllowInsecureRedirectToDataURI(
|
2018-06-04 19:26:50 +03:00
|
|
|
aForwarderArgs.allowInsecureRedirectToDataURI());
|
2018-03-06 09:07:00 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2018-06-04 19:26:50 +03:00
|
|
|
aLoadInfo->ClearController();
|
|
|
|
auto& controller = aForwarderArgs.controller();
|
|
|
|
if (controller.type() != OptionalIPCServiceWorkerDescriptor::Tvoid_t) {
|
|
|
|
aLoadInfo->SetController(
|
|
|
|
ServiceWorkerDescriptor(controller.get_IPCServiceWorkerDescriptor()));
|
|
|
|
}
|
|
|
|
|
2018-06-11 22:54:22 +03:00
|
|
|
if (aForwarderArgs.serviceWorkerTaintingSynthesized()) {
|
|
|
|
aLoadInfo->SynthesizeServiceWorkerTainting(
|
|
|
|
static_cast<LoadTainting>(aForwarderArgs.tainting()));
|
|
|
|
} else {
|
|
|
|
aLoadInfo->MaybeIncreaseTainting(aForwarderArgs.tainting());
|
|
|
|
}
|
|
|
|
|
2018-08-16 18:29:22 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(aLoadInfo->SetIsTracker(aForwarderArgs.isTracker()));
|
|
|
|
MOZ_ALWAYS_SUCCEEDS(aLoadInfo->SetIsTrackerBlocked(aForwarderArgs.isTrackerBlocked()));
|
2018-09-07 21:43:11 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(aLoadInfo->SetTrackerBlockedReason(aForwarderArgs.trackerBlockedReason()));
|
2018-08-31 14:21:17 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(aLoadInfo->SetDocumentHasUserInteracted(aForwarderArgs.documentHasUserInteracted()));
|
2018-08-16 18:29:22 +03:00
|
|
|
|
2018-03-06 09:07:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-06-04 19:26:51 +03:00
|
|
|
void
|
|
|
|
LoadInfoToChildLoadInfoForwarder(nsILoadInfo* aLoadInfo,
|
|
|
|
ChildLoadInfoForwarderArgs* aForwarderArgsOut)
|
|
|
|
{
|
|
|
|
if (!aLoadInfo) {
|
|
|
|
*aForwarderArgsOut = ChildLoadInfoForwarderArgs(void_t(), void_t(),
|
|
|
|
void_t());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionalIPCClientInfo ipcReserved = void_t();
|
|
|
|
Maybe<ClientInfo> reserved(aLoadInfo->GetReservedClientInfo());
|
|
|
|
if (reserved.isSome()) {
|
|
|
|
ipcReserved = reserved.ref().ToIPC();
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionalIPCClientInfo ipcInitial = void_t();
|
|
|
|
Maybe<ClientInfo> initial(aLoadInfo->GetInitialClientInfo());
|
|
|
|
if (initial.isSome()) {
|
|
|
|
ipcInitial = initial.ref().ToIPC();
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionalIPCServiceWorkerDescriptor ipcController = void_t();
|
|
|
|
Maybe<ServiceWorkerDescriptor> controller(aLoadInfo->GetController());
|
|
|
|
if (controller.isSome()) {
|
|
|
|
ipcController = controller.ref().ToIPC();
|
|
|
|
}
|
|
|
|
|
|
|
|
*aForwarderArgsOut = ChildLoadInfoForwarderArgs(
|
|
|
|
ipcReserved,
|
|
|
|
ipcInitial,
|
|
|
|
ipcController
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
MergeChildLoadInfoForwarder(const ChildLoadInfoForwarderArgs& aForwarderArgs,
|
|
|
|
nsILoadInfo* aLoadInfo)
|
|
|
|
{
|
|
|
|
if (!aLoadInfo) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<ClientInfo> reservedClientInfo;
|
|
|
|
auto& ipcReserved = aForwarderArgs.reservedClientInfo();
|
|
|
|
if (ipcReserved.type() != OptionalIPCClientInfo::Tvoid_t) {
|
|
|
|
reservedClientInfo.emplace(ClientInfo(ipcReserved.get_IPCClientInfo()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<ClientInfo> initialClientInfo;
|
|
|
|
auto& ipcInitial = aForwarderArgs.initialClientInfo();
|
|
|
|
if (ipcInitial.type() != OptionalIPCClientInfo::Tvoid_t) {
|
|
|
|
initialClientInfo.emplace(ClientInfo(ipcInitial.get_IPCClientInfo()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// There should only be at most one reserved or initial ClientInfo.
|
|
|
|
if (NS_WARN_IF(reservedClientInfo.isSome() && initialClientInfo.isSome())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we received no reserved or initial ClientInfo, then we must not
|
|
|
|
// already have one set. There are no use cases where this should
|
|
|
|
// happen and we don't have a way to clear the current value.
|
|
|
|
if (NS_WARN_IF(reservedClientInfo.isNothing() &&
|
|
|
|
initialClientInfo.isNothing() &&
|
|
|
|
(aLoadInfo->GetReservedClientInfo().isSome() ||
|
|
|
|
aLoadInfo->GetInitialClientInfo().isSome()))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reservedClientInfo.isSome()) {
|
2018-06-22 18:09:00 +03:00
|
|
|
// We need to override here instead of simply set the value. This
|
|
|
|
// allows us to change the reserved client. This is necessary when
|
|
|
|
// the ClientChannelHelper created a new reserved client in the
|
|
|
|
// child-side of the redirect.
|
|
|
|
aLoadInfo->OverrideReservedClientInfoInParent(reservedClientInfo.ref());
|
2018-06-04 19:26:51 +03:00
|
|
|
} else if (initialClientInfo.isSome()) {
|
|
|
|
aLoadInfo->SetInitialClientInfo(initialClientInfo.ref());
|
|
|
|
}
|
|
|
|
|
|
|
|
aLoadInfo->ClearController();
|
|
|
|
auto& controller = aForwarderArgs.controller();
|
|
|
|
if (controller.type() != OptionalIPCServiceWorkerDescriptor::Tvoid_t) {
|
|
|
|
aLoadInfo->SetController(
|
|
|
|
ServiceWorkerDescriptor(controller.get_IPCServiceWorkerDescriptor()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-07 22:13:04 +04:00
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|