2003-07-24 05:15:20 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-10-14 18:57:26 +00:00
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2012-05-21 11:12:37 +00: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/. */
|
2003-07-24 05:15:20 +00:00
|
|
|
|
2013-08-14 06:56:21 +00:00
|
|
|
#include "nsPrincipal.h"
|
|
|
|
|
2013-01-08 21:53:32 +00:00
|
|
|
#include "mozIThirdPartyUtil.h"
|
2003-07-24 05:15:20 +00:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsScriptSecurityManager.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2013-07-11 20:21:45 +00:00
|
|
|
#include "pratom.h"
|
2003-07-24 05:15:20 +00:00
|
|
|
#include "nsIURI.h"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "nsIURL.h"
|
2015-06-27 00:49:41 +00:00
|
|
|
#include "nsIStandardURL.h"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "nsIURIWithPrincipal.h"
|
2003-07-24 05:15:20 +00:00
|
|
|
#include "nsJSPrincipals.h"
|
2015-03-13 20:15:09 +00:00
|
|
|
#include "nsIEffectiveTLDService.h"
|
2006-03-15 04:59:42 +00:00
|
|
|
#include "nsIClassInfoImpl.h"
|
2014-11-11 09:10:56 +00:00
|
|
|
#include "nsIProtocolHandler.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2010-01-22 21:38:21 +00:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2015-03-13 20:15:09 +00:00
|
|
|
#include "nsNetCID.h"
|
2012-07-12 08:10:15 +00:00
|
|
|
#include "jswrapper.h"
|
2003-07-24 05:15:20 +00:00
|
|
|
|
2014-08-15 01:47:15 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2011-06-20 03:00:16 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-03-12 22:53:18 +00:00
|
|
|
#include "mozilla/HashFunctions.h"
|
2009-06-16 11:00:06 +00:00
|
|
|
|
2012-08-28 02:43:57 +00:00
|
|
|
#include "nsIAppsService.h"
|
|
|
|
#include "mozIApplication.h"
|
|
|
|
|
2011-06-20 03:00:16 +00:00
|
|
|
using namespace mozilla;
|
2009-06-16 11:00:06 +00:00
|
|
|
|
2015-03-13 20:15:09 +00:00
|
|
|
static bool gIsWhitelistingTestDomains = false;
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool gCodeBasePrincipalSupport = false;
|
2009-06-16 11:00:06 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool URIIsImmutable(nsIURI* aURI)
|
2007-06-18 15:07:02 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMutable> mutableObj(do_QueryInterface(aURI));
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isMutable;
|
2007-06-18 15:07:02 +00:00
|
|
|
return
|
|
|
|
mutableObj &&
|
|
|
|
NS_SUCCEEDED(mutableObj->GetMutable(&isMutable)) &&
|
2013-05-31 21:33:51 +00:00
|
|
|
!isMutable;
|
2007-06-18 15:07:02 +00:00
|
|
|
}
|
2003-07-24 05:15:20 +00:00
|
|
|
|
2013-04-03 00:16:25 +00:00
|
|
|
NS_IMPL_CLASSINFO(nsPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
|
2012-06-09 22:19:26 +00:00
|
|
|
NS_PRINCIPAL_CID)
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(nsPrincipal,
|
|
|
|
nsIPrincipal,
|
|
|
|
nsISerializable)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(nsPrincipal,
|
2012-06-09 22:19:26 +00:00
|
|
|
nsIPrincipal,
|
|
|
|
nsISerializable)
|
|
|
|
|
2015-03-13 20:15:09 +00:00
|
|
|
// Called at startup:
|
|
|
|
/* static */ void
|
|
|
|
nsPrincipal::InitializeStatics()
|
|
|
|
{
|
|
|
|
Preferences::AddBoolVarCache(
|
|
|
|
&gIsWhitelistingTestDomains,
|
|
|
|
"layout.css.unprefixing-service.include-test-domains");
|
2015-03-13 20:16:01 +00:00
|
|
|
|
|
|
|
Preferences::AddBoolVarCache(&gCodeBasePrincipalSupport,
|
|
|
|
"signed.applets.codebase_principal_support",
|
|
|
|
false);
|
2015-03-13 20:15:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-09 22:19:26 +00:00
|
|
|
nsPrincipal::nsPrincipal()
|
2015-05-14 01:25:40 +00:00
|
|
|
: mCodebaseImmutable(false)
|
2012-06-10 19:25:17 +00:00
|
|
|
, mDomainImmutable(false)
|
|
|
|
, mInitialized(false)
|
2012-06-09 22:19:26 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
nsPrincipal::~nsPrincipal()
|
|
|
|
{ }
|
|
|
|
|
2012-05-02 21:57:34 +00:00
|
|
|
nsresult
|
2015-05-14 19:24:03 +00:00
|
|
|
nsPrincipal::Init(nsIURI *aCodebase, const OriginAttributes& aOriginAttributes)
|
2012-06-09 22:19:26 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(!mInitialized);
|
2012-10-22 06:29:56 +00:00
|
|
|
NS_ENSURE_ARG(aCodebase);
|
2012-06-09 22:19:26 +00:00
|
|
|
|
|
|
|
mInitialized = true;
|
|
|
|
|
|
|
|
mCodebase = NS_TryToMakeImmutable(aCodebase);
|
|
|
|
mCodebaseImmutable = URIIsImmutable(mCodebase);
|
2015-05-14 19:24:03 +00:00
|
|
|
mOriginAttributes = aOriginAttributes;
|
2012-07-20 05:44:03 +00:00
|
|
|
|
2012-10-22 06:29:56 +00:00
|
|
|
return NS_OK;
|
2012-06-09 22:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPrincipal::GetScriptLocation(nsACString &aStr)
|
|
|
|
{
|
2012-10-22 06:29:56 +00:00
|
|
|
mCodebase->GetSpec(aStr);
|
2012-06-09 22:19:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 04:23:44 +00:00
|
|
|
/* static */ nsresult
|
2015-05-12 22:08:20 +00:00
|
|
|
nsPrincipal::GetOriginForURI(nsIURI* aURI, nsACString& aOrigin)
|
2003-07-24 05:15:20 +00:00
|
|
|
{
|
2012-07-19 04:23:44 +00:00
|
|
|
if (!aURI) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> origin = NS_GetInnermostURI(aURI);
|
2012-06-09 22:19:26 +00:00
|
|
|
if (!origin) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-09-28 14:31:04 +00:00
|
|
|
}
|
2003-07-24 05:15:20 +00:00
|
|
|
|
2015-08-17 19:34:17 +00:00
|
|
|
nsAutoCString hostPort;
|
2012-06-09 22:19:26 +00:00
|
|
|
|
|
|
|
// chrome: URLs don't have a meaningful origin, so make
|
|
|
|
// sure we just get the full spec for them.
|
|
|
|
// XXX this should be removed in favor of the solution in
|
|
|
|
// bug 160042.
|
|
|
|
bool isChrome;
|
|
|
|
nsresult rv = origin->SchemeIs("chrome", &isChrome);
|
|
|
|
if (NS_SUCCEEDED(rv) && !isChrome) {
|
2015-08-17 19:34:17 +00:00
|
|
|
rv = origin->GetAsciiHostPort(hostPort);
|
2012-06-09 22:19:26 +00:00
|
|
|
// Some implementations return an empty string, treat it as no support
|
|
|
|
// for asciiHost by that implementation.
|
2015-08-17 19:34:17 +00:00
|
|
|
if (hostPort.IsEmpty()) {
|
2012-06-09 22:19:26 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2012-07-19 04:23:44 +00:00
|
|
|
}
|
2003-07-24 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2015-06-27 00:49:41 +00:00
|
|
|
// We want the invariant that prinA.origin == prinB.origin i.f.f.
|
|
|
|
// prinA.equals(prinB). However, this requires that we impose certain constraints
|
|
|
|
// on the behavior and origin semantics of principals, and in particular, forbid
|
|
|
|
// creating origin strings for principals whose equality constraints are not
|
|
|
|
// expressible as strings (i.e. object equality). Moreover, we want to forbid URIs
|
|
|
|
// containing the magic "^" we use as a separating character for origin
|
|
|
|
// attributes.
|
|
|
|
//
|
|
|
|
// These constraints can generally be achieved by restricting .origin to
|
|
|
|
// nsIStandardURL-based URIs, but there are a few other URI schemes that we need
|
|
|
|
// to handle.
|
|
|
|
bool isBehaved;
|
|
|
|
if ((NS_SUCCEEDED(origin->SchemeIs("about", &isBehaved)) && isBehaved) ||
|
|
|
|
(NS_SUCCEEDED(origin->SchemeIs("moz-safe-about", &isBehaved)) && isBehaved) ||
|
|
|
|
(NS_SUCCEEDED(origin->SchemeIs("indexeddb", &isBehaved)) && isBehaved)) {
|
|
|
|
rv = origin->GetAsciiSpec(aOrigin);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// These URIs could technically contain a '^', but they never should.
|
|
|
|
if (NS_WARN_IF(aOrigin.FindChar('^', 0) != -1)) {
|
|
|
|
aOrigin.Truncate();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-09 22:19:26 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && !isChrome) {
|
2015-05-12 22:08:20 +00:00
|
|
|
rv = origin->GetScheme(aOrigin);
|
2012-06-09 22:19:26 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-05-12 22:08:20 +00:00
|
|
|
aOrigin.AppendLiteral("://");
|
|
|
|
aOrigin.Append(hostPort);
|
2012-06-09 22:19:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-06-27 00:49:41 +00:00
|
|
|
// If we reached this branch, we can only create an origin if we have a nsIStandardURL.
|
|
|
|
// So, we query to a nsIStandardURL, and fail if we aren't an instance of an nsIStandardURL
|
|
|
|
// nsIStandardURLs have the good property of escaping the '^' character in their specs,
|
|
|
|
// which means that we can be sure that the caret character (which is reserved for delimiting
|
|
|
|
// the end of the spec, and the beginning of the origin attributes) is not present in the
|
|
|
|
// origin string
|
|
|
|
nsCOMPtr<nsIStandardURL> standardURL = do_QueryInterface(origin);
|
|
|
|
NS_ENSURE_TRUE(standardURL, NS_ERROR_FAILURE);
|
2015-05-12 22:08:20 +00:00
|
|
|
rv = origin->GetAsciiSpec(aOrigin);
|
2012-06-09 22:19:26 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-07-24 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2015-05-12 22:08:20 +00:00
|
|
|
return NS_OK;
|
2003-07-24 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 23:50:44 +00:00
|
|
|
nsresult
|
|
|
|
nsPrincipal::GetOriginInternal(nsACString& aOrigin)
|
2012-07-19 04:23:44 +00:00
|
|
|
{
|
|
|
|
return GetOriginForURI(mCodebase, aOrigin);
|
|
|
|
}
|
|
|
|
|
2015-05-14 18:15:56 +00:00
|
|
|
bool
|
|
|
|
nsPrincipal::SubsumesInternal(nsIPrincipal* aOther,
|
|
|
|
BasePrincipal::DocumentDomainConsideration aConsideration)
|
2003-07-24 05:15:20 +00:00
|
|
|
{
|
2015-05-14 18:15:56 +00:00
|
|
|
MOZ_ASSERT(aOther);
|
2012-06-09 22:19:26 +00:00
|
|
|
|
2015-05-14 18:15:56 +00:00
|
|
|
// For nsPrincipal, Subsumes is equivalent to Equals.
|
2012-10-24 17:50:25 +00:00
|
|
|
if (aOther == this) {
|
2015-05-14 18:15:56 +00:00
|
|
|
return true;
|
2003-07-24 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 19:24:03 +00:00
|
|
|
if (OriginAttributesRef() != Cast(aOther)->OriginAttributesRef()) {
|
|
|
|
return false;
|
2014-02-14 02:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If either the subject or the object has changed its principal by
|
|
|
|
// explicitly setting document.domain then the other must also have
|
|
|
|
// done so in order to be considered the same origin. This prevents
|
|
|
|
// DNS spoofing based on document.domain (154930)
|
2015-05-14 18:15:56 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (aConsideration == ConsiderDocumentDomain) {
|
|
|
|
// Get .domain on each principal.
|
|
|
|
nsCOMPtr<nsIURI> thisDomain, otherDomain;
|
|
|
|
GetDomain(getter_AddRefs(thisDomain));
|
|
|
|
aOther->GetDomain(getter_AddRefs(otherDomain));
|
|
|
|
|
|
|
|
// If either has .domain set, we have equality i.f.f. the domains match.
|
|
|
|
// Otherwise, we fall through to the non-document-domain-considering case.
|
|
|
|
if (thisDomain || otherDomain) {
|
|
|
|
return nsScriptSecurityManager::SecurityCompareURIs(thisDomain, otherDomain);
|
|
|
|
}
|
2003-07-24 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 18:15:56 +00:00
|
|
|
nsCOMPtr<nsIURI> otherURI;
|
|
|
|
rv = aOther->GetURI(getter_AddRefs(otherURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2012-06-09 22:19:26 +00:00
|
|
|
|
|
|
|
// Compare codebases.
|
2015-05-14 18:15:56 +00:00
|
|
|
return nsScriptSecurityManager::SecurityCompareURIs(mCodebase, otherURI);
|
2014-02-14 02:57:34 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 05:15:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetURI(nsIURI** aURI)
|
|
|
|
{
|
2007-06-18 15:07:02 +00:00
|
|
|
if (mCodebaseImmutable) {
|
|
|
|
NS_ADDREF(*aURI = mCodebase);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-20 03:17:41 +00:00
|
|
|
if (!mCodebase) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aURI = nullptr;
|
2006-06-20 03:17:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-07-24 05:15:20 +00:00
|
|
|
|
2006-06-20 03:17:41 +00:00
|
|
|
return NS_EnsureSafeToReturn(mCodebase, aURI);
|
2003-07-24 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-20 18:34:33 +00:00
|
|
|
nsPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport, bool aAllowIfInheritsPrincipal)
|
2003-07-24 05:15:20 +00:00
|
|
|
{
|
2012-08-20 18:34:33 +00:00
|
|
|
if (aAllowIfInheritsPrincipal) {
|
|
|
|
// If the caller specified to allow loads of URIs that inherit
|
|
|
|
// our principal, allow the load if this URI inherits its principal
|
|
|
|
if (nsPrincipal::IsPrincipalInherited(aURI)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 08:21:17 +00:00
|
|
|
// See if aURI is something like a Blob URI that is actually associated with
|
|
|
|
// a principal.
|
|
|
|
nsCOMPtr<nsIURIWithPrincipal> uriWithPrin = do_QueryInterface(aURI);
|
|
|
|
nsCOMPtr<nsIPrincipal> uriPrin;
|
|
|
|
if (uriWithPrin) {
|
|
|
|
uriWithPrin->GetPrincipal(getter_AddRefs(uriPrin));
|
|
|
|
}
|
|
|
|
if (uriPrin && nsIPrincipal::Subsumes(uriPrin)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-08 00:53:15 +00:00
|
|
|
// If this principal is associated with an addon, check whether that addon
|
|
|
|
// has been given permission to load from this domain.
|
|
|
|
if (AddonAllowsLoad(aURI)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-31 21:33:51 +00:00
|
|
|
if (nsScriptSecurityManager::SecurityCompareURIs(mCodebase, aURI)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-08 21:53:32 +00:00
|
|
|
|
2013-05-31 21:33:51 +00:00
|
|
|
// If strict file origin policy is in effect, local files will always fail
|
|
|
|
// SecurityCompareURIs unless they are identical. Explicitly check file origin
|
|
|
|
// policy, in that case.
|
|
|
|
if (nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
|
|
|
|
NS_URIIsLocalFile(aURI) &&
|
|
|
|
NS_RelaxStrictFileOriginPolicy(aURI, mCodebase)) {
|
|
|
|
return NS_OK;
|
2005-07-22 19:05:42 +00:00
|
|
|
}
|
2012-06-09 22:19:26 +00:00
|
|
|
|
2013-05-31 21:33:51 +00:00
|
|
|
if (aReport) {
|
|
|
|
nsScriptSecurityManager::ReportError(nullptr, NS_LITERAL_STRING("CheckSameOriginError"), mCodebase, aURI);
|
|
|
|
}
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
2005-07-22 19:05:42 +00:00
|
|
|
}
|
2003-07-24 05:15:20 +00:00
|
|
|
|
2012-06-09 22:19:26 +00:00
|
|
|
void
|
|
|
|
nsPrincipal::SetURI(nsIURI* aURI)
|
2010-01-22 21:38:21 +00:00
|
|
|
{
|
2012-06-09 22:19:26 +00:00
|
|
|
mCodebase = NS_TryToMakeImmutable(aURI);
|
|
|
|
mCodebaseImmutable = URIIsImmutable(mCodebase);
|
2010-01-22 21:38:21 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 05:15:20 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrincipal::GetHashValue(uint32_t* aValue)
|
2003-07-24 05:15:20 +00:00
|
|
|
{
|
2012-10-22 06:29:56 +00:00
|
|
|
NS_PRECONDITION(mCodebase, "Need a codebase");
|
2003-07-24 05:15:20 +00:00
|
|
|
|
2012-10-22 06:29:56 +00:00
|
|
|
*aValue = nsScriptSecurityManager::HashPrincipalByOrigin(this);
|
2003-07-24 05:15:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetDomain(nsIURI** aDomain)
|
|
|
|
{
|
2006-06-20 03:17:41 +00:00
|
|
|
if (!mDomain) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aDomain = nullptr;
|
2006-06-20 03:17:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-07-24 05:15:20 +00:00
|
|
|
|
2007-06-18 15:07:02 +00:00
|
|
|
if (mDomainImmutable) {
|
|
|
|
NS_ADDREF(*aDomain = mDomain);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-20 03:17:41 +00:00
|
|
|
return NS_EnsureSafeToReturn(mDomain, aDomain);
|
2003-07-24 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::SetDomain(nsIURI* aDomain)
|
|
|
|
{
|
2006-06-20 03:17:41 +00:00
|
|
|
mDomain = NS_TryToMakeImmutable(aDomain);
|
2007-06-18 15:07:02 +00:00
|
|
|
mDomainImmutable = URIIsImmutable(mDomain);
|
2013-01-08 21:53:32 +00:00
|
|
|
|
2012-07-12 08:10:15 +00:00
|
|
|
// Recompute all wrappers between compartments using this principal and other
|
|
|
|
// non-chrome compartments.
|
2013-05-06 13:04:17 +00:00
|
|
|
AutoSafeJSContext cx;
|
2012-07-12 08:10:15 +00:00
|
|
|
JSPrincipals *principals = nsJSPrincipals::get(static_cast<nsIPrincipal*>(this));
|
|
|
|
bool success = js::RecomputeWrappers(cx, js::ContentCompartmentsOnly(),
|
|
|
|
js::CompartmentsWithPrincipals(principals));
|
|
|
|
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
|
|
|
|
success = js::RecomputeWrappers(cx, js::CompartmentsWithPrincipals(principals),
|
|
|
|
js::ContentCompartmentsOnly());
|
|
|
|
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
|
|
|
|
|
2003-07-24 05:15:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 21:53:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
|
|
|
{
|
|
|
|
// For a file URI, we return the file path.
|
2013-05-31 21:33:51 +00:00
|
|
|
if (NS_URIIsLocalFile(mCodebase)) {
|
2013-01-08 21:53:32 +00:00
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(mCodebase);
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
return url->GetFilePath(aBaseDomain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-11 09:10:56 +00:00
|
|
|
bool hasNoRelativeFlag;
|
|
|
|
nsresult rv = NS_URIChainHasFlags(mCodebase,
|
|
|
|
nsIProtocolHandler::URI_NORELATIVE,
|
|
|
|
&hasNoRelativeFlag);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasNoRelativeFlag) {
|
|
|
|
return mCodebase->GetSpec(aBaseDomain);
|
|
|
|
}
|
|
|
|
|
2013-01-08 21:53:32 +00:00
|
|
|
// For everything else, we ask the TLD service via
|
|
|
|
// the ThirdPartyUtil.
|
|
|
|
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
|
|
|
|
do_GetService(THIRDPARTYUTIL_CONTRACTID);
|
|
|
|
if (thirdPartyUtil) {
|
|
|
|
return thirdPartyUtil->GetBaseDomain(mCodebase, aBaseDomain);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-07-24 05:15:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
2014-03-15 19:00:17 +00:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
2007-09-17 22:18:28 +00:00
|
|
|
nsCOMPtr<nsIURI> codebase;
|
2014-03-15 19:00:17 +00:00
|
|
|
nsresult rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
|
2007-09-17 22:18:28 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2003-07-24 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2014-03-15 19:00:17 +00:00
|
|
|
codebase = do_QueryInterface(supports);
|
|
|
|
|
2012-07-26 00:12:03 +00:00
|
|
|
nsCOMPtr<nsIURI> domain;
|
2014-03-15 19:00:17 +00:00
|
|
|
rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
|
2012-07-26 00:12:03 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-03-15 19:00:17 +00:00
|
|
|
domain = do_QueryInterface(supports);
|
|
|
|
|
2015-06-04 18:51:57 +00:00
|
|
|
nsAutoCString suffix;
|
|
|
|
rv = aStream->ReadCString(suffix);
|
2015-06-05 11:07:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-06-04 18:51:57 +00:00
|
|
|
|
2015-06-04 18:51:57 +00:00
|
|
|
OriginAttributes attrs;
|
|
|
|
bool ok = attrs.PopulateFromSuffix(suffix);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
|
|
|
|
|
2014-03-15 19:00:17 +00:00
|
|
|
rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
|
2014-01-23 23:34:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-03-15 19:00:17 +00:00
|
|
|
// This may be null.
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp = do_QueryInterface(supports, &rv);
|
|
|
|
|
2015-05-14 19:24:03 +00:00
|
|
|
rv = Init(codebase, attrs);
|
2007-09-17 22:18:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-01-23 23:34:59 +00:00
|
|
|
rv = SetCsp(csp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-07-30 21:37:22 +00:00
|
|
|
// need to link in the CSP context here (link in the URI of the protected
|
|
|
|
// resource).
|
2014-01-23 23:34:59 +00:00
|
|
|
if (csp) {
|
2014-07-30 21:37:22 +00:00
|
|
|
csp->SetRequestContext(codebase, nullptr, nullptr);
|
2014-01-23 23:34:59 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 22:18:28 +00:00
|
|
|
SetDomain(domain);
|
|
|
|
|
2003-07-24 05:15:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
2012-10-22 06:29:56 +00:00
|
|
|
NS_ENSURE_STATE(mCodebase);
|
2007-09-17 22:18:28 +00:00
|
|
|
|
2012-10-22 06:29:56 +00:00
|
|
|
nsresult rv = NS_WriteOptionalCompoundObject(aStream, mCodebase, NS_GET_IID(nsIURI),
|
|
|
|
true);
|
2007-09-17 22:18:28 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2003-07-24 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 22:18:28 +00:00
|
|
|
rv = NS_WriteOptionalCompoundObject(aStream, mDomain, NS_GET_IID(nsIURI),
|
2011-10-17 14:59:28 +00:00
|
|
|
true);
|
2003-07-24 05:15:20 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-06-04 18:51:57 +00:00
|
|
|
nsAutoCString suffix;
|
|
|
|
OriginAttributesRef().CreateSuffix(suffix);
|
|
|
|
|
|
|
|
rv = aStream->WriteStringZ(suffix.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-07-20 05:44:03 +00:00
|
|
|
|
2014-01-23 23:34:59 +00:00
|
|
|
rv = NS_WriteOptionalCompoundObject(aStream, mCSP,
|
|
|
|
NS_GET_IID(nsIContentSecurityPolicy),
|
|
|
|
true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-09-17 22:18:28 +00:00
|
|
|
// mCodebaseImmutable and mDomainImmutable will be recomputed based
|
|
|
|
// on the deserialized URIs in Read().
|
|
|
|
|
2003-07-24 05:15:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-06-09 22:19:26 +00:00
|
|
|
|
2015-03-13 20:15:09 +00:00
|
|
|
// Helper-function to indicate whether the CSS Unprefixing Service
|
|
|
|
// whitelist should include dummy domains that are only intended for
|
|
|
|
// use in testing. (Controlled by a pref.)
|
|
|
|
static inline bool
|
|
|
|
IsWhitelistingTestDomains()
|
|
|
|
{
|
|
|
|
return gIsWhitelistingTestDomains;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks if the given URI's host is on our "full domain" whitelist
|
|
|
|
// (i.e. if it's an exact match against a domain that needs unprefixing)
|
|
|
|
static bool
|
|
|
|
IsOnFullDomainWhitelist(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
nsAutoCString hostStr;
|
|
|
|
nsresult rv = aURI->GetHost(hostStr);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
// NOTE: This static whitelist is expected to be short. If that changes,
|
|
|
|
// we should consider a different representation; e.g. hash-set, prefix tree.
|
|
|
|
static const nsLiteralCString sFullDomainsOnWhitelist[] = {
|
|
|
|
// 0th entry only active when testing:
|
|
|
|
NS_LITERAL_CSTRING("test1.example.org"),
|
|
|
|
NS_LITERAL_CSTRING("map.baidu.com"),
|
|
|
|
NS_LITERAL_CSTRING("3g.163.com"),
|
|
|
|
NS_LITERAL_CSTRING("3glogo.gtimg.com"), // for 3g.163.com
|
|
|
|
NS_LITERAL_CSTRING("info.3g.qq.com"), // for 3g.qq.com
|
|
|
|
NS_LITERAL_CSTRING("3gimg.qq.com"), // for 3g.qq.com
|
|
|
|
NS_LITERAL_CSTRING("img.m.baidu.com"), // for [shucheng|ks].baidu.com
|
|
|
|
NS_LITERAL_CSTRING("m.mogujie.com"),
|
|
|
|
NS_LITERAL_CSTRING("touch.qunar.com"),
|
2015-05-05 16:04:23 +00:00
|
|
|
NS_LITERAL_CSTRING("mjs.sinaimg.cn"), // for sina.cn
|
|
|
|
NS_LITERAL_CSTRING("static.qiyi.com"), // for m.iqiyi.com
|
2015-05-08 16:08:27 +00:00
|
|
|
NS_LITERAL_CSTRING("cdn.kuaidi100.com"), // for m.kuaidi100.com
|
2015-05-05 16:04:23 +00:00
|
|
|
NS_LITERAL_CSTRING("m.pc6.com"),
|
|
|
|
NS_LITERAL_CSTRING("m.haosou.com"),
|
|
|
|
NS_LITERAL_CSTRING("m.mi.com"),
|
|
|
|
NS_LITERAL_CSTRING("wappass.baidu.com"),
|
|
|
|
NS_LITERAL_CSTRING("m.video.baidu.com"),
|
|
|
|
NS_LITERAL_CSTRING("m.video.baidu.com"),
|
|
|
|
NS_LITERAL_CSTRING("imgcache.gtimg.cn"), // for m.v.qq.com
|
2015-06-09 01:26:00 +00:00
|
|
|
NS_LITERAL_CSTRING("s.tabelog.jp"),
|
|
|
|
NS_LITERAL_CSTRING("s.yimg.jp"), // for s.tabelog.jp
|
2015-05-07 16:04:42 +00:00
|
|
|
NS_LITERAL_CSTRING("i.yimg.jp"), // for *.yahoo.co.jp
|
|
|
|
NS_LITERAL_CSTRING("ai.yimg.jp"), // for *.yahoo.co.jp
|
2015-06-09 01:26:00 +00:00
|
|
|
NS_LITERAL_CSTRING("m.finance.yahoo.co.jp"),
|
2015-05-07 16:04:42 +00:00
|
|
|
NS_LITERAL_CSTRING("daily.c.yimg.jp"), // for sp.daily.co.jp
|
|
|
|
NS_LITERAL_CSTRING("stat100.ameba.jp"), // for ameblo.jp
|
|
|
|
NS_LITERAL_CSTRING("user.ameba.jp"), // for ameblo.jp
|
|
|
|
NS_LITERAL_CSTRING("www.goo.ne.jp"),
|
|
|
|
NS_LITERAL_CSTRING("x.gnst.jp"), // for mobile.gnavi.co.jp
|
|
|
|
NS_LITERAL_CSTRING("c.x.gnst.jp"), // for mobile.gnavi.co.jp
|
|
|
|
NS_LITERAL_CSTRING("www.smbc-card.com"),
|
|
|
|
NS_LITERAL_CSTRING("static.card.jp.rakuten-static.com"), // for rakuten-card.co.jp
|
2015-06-09 01:26:00 +00:00
|
|
|
NS_LITERAL_CSTRING("img.travel.rakuten.co.jp"), // for travel.rakuten.co.jp
|
2015-05-07 16:04:42 +00:00
|
|
|
NS_LITERAL_CSTRING("img.mixi.net"), // for mixi.jp
|
|
|
|
NS_LITERAL_CSTRING("girlschannel.net"),
|
|
|
|
NS_LITERAL_CSTRING("www.fancl.co.jp"),
|
|
|
|
NS_LITERAL_CSTRING("s.cosme.net"),
|
|
|
|
NS_LITERAL_CSTRING("www.sapporobeer.jp"),
|
|
|
|
NS_LITERAL_CSTRING("www.mapion.co.jp"),
|
|
|
|
NS_LITERAL_CSTRING("touch.navitime.co.jp"),
|
|
|
|
NS_LITERAL_CSTRING("sp.mbga.jp"),
|
|
|
|
NS_LITERAL_CSTRING("ava-a.sp.mbga.jp"), // for sp.mbga.jp
|
|
|
|
NS_LITERAL_CSTRING("www.ntv.co.jp"),
|
|
|
|
NS_LITERAL_CSTRING("mobile.suntory.co.jp"), // for suntory.jp
|
|
|
|
NS_LITERAL_CSTRING("www.aeonsquare.net"),
|
|
|
|
NS_LITERAL_CSTRING("mw.nikkei.com"),
|
|
|
|
NS_LITERAL_CSTRING("www.nhk.or.jp"),
|
|
|
|
NS_LITERAL_CSTRING("www.tokyo-sports.co.jp"),
|
2015-05-14 14:32:00 +00:00
|
|
|
NS_LITERAL_CSTRING("www.bellemaison.jp"),
|
|
|
|
NS_LITERAL_CSTRING("www.kuronekoyamato.co.jp"),
|
|
|
|
NS_LITERAL_CSTRING("formassist.jp"), // for orico.jp
|
2015-05-20 17:04:00 +00:00
|
|
|
NS_LITERAL_CSTRING("sp.m.reuters.co.jp"),
|
|
|
|
NS_LITERAL_CSTRING("www.atre.co.jp"),
|
|
|
|
NS_LITERAL_CSTRING("www.jtb.co.jp"),
|
|
|
|
NS_LITERAL_CSTRING("www.sharp.co.jp"),
|
|
|
|
NS_LITERAL_CSTRING("www.biccamera.com"),
|
2015-06-09 01:26:00 +00:00
|
|
|
NS_LITERAL_CSTRING("weathernews.jp"),
|
|
|
|
NS_LITERAL_CSTRING("cache.ymail.jp"), // for www.yamada-denkiweb.com
|
2015-03-13 20:15:09 +00:00
|
|
|
};
|
|
|
|
static const size_t sNumFullDomainsOnWhitelist =
|
|
|
|
MOZ_ARRAY_LENGTH(sFullDomainsOnWhitelist);
|
|
|
|
|
|
|
|
// Skip 0th (dummy) entry in whitelist, unless a pref is enabled.
|
|
|
|
const size_t firstWhitelistIdx = IsWhitelistingTestDomains() ? 0 : 1;
|
|
|
|
|
|
|
|
for (size_t i = firstWhitelistIdx; i < sNumFullDomainsOnWhitelist; ++i) {
|
|
|
|
if (hostStr == sFullDomainsOnWhitelist[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks if the given URI's host is on our "base domain" whitelist
|
|
|
|
// (i.e. if it's a subdomain of some host that we've whitelisted as needing
|
|
|
|
// unprefixing for all its subdomains)
|
|
|
|
static bool
|
|
|
|
IsOnBaseDomainWhitelist(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
static const nsLiteralCString sBaseDomainsOnWhitelist[] = {
|
|
|
|
// 0th entry only active when testing:
|
|
|
|
NS_LITERAL_CSTRING("test2.example.org"),
|
|
|
|
NS_LITERAL_CSTRING("tbcdn.cn"), // for m.taobao.com
|
2015-05-19 17:38:06 +00:00
|
|
|
NS_LITERAL_CSTRING("alicdn.com"), // for m.taobao.com
|
2015-03-13 20:15:09 +00:00
|
|
|
NS_LITERAL_CSTRING("dpfile.com"), // for m.dianping.com
|
|
|
|
NS_LITERAL_CSTRING("hao123img.com"), // for hao123.com
|
2015-05-20 17:04:00 +00:00
|
|
|
NS_LITERAL_CSTRING("tabelog.k-img.com"), // for s.tabelog.com
|
2015-06-09 01:26:00 +00:00
|
|
|
NS_LITERAL_CSTRING("tsite.jp"), // for *.tsite.jp
|
2015-03-13 20:15:09 +00:00
|
|
|
};
|
|
|
|
static const size_t sNumBaseDomainsOnWhitelist =
|
|
|
|
MOZ_ARRAY_LENGTH(sBaseDomainsOnWhitelist);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEffectiveTLDService> tldService =
|
|
|
|
do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (tldService) {
|
|
|
|
// Skip 0th test-entry in whitelist, unless the testing pref is enabled.
|
|
|
|
const size_t firstWhitelistIdx = IsWhitelistingTestDomains() ? 0 : 1;
|
|
|
|
|
|
|
|
// Right now, the test base-domain "test2.example.org" is the only entry in
|
|
|
|
// its whitelist with a nonzero "depth". So we'll only bother going beyond
|
|
|
|
// 0 depth (to 1) if that entry is enabled. (No point in slowing down the
|
|
|
|
// normal codepath, for the benefit of a disabled test domain.) If we add a
|
|
|
|
// "real" base-domain with a depth of >= 1 to our whitelist, we can get rid
|
|
|
|
// of this conditional & just make this a static variable.
|
|
|
|
const uint32_t maxSubdomainDepth = IsWhitelistingTestDomains() ? 1 : 0;
|
|
|
|
|
|
|
|
for (uint32_t subdomainDepth = 0;
|
|
|
|
subdomainDepth <= maxSubdomainDepth; ++subdomainDepth) {
|
|
|
|
|
|
|
|
// Get the base domain (to depth |subdomainDepth|) from passed-in URI:
|
|
|
|
nsAutoCString baseDomainStr;
|
|
|
|
nsresult rv = tldService->GetBaseDomain(aURI, subdomainDepth,
|
|
|
|
baseDomainStr);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// aURI doesn't have |subdomainDepth| levels of subdomains. If we got
|
|
|
|
// here without a match yet, then aURI is not on our whitelist.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare the base domain against each entry in our whitelist:
|
|
|
|
for (size_t i = firstWhitelistIdx; i < sNumBaseDomainsOnWhitelist; ++i) {
|
|
|
|
if (baseDomainStr == sBaseDomainsOnWhitelist[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The actual (non-cached) implementation of IsOnCSSUnprefixingWhitelist():
|
|
|
|
static bool
|
|
|
|
IsOnCSSUnprefixingWhitelistImpl(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
// Check scheme, so we can drop any non-HTTP/HTTPS URIs right away
|
|
|
|
nsAutoCString schemeStr;
|
|
|
|
nsresult rv = aURI->GetScheme(schemeStr);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
// Only proceed if scheme is "http" or "https"
|
|
|
|
if (!(StringBeginsWith(schemeStr, NS_LITERAL_CSTRING("http")) &&
|
|
|
|
(schemeStr.Length() == 4 ||
|
|
|
|
(schemeStr.Length() == 5 && schemeStr[4] == 's')))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (IsOnFullDomainWhitelist(aURI) ||
|
|
|
|
IsOnBaseDomainWhitelist(aURI));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPrincipal::IsOnCSSUnprefixingWhitelist()
|
|
|
|
{
|
|
|
|
if (mIsOnCSSUnprefixingWhitelist.isNothing()) {
|
|
|
|
// Value not cached -- perform our lazy whitelist-check.
|
|
|
|
// (NOTE: If our URI is mutable, we just assume it's not on the whitelist,
|
|
|
|
// since our caching strategy won't work. This isn't expected to be common.)
|
|
|
|
mIsOnCSSUnprefixingWhitelist.emplace(
|
|
|
|
mCodebaseImmutable &&
|
|
|
|
IsOnCSSUnprefixingWhitelistImpl(mCodebase));
|
|
|
|
}
|
|
|
|
|
|
|
|
return *mIsOnCSSUnprefixingWhitelist;
|
|
|
|
}
|
|
|
|
|
2012-06-09 22:19:26 +00:00
|
|
|
/************************************************************************************************************************/
|
|
|
|
|
2013-04-03 00:16:25 +00:00
|
|
|
NS_IMPL_CLASSINFO(nsExpandedPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
|
2012-06-09 22:19:26 +00:00
|
|
|
NS_EXPANDEDPRINCIPAL_CID)
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(nsExpandedPrincipal,
|
|
|
|
nsIPrincipal,
|
|
|
|
nsIExpandedPrincipal)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(nsExpandedPrincipal,
|
2012-06-09 22:19:26 +00:00
|
|
|
nsIPrincipal,
|
|
|
|
nsIExpandedPrincipal)
|
|
|
|
|
2015-05-12 23:46:21 +00:00
|
|
|
struct OriginComparator
|
|
|
|
{
|
|
|
|
bool LessThan(nsIPrincipal* a, nsIPrincipal* b) const
|
|
|
|
{
|
|
|
|
nsAutoCString originA;
|
|
|
|
nsresult rv = a->GetOrigin(originA);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
nsAutoCString originB;
|
|
|
|
rv = b->GetOrigin(originB);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
return originA < originB;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Equals(nsIPrincipal* a, nsIPrincipal* b) const
|
|
|
|
{
|
|
|
|
nsAutoCString originA;
|
|
|
|
nsresult rv = a->GetOrigin(originA);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
nsAutoCString originB;
|
|
|
|
rv = b->GetOrigin(originB);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-09 22:19:26 +00:00
|
|
|
nsExpandedPrincipal::nsExpandedPrincipal(nsTArray<nsCOMPtr <nsIPrincipal> > &aWhiteList)
|
|
|
|
{
|
2015-05-12 23:46:21 +00:00
|
|
|
// We force the principals to be sorted by origin so that nsExpandedPrincipal
|
|
|
|
// origins can have a canonical form.
|
|
|
|
OriginComparator c;
|
|
|
|
for (size_t i = 0; i < aWhiteList.Length(); ++i) {
|
|
|
|
mPrincipals.InsertElementSorted(aWhiteList[i], c);
|
|
|
|
}
|
2012-06-09 22:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsExpandedPrincipal::~nsExpandedPrincipal()
|
|
|
|
{ }
|
|
|
|
|
2013-01-08 21:53:32 +00:00
|
|
|
NS_IMETHODIMP
|
2012-06-09 22:19:26 +00:00
|
|
|
nsExpandedPrincipal::GetDomain(nsIURI** aDomain)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aDomain = nullptr;
|
2012-06-09 22:19:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 21:53:32 +00:00
|
|
|
NS_IMETHODIMP
|
2012-06-09 22:19:26 +00:00
|
|
|
nsExpandedPrincipal::SetDomain(nsIURI* aDomain)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-14 23:50:44 +00:00
|
|
|
nsresult
|
|
|
|
nsExpandedPrincipal::GetOriginInternal(nsACString& aOrigin)
|
2012-06-09 22:19:26 +00:00
|
|
|
{
|
2015-05-12 22:45:54 +00:00
|
|
|
aOrigin.AssignLiteral("[Expanded Principal [");
|
|
|
|
for (size_t i = 0; i < mPrincipals.Length(); ++i) {
|
|
|
|
if (i != 0) {
|
|
|
|
aOrigin.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString subOrigin;
|
|
|
|
nsresult rv = mPrincipals.ElementAt(i)->GetOrigin(subOrigin);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
aOrigin.Append(subOrigin);
|
|
|
|
}
|
|
|
|
|
|
|
|
aOrigin.Append("]]");
|
2015-05-12 22:08:20 +00:00
|
|
|
return NS_OK;
|
2012-06-09 22:19:26 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 18:15:56 +00:00
|
|
|
bool
|
|
|
|
nsExpandedPrincipal::SubsumesInternal(nsIPrincipal* aOther,
|
|
|
|
BasePrincipal::DocumentDomainConsideration aConsideration)
|
2012-06-09 22:19:26 +00:00
|
|
|
{
|
2015-05-14 18:15:56 +00:00
|
|
|
// If aOther is an ExpandedPrincipal too, we break it down into its component
|
|
|
|
// nsIPrincipals, and check subsumes on each one.
|
2013-01-08 21:53:32 +00:00
|
|
|
nsCOMPtr<nsIExpandedPrincipal> expanded = do_QueryInterface(aOther);
|
2012-06-09 22:19:26 +00:00
|
|
|
if (expanded) {
|
|
|
|
nsTArray< nsCOMPtr<nsIPrincipal> >* otherList;
|
|
|
|
expanded->GetWhiteList(&otherList);
|
|
|
|
for (uint32_t i = 0; i < otherList->Length(); ++i){
|
2015-05-14 18:15:56 +00:00
|
|
|
if (!SubsumesInternal((*otherList)[i], aConsideration)) {
|
|
|
|
return false;
|
2012-06-09 22:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-14 18:15:56 +00:00
|
|
|
return true;
|
2012-06-09 22:19:26 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 18:15:56 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
2012-06-09 22:19:26 +00:00
|
|
|
|
2015-05-14 18:15:56 +00:00
|
|
|
return false;
|
2014-02-14 02:57:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-09 22:19:26 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-20 18:34:33 +00:00
|
|
|
nsExpandedPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal)
|
2012-06-09 22:19:26 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
for (uint32_t i = 0; i < mPrincipals.Length(); ++i){
|
2012-08-20 18:34:33 +00:00
|
|
|
rv = mPrincipals[i]->CheckMayLoad(uri, aReport, aAllowIfInheritsPrincipal);
|
2012-06-09 22:19:26 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsExpandedPrincipal::GetHashValue(uint32_t* result)
|
2012-06-09 22:19:26 +00:00
|
|
|
{
|
2013-06-29 01:38:30 +00:00
|
|
|
MOZ_CRASH("extended principal should never be used as key in a hash map");
|
2012-06-09 22:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetURI(nsIURI** aURI)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aURI = nullptr;
|
2012-06-09 22:19:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 21:53:32 +00:00
|
|
|
NS_IMETHODIMP
|
2012-06-09 22:19:26 +00:00
|
|
|
nsExpandedPrincipal::GetWhiteList(nsTArray<nsCOMPtr<nsIPrincipal> >** aWhiteList)
|
|
|
|
{
|
|
|
|
*aWhiteList = &mPrincipals;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 21:53:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2015-03-13 20:15:09 +00:00
|
|
|
bool
|
|
|
|
nsExpandedPrincipal::IsOnCSSUnprefixingWhitelist()
|
|
|
|
{
|
|
|
|
// CSS Unprefixing Whitelist is a per-origin thing; doesn't really make sense
|
|
|
|
// for an expanded principal. (And probably shouldn't be needed.)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-09 22:19:26 +00:00
|
|
|
void
|
|
|
|
nsExpandedPrincipal::GetScriptLocation(nsACString& aStr)
|
|
|
|
{
|
2015-05-12 22:47:17 +00:00
|
|
|
aStr.Assign("[Expanded Principal [");
|
2015-04-10 15:52:29 +00:00
|
|
|
for (size_t i = 0; i < mPrincipals.Length(); ++i) {
|
|
|
|
if (i != 0) {
|
|
|
|
aStr.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString spec;
|
|
|
|
nsJSPrincipals::get(mPrincipals.ElementAt(i))->GetScriptLocation(spec);
|
|
|
|
|
|
|
|
aStr.Append(spec);
|
|
|
|
|
|
|
|
}
|
2015-05-12 22:47:17 +00:00
|
|
|
aStr.Append("]]");
|
2012-06-09 22:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
// Methods implementing nsISerializable //
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|