/* -*- 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/. */
bool ExpandedPrincipal::SubsumesInternal(
nsIPrincipal* aOther,
BasePrincipal::DocumentDomainConsideration aConsideration) { // If aOther is an ExpandedPrincipal too, we break it down into its component // nsIPrincipals, and check subsumes on each one. if (Cast(aOther)->Is<ExpandedPrincipal>()) { auto* expanded = Cast(aOther)->As<ExpandedPrincipal>();
for (auto& other : expanded->AllowList()) { // 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. if (!SubsumesInternal(other, aConsideration)) { returnfalse;
}
} returntrue;
}
// 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)) { returntrue;
}
}
returnfalse;
}
bool ExpandedPrincipal::MayLoadInternal(nsIURI* uri) { for (uint32_t i = 0; i < mPrincipals.Length(); ++i) { if (BasePrincipal::Cast(mPrincipals[i])->MayLoadInternal(uri)) { returntrue;
}
}
returnfalse;
}
uint32_t ExpandedPrincipal::GetHashValue() {
MOZ_CRASH("extended principal should never be used as key in a hash map");
}
nsIPrincipal* ExpandedPrincipal::PrincipalToInherit(nsIURI* aRequestedURI) { if (aRequestedURI) { // 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 // allowlist. for (constauto& principal : mPrincipals) { if (Cast(principal)->MayLoadInternal(aRequestedURI)) { return principal;
}
}
} return mPrincipals.LastElement();
}
nsresult ExpandedPrincipal::GetScriptLocation(nsACString& aStr) {
aStr.AssignLiteral("[Expanded Principal ["); for (size_t i = 0; i < mPrincipals.Length(); ++i) { if (i != 0) {
aStr.AppendLiteral(", ");
}
// We've had way too many issues with unversioned serializations, so // explicitly version this one. staticconst uint32_t kSerializationVersion = 1;
NS_IMETHODIMP
ExpandedPrincipal::Deserializer::Read(nsIObjectInputStream* aStream) {
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;
}
nsresult ExpandedPrincipal::GetSiteIdentifier(SiteIdentifier& aSite) { // Call GetSiteIdentifier on each of our principals and return a new // ExpandedPrincipal.
nsTArray<nsCOMPtr<nsIPrincipal>> allowlist; for (constauto& principal : mPrincipals) {
SiteIdentifier site;
nsresult rv = Cast(principal)->GetSiteIdentifier(site);
NS_ENSURE_SUCCESS(rv, rv);
allowlist.AppendElement(site.GetPrincipal());
}
RefPtr<ExpandedPrincipal> expandedPrincipal =
ExpandedPrincipal::Create(allowlist, OriginAttributesRef());
MOZ_ASSERT(expandedPrincipal, "ExpandedPrincipal::Create returned nullptr?");
NS_IMETHODIMP
ExpandedPrincipal::IsThirdPartyURI(nsIURI* aURI, bool* aRes) { // 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.
for (constauto& principal : mPrincipals) { if (!Cast(principal)->AddonPolicyCore()) { return Cast(principal)->IsThirdPartyURI(aURI, aRes);
}
}
if (mPrincipals.IsEmpty()) {
*aRes = true; return NS_OK;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.