2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-13 23:56:21 -07:00
|
|
|
#include "nsPrincipal.h"
|
|
|
|
|
2013-01-08 13:53:32 -08:00
|
|
|
#include "mozIThirdPartyUtil.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsScriptSecurityManager.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2013-07-11 13:21:45 -07:00
|
|
|
#include "pratom.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsJSPrincipals.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsIClassInfoImpl.h"
|
2014-11-11 01:10:56 -08:00
|
|
|
#include "nsIProtocolHandler.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2010-01-22 13:38:21 -08:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2012-07-12 01:10:15 -07:00
|
|
|
#include "jswrapper.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-14 18:47:15 -07:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2011-06-19 20:00:16 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-03-12 15:53:18 -07:00
|
|
|
#include "mozilla/HashFunctions.h"
|
2009-06-16 04:00:06 -07:00
|
|
|
|
2012-08-27 19:43:57 -07:00
|
|
|
#include "nsIAppsService.h"
|
|
|
|
#include "mozIApplication.h"
|
|
|
|
|
2011-06-19 20:00:16 -07:00
|
|
|
using namespace mozilla;
|
2009-06-16 04:00:06 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool gCodeBasePrincipalSupport = false;
|
|
|
|
static bool gIsObservingCodeBasePrincipalSupport = false;
|
2009-06-16 04:00:06 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool URIIsImmutable(nsIURI* aURI)
|
2007-06-18 08:07:02 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMutable> mutableObj(do_QueryInterface(aURI));
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isMutable;
|
2007-06-18 08:07:02 -07:00
|
|
|
return
|
|
|
|
mutableObj &&
|
|
|
|
NS_SUCCEEDED(mutableObj->GetMutable(&isMutable)) &&
|
2013-05-31 14:33:51 -07:00
|
|
|
!isMutable;
|
2007-06-18 08:07:02 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Static member variables
|
2012-06-09 15:19:26 -07:00
|
|
|
const char nsBasePrincipal::sInvalid[] = "Invalid";
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-27 13:38:33 -07:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2012-06-09 15:19:26 -07:00
|
|
|
nsBasePrincipal::AddRef()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXXcaa does this need to be threadsafe? See bug 143559.
|
2013-11-27 07:37:10 -08:00
|
|
|
nsrefcnt count = ++refcount;
|
2012-06-09 15:19:26 -07:00
|
|
|
NS_LOG_ADDREF(this, count, "nsBasePrincipal", sizeof(*this));
|
2007-03-22 10:30:00 -07:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-03-27 13:38:33 -07:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2012-06-09 15:19:26 -07:00
|
|
|
nsBasePrincipal::Release()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-09 01:48:50 -08:00
|
|
|
NS_PRECONDITION(0 != refcount, "dup release");
|
2013-11-27 07:37:10 -08:00
|
|
|
nsrefcnt count = --refcount;
|
2012-06-09 15:19:26 -07:00
|
|
|
NS_LOG_RELEASE(this, count, "nsBasePrincipal");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (count == 0) {
|
2010-07-05 02:42:18 -07:00
|
|
|
delete this;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2013-12-13 19:15:43 -08:00
|
|
|
nsBasePrincipal::nsBasePrincipal()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-19 20:00:16 -07:00
|
|
|
if (!gIsObservingCodeBasePrincipalSupport) {
|
|
|
|
nsresult rv =
|
|
|
|
Preferences::AddBoolVarCache(&gCodeBasePrincipalSupport,
|
|
|
|
"signed.applets.codebase_principal_support",
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2011-06-19 20:00:16 -07:00
|
|
|
gIsObservingCodeBasePrincipalSupport = NS_SUCCEEDED(rv);
|
|
|
|
NS_WARN_IF_FALSE(gIsObservingCodeBasePrincipalSupport,
|
|
|
|
"Installing gCodeBasePrincipalSupport failed!");
|
2009-06-16 04:00:06 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
nsBasePrincipal::~nsBasePrincipal(void)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
NS_IMETHODIMP
|
2012-06-09 15:19:26 -07:00
|
|
|
nsBasePrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
|
2012-06-09 15:19:26 -07:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aCsp = mCSP);
|
2008-02-26 19:45:29 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-06-09 15:19:26 -07:00
|
|
|
nsBasePrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-09 15:19:26 -07:00
|
|
|
// If CSP was already set, it should not be destroyed! Instead, it should
|
|
|
|
// get set anew when a new principal is created.
|
|
|
|
if (mCSP)
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
mCSP = aCsp;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void nsPrincipal::dumpImpl()
|
|
|
|
{
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString str;
|
2012-06-09 15:19:26 -07:00
|
|
|
GetScriptLocation(str);
|
2012-07-19 22:44:03 -07:00
|
|
|
fprintf(stderr, "nsPrincipal (%p) = %s\n", static_cast<void*>(this), str.get());
|
2012-06-09 15:19:26 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-02 17:16:25 -07:00
|
|
|
NS_IMPL_CLASSINFO(nsPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
|
2012-06-09 15:19:26 -07:00
|
|
|
NS_PRINCIPAL_CID)
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(nsPrincipal,
|
|
|
|
nsIPrincipal,
|
|
|
|
nsISerializable)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(nsPrincipal,
|
2012-06-09 15:19:26 -07:00
|
|
|
nsIPrincipal,
|
|
|
|
nsISerializable)
|
2012-06-10 12:25:17 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsPrincipal, nsBasePrincipal)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsPrincipal, nsBasePrincipal)
|
2012-06-09 15:19:26 -07:00
|
|
|
|
|
|
|
nsPrincipal::nsPrincipal()
|
2012-07-19 22:44:03 -07:00
|
|
|
: mAppId(nsIScriptSecurityManager::UNKNOWN_APP_ID)
|
|
|
|
, mInMozBrowser(false)
|
|
|
|
, mCodebaseImmutable(false)
|
2012-06-10 12:25:17 -07:00
|
|
|
, mDomainImmutable(false)
|
|
|
|
, mInitialized(false)
|
2012-06-09 15:19:26 -07:00
|
|
|
{ }
|
|
|
|
|
|
|
|
nsPrincipal::~nsPrincipal()
|
|
|
|
{ }
|
|
|
|
|
2012-05-02 14:57:34 -07:00
|
|
|
nsresult
|
2012-10-21 23:29:56 -07:00
|
|
|
nsPrincipal::Init(nsIURI *aCodebase,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aAppId,
|
2012-07-19 22:44:03 -07:00
|
|
|
bool aInMozBrowser)
|
2012-06-09 15:19:26 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(!mInitialized);
|
2012-10-21 23:29:56 -07:00
|
|
|
NS_ENSURE_ARG(aCodebase);
|
2012-06-09 15:19:26 -07:00
|
|
|
|
|
|
|
mInitialized = true;
|
|
|
|
|
|
|
|
mCodebase = NS_TryToMakeImmutable(aCodebase);
|
|
|
|
mCodebaseImmutable = URIIsImmutable(mCodebase);
|
|
|
|
|
2012-07-19 22:44:03 -07:00
|
|
|
mAppId = aAppId;
|
|
|
|
mInMozBrowser = aInMozBrowser;
|
|
|
|
|
2012-10-21 23:29:56 -07:00
|
|
|
return NS_OK;
|
2012-06-09 15:19:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPrincipal::GetScriptLocation(nsACString &aStr)
|
|
|
|
{
|
2012-10-21 23:29:56 -07:00
|
|
|
mCodebase->GetSpec(aStr);
|
2012-06-09 15:19:26 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 21:23:44 -07:00
|
|
|
/* static */ nsresult
|
|
|
|
nsPrincipal::GetOriginForURI(nsIURI* aURI, char **aOrigin)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-18 21:23:44 -07:00
|
|
|
if (!aURI) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
*aOrigin = nullptr;
|
2012-06-09 15:19:26 -07:00
|
|
|
|
2012-07-18 21:23:44 -07:00
|
|
|
nsCOMPtr<nsIURI> origin = NS_GetInnermostURI(aURI);
|
2012-06-09 15:19:26 -07:00
|
|
|
if (!origin) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-09-28 07:31:04 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString hostPort;
|
2012-06-09 15:19:26 -07: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) {
|
|
|
|
rv = origin->GetAsciiHost(hostPort);
|
|
|
|
// Some implementations return an empty string, treat it as no support
|
|
|
|
// for asciiHost by that implementation.
|
2012-07-18 21:23:44 -07:00
|
|
|
if (hostPort.IsEmpty()) {
|
2012-06-09 15:19:26 -07:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2012-07-18 21:23:44 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t port;
|
2012-06-09 15:19:26 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && !isChrome) {
|
|
|
|
rv = origin->GetPort(&port);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && !isChrome) {
|
|
|
|
if (port != -1) {
|
2014-05-21 20:48:51 -07:00
|
|
|
hostPort.Append(':');
|
2012-06-09 15:19:26 -07:00
|
|
|
hostPort.AppendInt(port, 10);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString scheme;
|
2012-06-09 15:19:26 -07:00
|
|
|
rv = origin->GetScheme(scheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-07-18 21:23:44 -07:00
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
*aOrigin = ToNewCString(scheme + NS_LITERAL_CSTRING("://") + hostPort);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Some URIs (e.g., nsSimpleURI) don't support asciiHost. Just
|
|
|
|
// get the full spec.
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString spec;
|
2012-06-09 15:19:26 -07:00
|
|
|
// XXX nsMozIconURI and nsJARURI don't implement this correctly, they
|
|
|
|
// both fall back to GetSpec. That needs to be fixed.
|
|
|
|
rv = origin->GetAsciiSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-07-18 21:23:44 -07:00
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
*aOrigin = ToNewCString(spec);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 21:23:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetOrigin(char **aOrigin)
|
|
|
|
{
|
|
|
|
return GetOriginForURI(mCodebase, aOrigin);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-13 18:57:36 -08:00
|
|
|
nsPrincipal::EqualsConsideringDomain(nsIPrincipal *aOther, bool *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-24 10:50:25 -07:00
|
|
|
*aResult = false;
|
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
if (!aOther) {
|
|
|
|
NS_WARNING("Need a principal to compare this to!");
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-06-09 15:19:26 -07:00
|
|
|
|
2012-10-24 10:50:25 -07:00
|
|
|
if (aOther == this) {
|
|
|
|
*aResult = true;
|
2012-06-09 15:19:26 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-13 18:57:36 -08:00
|
|
|
if (!nsScriptSecurityManager::AppAttributesEqual(this, aOther)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> thisURI;
|
|
|
|
this->GetDomain(getter_AddRefs(thisURI));
|
|
|
|
bool thisSetDomain = !!thisURI;
|
|
|
|
if (!thisURI) {
|
|
|
|
this->GetURI(getter_AddRefs(thisURI));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> otherURI;
|
|
|
|
aOther->GetDomain(getter_AddRefs(otherURI));
|
|
|
|
bool otherSetDomain = !!otherURI;
|
|
|
|
if (!otherURI) {
|
|
|
|
aOther->GetURI(getter_AddRefs(otherURI));
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = thisSetDomain == otherSetDomain &&
|
|
|
|
nsScriptSecurityManager::SecurityCompareURIs(thisURI, otherURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-13 18:57:36 -08:00
|
|
|
nsPrincipal::Equals(nsIPrincipal *aOther, bool *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-24 10:50:25 -07:00
|
|
|
*aResult = false;
|
|
|
|
|
|
|
|
if (!aOther) {
|
|
|
|
NS_WARNING("Need a principal to compare this to!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOther == this) {
|
2012-06-09 15:19:26 -07:00
|
|
|
*aResult = true;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-24 10:50:25 -07:00
|
|
|
if (!nsScriptSecurityManager::AppAttributesEqual(this, aOther)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
nsCOMPtr<nsIURI> otherURI;
|
|
|
|
nsresult rv = aOther->GetURI(getter_AddRefs(otherURI));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
NS_ASSERTION(mCodebase,
|
|
|
|
"shouldn't be calling this on principals from preferences");
|
|
|
|
|
|
|
|
// Compare codebases.
|
|
|
|
*aResult = nsScriptSecurityManager::SecurityCompareURIs(mCodebase,
|
|
|
|
otherURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-09 15:19:26 -07:00
|
|
|
nsPrincipal::Subsumes(nsIPrincipal *aOther, bool *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-09 15:19:26 -07:00
|
|
|
return Equals(aOther, aResult);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-13 18:57:34 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::SubsumesConsideringDomain(nsIPrincipal *aOther, bool *aResult)
|
|
|
|
{
|
2014-02-13 18:57:36 -08:00
|
|
|
return EqualsConsideringDomain(aOther, aResult);
|
2014-02-13 18:57:34 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetURI(nsIURI** aURI)
|
|
|
|
{
|
2007-06-18 08:07:02 -07:00
|
|
|
if (mCodebaseImmutable) {
|
|
|
|
NS_ADDREF(*aURI = mCodebase);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mCodebase) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aURI = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_EnsureSafeToReturn(mCodebase, aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-20 11:34:33 -07:00
|
|
|
nsPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport, bool aAllowIfInheritsPrincipal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-20 11:34:33 -07: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 01:21:17 -07: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;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:33:51 -07:00
|
|
|
if (nsScriptSecurityManager::SecurityCompareURIs(mCodebase, aURI)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-08 13:53:32 -08:00
|
|
|
|
2013-05-31 14:33:51 -07: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-06-09 15:19:26 -07:00
|
|
|
|
2013-05-31 14:33:51 -07:00
|
|
|
if (aReport) {
|
|
|
|
nsScriptSecurityManager::ReportError(nullptr, NS_LITERAL_STRING("CheckSameOriginError"), mCodebase, aURI);
|
|
|
|
}
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
void
|
|
|
|
nsPrincipal::SetURI(nsIURI* aURI)
|
2010-01-22 13:38:21 -08:00
|
|
|
{
|
2012-06-09 15:19:26 -07:00
|
|
|
mCodebase = NS_TryToMakeImmutable(aURI);
|
|
|
|
mCodebaseImmutable = URIIsImmutable(mCodebase);
|
2010-01-22 13:38:21 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsPrincipal::GetHashValue(uint32_t* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-21 23:29:56 -07:00
|
|
|
NS_PRECONDITION(mCodebase, "Need a codebase");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-21 23:29:56 -07:00
|
|
|
*aValue = nsScriptSecurityManager::HashPrincipalByOrigin(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetDomain(nsIURI** aDomain)
|
|
|
|
{
|
|
|
|
if (!mDomain) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aDomain = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-18 08:07:02 -07:00
|
|
|
if (mDomainImmutable) {
|
|
|
|
NS_ADDREF(*aDomain = mDomain);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_EnsureSafeToReturn(mDomain, aDomain);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::SetDomain(nsIURI* aDomain)
|
|
|
|
{
|
|
|
|
mDomain = NS_TryToMakeImmutable(aDomain);
|
2007-06-18 08:07:02 -07:00
|
|
|
mDomainImmutable = URIIsImmutable(mDomain);
|
2013-01-08 13:53:32 -08:00
|
|
|
|
2012-07-12 01:10:15 -07:00
|
|
|
// Recompute all wrappers between compartments using this principal and other
|
|
|
|
// non-chrome compartments.
|
2013-05-06 06:04:17 -07:00
|
|
|
AutoSafeJSContext cx;
|
2012-07-12 01:10:15 -07: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);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-19 22:44:03 -07:00
|
|
|
NS_IMETHODIMP
|
2013-09-10 21:18:36 -07:00
|
|
|
nsPrincipal::GetJarPrefix(nsACString& aJarPrefix)
|
2012-07-19 22:44:03 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID);
|
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
mozilla::GetJarPrefix(mAppId, mInMozBrowser, aJarPrefix);
|
2012-07-19 22:44:03 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsPrincipal::GetAppStatus(uint16_t* aAppStatus)
|
2012-07-19 22:44:03 -07:00
|
|
|
{
|
|
|
|
*aAppStatus = GetAppStatus();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsPrincipal::GetAppId(uint32_t* aAppId)
|
2012-07-19 22:44:03 -07:00
|
|
|
{
|
|
|
|
if (mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
*aAppId = nsIScriptSecurityManager::NO_APP_ID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aAppId = mAppId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-31 08:47:20 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
|
|
|
|
{
|
|
|
|
*aIsInBrowserElement = mInMozBrowser;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-25 16:28:17 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetUnknownAppId(bool* aUnknownAppId)
|
|
|
|
{
|
|
|
|
*aUnknownAppId = mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-23 09:31:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
|
|
|
|
{
|
|
|
|
*aIsNullPrincipal = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 13:53:32 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
|
|
|
{
|
|
|
|
// For a file URI, we return the file path.
|
2013-05-31 14:33:51 -07:00
|
|
|
if (NS_URIIsLocalFile(mCodebase)) {
|
2013-01-08 13:53:32 -08:00
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(mCodebase);
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
return url->GetFilePath(aBaseDomain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-11 01:10:56 -08: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 13:53:32 -08: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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
2014-03-15 12:00:17 -07:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
2007-09-17 15:18:28 -07:00
|
|
|
nsCOMPtr<nsIURI> codebase;
|
2014-03-15 12:00:17 -07:00
|
|
|
nsresult rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
|
2007-09-17 15:18:28 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-15 12:00:17 -07:00
|
|
|
codebase = do_QueryInterface(supports);
|
|
|
|
|
2012-07-25 17:12:03 -07:00
|
|
|
nsCOMPtr<nsIURI> domain;
|
2014-03-15 12:00:17 -07:00
|
|
|
rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
|
2012-07-25 17:12:03 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-03-15 12:00:17 -07:00
|
|
|
domain = do_QueryInterface(supports);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t appId;
|
2012-07-19 22:44:03 -07:00
|
|
|
rv = aStream->Read32(&appId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
bool inMozBrowser;
|
|
|
|
rv = aStream->ReadBoolean(&inMozBrowser);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-03-15 12:00:17 -07:00
|
|
|
rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
|
2014-01-23 15:34:59 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-03-15 12:00:17 -07:00
|
|
|
// This may be null.
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp = do_QueryInterface(supports, &rv);
|
|
|
|
|
2012-10-21 23:29:56 -07:00
|
|
|
rv = Init(codebase, appId, inMozBrowser);
|
2007-09-17 15:18:28 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-01-23 15:34:59 -08:00
|
|
|
rv = SetCsp(csp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-07-30 14:37:22 -07:00
|
|
|
// need to link in the CSP context here (link in the URI of the protected
|
|
|
|
// resource).
|
2014-01-23 15:34:59 -08:00
|
|
|
if (csp) {
|
2014-07-30 14:37:22 -07:00
|
|
|
csp->SetRequestContext(codebase, nullptr, nullptr);
|
2014-01-23 15:34:59 -08:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:18:28 -07:00
|
|
|
SetDomain(domain);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrincipal::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
2012-10-21 23:29:56 -07:00
|
|
|
NS_ENSURE_STATE(mCodebase);
|
2007-09-17 15:18:28 -07:00
|
|
|
|
2012-10-21 23:29:56 -07:00
|
|
|
nsresult rv = NS_WriteOptionalCompoundObject(aStream, mCodebase, NS_GET_IID(nsIURI),
|
|
|
|
true);
|
2007-09-17 15:18:28 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:18:28 -07:00
|
|
|
rv = NS_WriteOptionalCompoundObject(aStream, mDomain, NS_GET_IID(nsIURI),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-07-19 22:44:03 -07:00
|
|
|
aStream->Write32(mAppId);
|
|
|
|
aStream->WriteBoolean(mInMozBrowser);
|
|
|
|
|
2014-01-23 15:34:59 -08:00
|
|
|
rv = NS_WriteOptionalCompoundObject(aStream, mCSP,
|
|
|
|
NS_GET_IID(nsIContentSecurityPolicy),
|
|
|
|
true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-09-17 15:18:28 -07:00
|
|
|
// mCodebaseImmutable and mDomainImmutable will be recomputed based
|
|
|
|
// on the deserialized URIs in Read().
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-06-09 15:19:26 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t
|
2012-07-19 22:44:03 -07:00
|
|
|
nsPrincipal::GetAppStatus()
|
|
|
|
{
|
2014-07-29 08:47:52 -07:00
|
|
|
if (mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
|
|
|
|
NS_WARNING("Asking for app status on a principal with an unknown app id");
|
2014-07-28 12:08:51 -07:00
|
|
|
return nsIPrincipal::APP_STATUS_NOT_INSTALLED;
|
|
|
|
}
|
2014-07-29 08:47:52 -07:00
|
|
|
return nsScriptSecurityManager::AppStatusForPrincipal(this);
|
2012-07-19 22:44:03 -07:00
|
|
|
}
|
2012-06-09 15:19:26 -07:00
|
|
|
|
|
|
|
/************************************************************************************************************************/
|
|
|
|
|
|
|
|
static const char EXPANDED_PRINCIPAL_SPEC[] = "[Expanded Principal]";
|
|
|
|
|
2013-04-02 17:16:25 -07:00
|
|
|
NS_IMPL_CLASSINFO(nsExpandedPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
|
2012-06-09 15:19:26 -07:00
|
|
|
NS_EXPANDEDPRINCIPAL_CID)
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(nsExpandedPrincipal,
|
|
|
|
nsIPrincipal,
|
|
|
|
nsIExpandedPrincipal)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(nsExpandedPrincipal,
|
2012-06-09 15:19:26 -07:00
|
|
|
nsIPrincipal,
|
|
|
|
nsIExpandedPrincipal)
|
2012-06-10 12:25:17 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsExpandedPrincipal, nsBasePrincipal)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsExpandedPrincipal, nsBasePrincipal)
|
2012-06-09 15:19:26 -07:00
|
|
|
|
|
|
|
nsExpandedPrincipal::nsExpandedPrincipal(nsTArray<nsCOMPtr <nsIPrincipal> > &aWhiteList)
|
|
|
|
{
|
|
|
|
mPrincipals.AppendElements(aWhiteList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsExpandedPrincipal::~nsExpandedPrincipal()
|
|
|
|
{ }
|
|
|
|
|
2013-01-08 13:53:32 -08:00
|
|
|
NS_IMETHODIMP
|
2012-06-09 15:19:26 -07:00
|
|
|
nsExpandedPrincipal::GetDomain(nsIURI** aDomain)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aDomain = nullptr;
|
2012-06-09 15:19:26 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 13:53:32 -08:00
|
|
|
NS_IMETHODIMP
|
2012-06-09 15:19:26 -07:00
|
|
|
nsExpandedPrincipal::SetDomain(nsIURI* aDomain)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 13:53:32 -08:00
|
|
|
NS_IMETHODIMP
|
2012-06-09 15:19:26 -07:00
|
|
|
nsExpandedPrincipal::GetOrigin(char** aOrigin)
|
|
|
|
{
|
|
|
|
*aOrigin = ToNewCString(NS_LITERAL_CSTRING(EXPANDED_PRINCIPAL_SPEC));
|
|
|
|
return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef nsresult (NS_STDCALL nsIPrincipal::*nsIPrincipalMemFn)(nsIPrincipal* aOther,
|
|
|
|
bool* aResult);
|
|
|
|
#define CALL_MEMBER_FUNCTION(THIS,MEM_FN) ((THIS)->*(MEM_FN))
|
|
|
|
|
2014-02-13 18:57:36 -08:00
|
|
|
// nsExpandedPrincipal::Equals and nsExpandedPrincipal::EqualsConsideringDomain
|
2013-01-08 13:53:32 -08:00
|
|
|
// shares the same logic. The difference only that Equals requires 'this'
|
2014-02-13 18:57:36 -08:00
|
|
|
// and 'aOther' to Subsume each other while EqualsConsideringDomain requires
|
|
|
|
// bidirectional SubsumesConsideringDomain.
|
2013-01-08 13:53:32 -08:00
|
|
|
static nsresult
|
2012-06-09 15:19:26 -07:00
|
|
|
Equals(nsExpandedPrincipal* aThis, nsIPrincipalMemFn aFn, nsIPrincipal* aOther,
|
|
|
|
bool* aResult)
|
|
|
|
{
|
2014-02-13 18:57:36 -08:00
|
|
|
// If (and only if) 'aThis' and 'aOther' both Subsume/SubsumesConsideringDomain
|
2012-06-09 15:19:26 -07:00
|
|
|
// each other, then they are Equal.
|
|
|
|
*aResult = false;
|
|
|
|
// Calling the corresponding subsume function on this (aFn).
|
|
|
|
nsresult rv = CALL_MEMBER_FUNCTION(aThis, aFn)(aOther, aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Calling the corresponding subsume function on aOther (aFn).
|
|
|
|
rv = CALL_MEMBER_FUNCTION(aOther, aFn)(aThis, aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::Equals(nsIPrincipal* aOther, bool* aResult)
|
|
|
|
{
|
|
|
|
return ::Equals(this, &nsIPrincipal::Subsumes, aOther, aResult);
|
|
|
|
}
|
|
|
|
|
2014-02-13 18:57:34 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::EqualsConsideringDomain(nsIPrincipal* aOther, bool* aResult)
|
|
|
|
{
|
|
|
|
return ::Equals(this, &nsIPrincipal::SubsumesConsideringDomain, aOther, aResult);
|
|
|
|
}
|
|
|
|
|
2014-02-13 18:57:36 -08:00
|
|
|
// nsExpandedPrincipal::Subsumes and nsExpandedPrincipal::SubsumesConsideringDomain
|
2012-06-09 15:19:26 -07:00
|
|
|
// shares the same logic. The difference only that Subsumes calls are replaced
|
2014-02-13 18:57:36 -08:00
|
|
|
//with SubsumesConsideringDomain calls in the second case.
|
2013-01-08 13:53:32 -08:00
|
|
|
static nsresult
|
|
|
|
Subsumes(nsExpandedPrincipal* aThis, nsIPrincipalMemFn aFn, nsIPrincipal* aOther,
|
2012-06-09 15:19:26 -07:00
|
|
|
bool* aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2013-01-08 13:53:32 -08:00
|
|
|
nsCOMPtr<nsIExpandedPrincipal> expanded = do_QueryInterface(aOther);
|
2012-06-09 15:19:26 -07:00
|
|
|
if (expanded) {
|
2013-01-08 13:53:32 -08:00
|
|
|
// If aOther is an ExpandedPrincipal too, check if all of its
|
2012-06-09 15:19:26 -07:00
|
|
|
// principals are subsumed.
|
|
|
|
nsTArray< nsCOMPtr<nsIPrincipal> >* otherList;
|
|
|
|
expanded->GetWhiteList(&otherList);
|
|
|
|
for (uint32_t i = 0; i < otherList->Length(); ++i){
|
|
|
|
rv = CALL_MEMBER_FUNCTION(aThis, aFn)((*otherList)[i], aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!*aResult) {
|
|
|
|
// If we don't subsume at least one principal of aOther, return false.
|
2013-01-08 13:53:32 -08:00
|
|
|
return NS_OK;
|
2012-06-09 15:19:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// For a regular aOther, one of our principals must subsume it.
|
|
|
|
nsTArray< nsCOMPtr<nsIPrincipal> >* list;
|
|
|
|
aThis->GetWhiteList(&list);
|
|
|
|
for (uint32_t i = 0; i < list->Length(); ++i){
|
|
|
|
rv = CALL_MEMBER_FUNCTION((*list)[i], aFn)(aOther, aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (*aResult) {
|
|
|
|
// If one of our principal subsumes it, return true.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CALL_MEMBER_FUNCTION
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::Subsumes(nsIPrincipal* aOther, bool* aResult)
|
|
|
|
{
|
|
|
|
return ::Subsumes(this, &nsIPrincipal::Subsumes, aOther, aResult);
|
|
|
|
}
|
|
|
|
|
2014-02-13 18:57:34 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::SubsumesConsideringDomain(nsIPrincipal* aOther, bool* aResult)
|
|
|
|
{
|
|
|
|
return ::Subsumes(this, &nsIPrincipal::SubsumesConsideringDomain, aOther, aResult);
|
|
|
|
}
|
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-20 11:34:33 -07:00
|
|
|
nsExpandedPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal)
|
2012-06-09 15:19:26 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
for (uint32_t i = 0; i < mPrincipals.Length(); ++i){
|
2012-08-20 11:34:33 -07:00
|
|
|
rv = mPrincipals[i]->CheckMayLoad(uri, aReport, aAllowIfInheritsPrincipal);
|
2012-06-09 15:19:26 -07:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsExpandedPrincipal::GetHashValue(uint32_t* result)
|
2012-06-09 15:19:26 -07:00
|
|
|
{
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("extended principal should never be used as key in a hash map");
|
2012-06-09 15:19:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetURI(nsIURI** aURI)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aURI = nullptr;
|
2012-06-09 15:19:26 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 13:53:32 -08:00
|
|
|
NS_IMETHODIMP
|
2012-06-09 15:19:26 -07:00
|
|
|
nsExpandedPrincipal::GetWhiteList(nsTArray<nsCOMPtr<nsIPrincipal> >** aWhiteList)
|
|
|
|
{
|
|
|
|
*aWhiteList = &mPrincipals;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-19 22:44:03 -07:00
|
|
|
NS_IMETHODIMP
|
2013-09-10 21:18:36 -07:00
|
|
|
nsExpandedPrincipal::GetJarPrefix(nsACString& aJarPrefix)
|
2012-07-19 22:44:03 -07:00
|
|
|
{
|
2013-09-10 21:18:36 -07:00
|
|
|
aJarPrefix.Truncate();
|
|
|
|
return NS_OK;
|
2012-07-19 22:44:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsExpandedPrincipal::GetAppStatus(uint16_t* aAppStatus)
|
2012-07-19 22:44:03 -07:00
|
|
|
{
|
2012-10-09 05:47:46 -07:00
|
|
|
*aAppStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
|
|
|
|
return NS_OK;
|
2012-07-19 22:44:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsExpandedPrincipal::GetAppId(uint32_t* aAppId)
|
2012-07-19 22:44:03 -07:00
|
|
|
{
|
2012-10-09 05:47:46 -07:00
|
|
|
*aAppId = nsIScriptSecurityManager::NO_APP_ID;
|
|
|
|
return NS_OK;
|
2012-07-19 22:44:03 -07:00
|
|
|
}
|
|
|
|
|
2012-07-31 08:47:20 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
|
|
|
|
{
|
2012-10-09 05:47:46 -07:00
|
|
|
*aIsInBrowserElement = false;
|
|
|
|
return NS_OK;
|
2012-07-31 08:47:20 -07:00
|
|
|
}
|
|
|
|
|
2012-09-25 16:28:17 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetUnknownAppId(bool* aUnknownAppId)
|
|
|
|
{
|
|
|
|
*aUnknownAppId = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-23 09:31:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
|
|
|
|
{
|
|
|
|
*aIsNullPrincipal = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 13:53:32 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExpandedPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-06-09 15:19:26 -07:00
|
|
|
void
|
|
|
|
nsExpandedPrincipal::GetScriptLocation(nsACString& aStr)
|
|
|
|
{
|
2012-10-21 23:29:56 -07:00
|
|
|
// Is that a good idea to list it's principals?
|
|
|
|
aStr.Assign(EXPANDED_PRINCIPAL_SPEC);
|
2012-06-09 15:19:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void nsExpandedPrincipal::dumpImpl()
|
|
|
|
{
|
2012-07-19 22:44:03 -07:00
|
|
|
fprintf(stderr, "nsExpandedPrincipal (%p)\n", static_cast<void*>(this));
|
2012-06-09 15:19:26 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
// 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;
|
|
|
|
}
|