2017-02-22 12:01:43 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
#include "ExpandedPrincipal.h"
|
2017-02-22 12:01:43 +03:00
|
|
|
#include "nsIClassInfoImpl.h"
|
2021-05-17 23:50:09 +03:00
|
|
|
#include "nsIObjectInputStream.h"
|
2020-12-17 17:58:18 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2019-06-03 15:37:12 +03:00
|
|
|
#include "mozilla/Base64.h"
|
2022-12-02 03:53:53 +03:00
|
|
|
#include "mozilla/extensions/WebExtensionPolicy.h"
|
2021-09-21 18:42:01 +03:00
|
|
|
#include "json/json.h"
|
2017-02-22 12:01:43 +03:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2023-02-02 00:45:44 +03:00
|
|
|
NS_IMPL_CLASSINFO(ExpandedPrincipal, nullptr, 0, NS_EXPANDEDPRINCIPAL_CID)
|
2017-03-22 13:38:17 +03:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(ExpandedPrincipal, nsIPrincipal,
|
2021-05-17 23:50:09 +03:00
|
|
|
nsIExpandedPrincipal)
|
2017-03-22 13:38:17 +03:00
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(ExpandedPrincipal, nsIPrincipal,
|
2021-05-17 23:50:09 +03:00
|
|
|
nsIExpandedPrincipal)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-31 20:56:43 +03:00
|
|
|
ExpandedPrincipal::ExpandedPrincipal(
|
2021-05-17 23:50:09 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIPrincipal>>&& aPrincipals,
|
|
|
|
const nsACString& aOriginNoSuffix, const OriginAttributes& aAttrs)
|
|
|
|
: BasePrincipal(eExpandedPrincipal, aOriginNoSuffix, aAttrs),
|
|
|
|
mPrincipals(std::move(aPrincipals)) {}
|
2017-02-22 12:01:43 +03:00
|
|
|
|
2021-05-17 23:50:09 +03:00
|
|
|
ExpandedPrincipal::~ExpandedPrincipal() = default;
|
2017-02-22 12:01:43 +03:00
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
already_AddRefed<ExpandedPrincipal> ExpandedPrincipal::Create(
|
2021-11-26 18:51:13 +03:00
|
|
|
const nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList,
|
2017-03-22 13:38:17 +03:00
|
|
|
const OriginAttributes& aAttrs) {
|
2021-05-17 23:50:09 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIPrincipal>> principals;
|
|
|
|
for (size_t i = 0; i < aAllowList.Length(); ++i) {
|
2023-03-13 17:52:04 +03:00
|
|
|
principals.AppendElement(aAllowList[i]);
|
2021-05-17 23:50:09 +03:00
|
|
|
}
|
2017-03-29 09:22:26 +03:00
|
|
|
|
|
|
|
nsAutoCString origin;
|
|
|
|
origin.AssignLiteral("[Expanded Principal [");
|
2020-12-17 17:58:18 +03:00
|
|
|
StringJoinAppend(
|
2021-05-17 23:50:09 +03:00
|
|
|
origin, ", "_ns, principals,
|
2020-12-17 17:58:18 +03:00
|
|
|
[](nsACString& dest, const nsCOMPtr<nsIPrincipal>& principal) {
|
|
|
|
nsAutoCString subOrigin;
|
|
|
|
DebugOnly<nsresult> rv = principal->GetOrigin(subOrigin);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
dest.Append(subOrigin);
|
|
|
|
});
|
2017-09-04 08:14:11 +03:00
|
|
|
origin.AppendLiteral("]]");
|
2017-03-29 09:22:26 +03:00
|
|
|
|
2021-05-17 23:50:09 +03:00
|
|
|
RefPtr<ExpandedPrincipal> ep =
|
|
|
|
new ExpandedPrincipal(std::move(principals), origin, aAttrs);
|
2017-02-25 01:02:24 +03:00
|
|
|
return ep.forget();
|
|
|
|
}
|
|
|
|
|
2017-02-22 12:01:43 +03:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:38:17 +03:00
|
|
|
ExpandedPrincipal::GetDomain(nsIURI** aDomain) {
|
2017-02-22 12:01:43 +03:00
|
|
|
*aDomain = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:38:17 +03:00
|
|
|
ExpandedPrincipal::SetDomain(nsIURI* aDomain) { return NS_OK; }
|
2017-02-22 12:01:43 +03:00
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
bool ExpandedPrincipal::SubsumesInternal(
|
|
|
|
nsIPrincipal* aOther,
|
|
|
|
BasePrincipal::DocumentDomainConsideration aConsideration) {
|
2017-02-22 12:01:43 +03:00
|
|
|
// If aOther is an ExpandedPrincipal too, we break it down into its component
|
|
|
|
// nsIPrincipals, and check subsumes on each one.
|
2017-10-11 01:00:16 +03:00
|
|
|
if (Cast(aOther)->Is<ExpandedPrincipal>()) {
|
|
|
|
auto* expanded = Cast(aOther)->As<ExpandedPrincipal>();
|
|
|
|
|
2018-10-31 20:56:43 +03:00
|
|
|
for (auto& other : expanded->AllowList()) {
|
2017-02-22 12:01:43 +03:00
|
|
|
// Use SubsumesInternal rather than Subsumes here, since OriginAttribute
|
|
|
|
// checks are only done between non-expanded sub-principals, and we don't
|
|
|
|
// need to incur the extra virtual call overhead.
|
2017-10-11 01:00:16 +03:00
|
|
|
if (!SubsumesInternal(other, aConsideration)) {
|
2017-02-22 12:01:43 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're dealing with a regular principal. One of our principals must subsume
|
|
|
|
// it.
|
|
|
|
for (uint32_t i = 0; i < mPrincipals.Length(); ++i) {
|
|
|
|
if (Cast(mPrincipals[i])->Subsumes(aOther, aConsideration)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
bool ExpandedPrincipal::MayLoadInternal(nsIURI* uri) {
|
2017-02-22 12:01:43 +03:00
|
|
|
for (uint32_t i = 0; i < mPrincipals.Length(); ++i) {
|
|
|
|
if (BasePrincipal::Cast(mPrincipals[i])->MayLoadInternal(uri)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-20 04:17:52 +03:00
|
|
|
uint32_t ExpandedPrincipal::GetHashValue() {
|
2017-02-22 12:01:43 +03:00
|
|
|
MOZ_CRASH("extended principal should never be used as key in a hash map");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:38:17 +03:00
|
|
|
ExpandedPrincipal::GetURI(nsIURI** aURI) {
|
2017-02-22 12:01:43 +03:00
|
|
|
*aURI = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-10-11 01:00:16 +03:00
|
|
|
const nsTArray<nsCOMPtr<nsIPrincipal>>& ExpandedPrincipal::AllowList() {
|
|
|
|
return mPrincipals;
|
2017-02-22 12:01:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:38:17 +03:00
|
|
|
ExpandedPrincipal::GetBaseDomain(nsACString& aBaseDomain) {
|
2017-02-22 12:01:43 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2016-11-06 08:38:17 +03:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:38:17 +03:00
|
|
|
ExpandedPrincipal::GetAddonId(nsAString& aAddonId) {
|
2016-11-06 08:38:17 +03:00
|
|
|
aAddonId.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
};
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
bool ExpandedPrincipal::AddonHasPermission(const nsAtom* aPerm) {
|
2017-02-22 12:01:43 +03:00
|
|
|
for (size_t i = 0; i < mPrincipals.Length(); ++i) {
|
|
|
|
if (BasePrincipal::Cast(mPrincipals[i])->AddonHasPermission(aPerm)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-04 17:54:26 +03:00
|
|
|
bool ExpandedPrincipal::AddonAllowsLoad(nsIURI* aURI,
|
|
|
|
bool aExplicit /* = false */) {
|
|
|
|
for (const auto& principal : mPrincipals) {
|
|
|
|
if (Cast(principal)->AddonAllowsLoad(aURI, aExplicit)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-02 03:53:50 +03:00
|
|
|
void ExpandedPrincipal::SetCsp(nsIContentSecurityPolicy* aCSP) {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
mCSP = new nsMainThreadPtrHolder<nsIContentSecurityPolicy>(
|
|
|
|
"ExpandedPrincipal::mCSP", aCSP);
|
|
|
|
}
|
2019-05-22 02:14:27 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExpandedPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp) {
|
2022-12-02 03:53:50 +03:00
|
|
|
AssertIsOnMainThread();
|
2019-05-22 02:14:27 +03:00
|
|
|
NS_IF_ADDREF(*aCsp = mCSP);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-23 01:20:26 +03:00
|
|
|
nsIPrincipal* ExpandedPrincipal::PrincipalToInherit(nsIURI* aRequestedURI) {
|
2017-11-03 05:56:27 +03:00
|
|
|
if (aRequestedURI) {
|
2017-11-23 01:20:26 +03:00
|
|
|
// If a given sub-principal subsumes the given URI, use that principal for
|
|
|
|
// inheritance. In general, this only happens with certain CORS modes, loads
|
|
|
|
// with forced principal inheritance, and creation of XML documents from
|
|
|
|
// XMLHttpRequests or fetch requests. For URIs that normally inherit a
|
|
|
|
// principal (such as data: URIs), we fall back to the last principal in the
|
2018-10-31 20:56:43 +03:00
|
|
|
// allowlist.
|
2017-11-03 05:56:27 +03:00
|
|
|
for (const auto& principal : mPrincipals) {
|
2017-11-23 01:20:26 +03:00
|
|
|
if (Cast(principal)->MayLoadInternal(aRequestedURI)) {
|
2017-11-03 05:56:27 +03:00
|
|
|
return principal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mPrincipals.LastElement();
|
|
|
|
}
|
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
nsresult ExpandedPrincipal::GetScriptLocation(nsACString& aStr) {
|
2017-09-04 08:12:56 +03:00
|
|
|
aStr.AssignLiteral("[Expanded Principal [");
|
2017-02-22 12:01:43 +03:00
|
|
|
for (size_t i = 0; i < mPrincipals.Length(); ++i) {
|
|
|
|
if (i != 0) {
|
|
|
|
aStr.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString spec;
|
|
|
|
nsresult rv =
|
|
|
|
nsJSPrincipals::get(mPrincipals.ElementAt(i))->GetScriptLocation(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aStr.Append(spec);
|
|
|
|
}
|
2017-09-04 08:14:11 +03:00
|
|
|
aStr.AppendLiteral("]]");
|
2017-02-22 12:01:43 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
// Methods implementing nsISerializable //
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
2018-05-24 09:43:14 +03:00
|
|
|
// We've had way too many issues with unversioned serializations, so
|
|
|
|
// explicitly version this one.
|
|
|
|
static const uint32_t kSerializationVersion = 1;
|
|
|
|
|
2017-02-22 12:01:43 +03:00
|
|
|
NS_IMETHODIMP
|
2021-05-17 23:50:09 +03:00
|
|
|
ExpandedPrincipal::Deserializer::Read(nsIObjectInputStream* aStream) {
|
2018-05-24 09:43:14 +03:00
|
|
|
uint32_t version;
|
|
|
|
nsresult rv = aStream->Read32(&version);
|
|
|
|
if (version != kSerializationVersion) {
|
|
|
|
MOZ_ASSERT(false,
|
|
|
|
"We really need to add handling of the old(?) version here");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t count;
|
|
|
|
rv = aStream->Read32(&count);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2021-05-17 23:50:09 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIPrincipal>> principals;
|
|
|
|
if (!principals.SetCapacity(count, fallible)) {
|
2018-05-24 09:43:14 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsISupports> read;
|
|
|
|
rv = aStream->ReadObject(true, getter_AddRefs(read));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(read);
|
|
|
|
if (!principal) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2023-03-13 17:52:04 +03:00
|
|
|
principals.AppendElement(std::move(principal));
|
2018-05-24 09:43:14 +03:00
|
|
|
}
|
|
|
|
|
2021-05-17 23:50:09 +03:00
|
|
|
mPrincipal = ExpandedPrincipal::Create(principals, OriginAttributes());
|
2018-05-24 09:43:14 +03:00
|
|
|
return NS_OK;
|
2017-02-22 12:01:43 +03:00
|
|
|
}
|
2018-09-11 12:01:14 +03:00
|
|
|
|
|
|
|
nsresult ExpandedPrincipal::GetSiteIdentifier(SiteIdentifier& aSite) {
|
|
|
|
// Call GetSiteIdentifier on each of our principals and return a new
|
|
|
|
// ExpandedPrincipal.
|
|
|
|
|
2018-10-31 20:56:43 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIPrincipal>> allowlist;
|
2018-09-11 12:01:14 +03:00
|
|
|
for (const auto& principal : mPrincipals) {
|
|
|
|
SiteIdentifier site;
|
|
|
|
nsresult rv = Cast(principal)->GetSiteIdentifier(site);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-10-31 20:56:43 +03:00
|
|
|
allowlist.AppendElement(site.GetPrincipal());
|
2018-09-11 12:01:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ExpandedPrincipal> expandedPrincipal =
|
2018-10-31 20:56:43 +03:00
|
|
|
ExpandedPrincipal::Create(allowlist, OriginAttributesRef());
|
2018-09-11 12:01:14 +03:00
|
|
|
MOZ_ASSERT(expandedPrincipal, "ExpandedPrincipal::Create returned nullptr?");
|
|
|
|
|
|
|
|
aSite.Init(expandedPrincipal);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-06-03 15:37:12 +03:00
|
|
|
|
|
|
|
nsresult ExpandedPrincipal::PopulateJSONObject(Json::Value& aObject) {
|
2023-02-14 13:17:17 +03:00
|
|
|
Json::Value& principalList =
|
|
|
|
aObject[Json::StaticString(JSONEnumKeyString<eSpecs>())] =
|
|
|
|
Json::arrayValue;
|
2023-02-14 13:17:16 +03:00
|
|
|
for (const auto& principal : mPrincipals) {
|
|
|
|
Json::Value object = Json::objectValue;
|
|
|
|
nsresult rv = BasePrincipal::Cast(principal)->ToJSON(object);
|
2020-08-19 20:45:16 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2023-02-14 13:17:16 +03:00
|
|
|
|
2023-02-14 13:17:17 +03:00
|
|
|
principalList.append(std::move(object));
|
2019-06-03 15:37:12 +03:00
|
|
|
}
|
|
|
|
|
2019-06-05 14:27:16 +03:00
|
|
|
nsAutoCString suffix;
|
|
|
|
OriginAttributesRef().CreateSuffix(suffix);
|
|
|
|
if (suffix.Length() > 0) {
|
2023-02-14 13:17:17 +03:00
|
|
|
SetJSONValue<eSuffix>(aObject, suffix);
|
2019-06-05 14:27:16 +03:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:37:12 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<BasePrincipal> ExpandedPrincipal::FromProperties(
|
|
|
|
nsTArray<ExpandedPrincipal::KeyVal>& aFields) {
|
|
|
|
MOZ_ASSERT(aFields.Length() == eMax + 1, "Must have all the keys");
|
|
|
|
nsTArray<nsCOMPtr<nsIPrincipal>> allowList;
|
2019-06-05 14:27:16 +03:00
|
|
|
OriginAttributes attrs;
|
2019-06-03 15:37:12 +03:00
|
|
|
// The odd structure here is to make the code to not compile
|
|
|
|
// if all the switch enum cases haven't been codified
|
2023-02-14 13:17:16 +03:00
|
|
|
|
2019-06-03 15:37:12 +03:00
|
|
|
for (const auto& field : aFields) {
|
|
|
|
switch (field.key) {
|
|
|
|
case ExpandedPrincipal::eSpecs:
|
|
|
|
if (!field.valueWasSerialized) {
|
|
|
|
MOZ_ASSERT(false,
|
|
|
|
"Expanded principals require specs in serialized JSON");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for (const nsACString& each : field.value.Split(',')) {
|
|
|
|
nsAutoCString result;
|
|
|
|
nsresult rv;
|
|
|
|
rv = Base64Decode(each, result);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv), "failed to decode");
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = BasePrincipal::FromJSON(result);
|
|
|
|
allowList.AppendElement(principal);
|
|
|
|
}
|
|
|
|
break;
|
2019-06-05 14:27:16 +03:00
|
|
|
case ExpandedPrincipal::eSuffix:
|
|
|
|
if (field.valueWasSerialized) {
|
|
|
|
bool ok = attrs.PopulateFromSuffix(field.value);
|
|
|
|
if (!ok) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-06-03 15:37:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allowList.Length() == 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ExpandedPrincipal> expandedPrincipal =
|
|
|
|
ExpandedPrincipal::Create(allowList, attrs);
|
|
|
|
|
|
|
|
return expandedPrincipal.forget();
|
|
|
|
}
|
2020-05-13 19:50:19 +03:00
|
|
|
|
2023-02-14 13:17:16 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<BasePrincipal> ExpandedPrincipal::FromProperties(
|
|
|
|
const Json::Value& aJSON) {
|
|
|
|
MOZ_ASSERT(aJSON.size() <= eMax + 1, "Must have at most, all the properties");
|
|
|
|
const std::string specs = std::to_string(eSpecs);
|
|
|
|
const std::string suffix = std::to_string(eSuffix);
|
|
|
|
MOZ_ASSERT(aJSON.isMember(specs), "The eSpecs member is required");
|
|
|
|
MOZ_ASSERT(aJSON.size() == 1 || aJSON.isMember(suffix),
|
|
|
|
"eSuffix is optional");
|
|
|
|
|
|
|
|
const auto* specsValue =
|
|
|
|
aJSON.find(specs.c_str(), specs.c_str() + specs.length());
|
|
|
|
if (!specsValue) {
|
|
|
|
MOZ_ASSERT(false, "Expanded principals require specs in serialized JSON");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsCOMPtr<nsIPrincipal>> allowList;
|
|
|
|
for (const auto& principalJSON : *specsValue) {
|
|
|
|
if (nsCOMPtr<nsIPrincipal> principal =
|
|
|
|
BasePrincipal::FromJSON(principalJSON)) {
|
|
|
|
allowList.AppendElement(principal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allowList.Length() == 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
OriginAttributes attrs;
|
|
|
|
if (aJSON.isMember(suffix)) {
|
|
|
|
const auto& value = aJSON[suffix];
|
|
|
|
if (!value.isString()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = attrs.PopulateFromSuffix(nsDependentCString(value.asCString()));
|
|
|
|
if (!ok) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ExpandedPrincipal> expandedPrincipal =
|
|
|
|
ExpandedPrincipal::Create(allowList, attrs);
|
|
|
|
|
|
|
|
return expandedPrincipal.forget();
|
|
|
|
}
|
|
|
|
|
2020-05-13 19:50:19 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ExpandedPrincipal::IsThirdPartyURI(nsIURI* aURI, bool* aRes) {
|
2020-06-23 14:52:57 +03:00
|
|
|
// ExpandedPrincipal for extension content scripts consist of two principals,
|
|
|
|
// the document's principal and the extension's principal.
|
|
|
|
// To make sure that the third-party check behaves like the web page on which
|
|
|
|
// the content script is running, ignore the extension's principal.
|
|
|
|
|
2020-05-13 19:50:19 +03:00
|
|
|
for (const auto& principal : mPrincipals) {
|
2022-12-02 03:53:53 +03:00
|
|
|
if (!Cast(principal)->AddonPolicyCore()) {
|
2020-06-23 14:52:57 +03:00
|
|
|
return Cast(principal)->IsThirdPartyURI(aURI, aRes);
|
2020-05-13 19:50:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 14:52:57 +03:00
|
|
|
if (mPrincipals.IsEmpty()) {
|
|
|
|
*aRes = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Cast(mPrincipals[0])->IsThirdPartyURI(aURI, aRes);
|
2020-05-13 19:50:19 +03:00
|
|
|
}
|