2013-01-03 05:47:50 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=4 et sw=4 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/. */
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2013-08-27 02:05:20 +00:00
|
|
|
#include "nsScriptSecurityManager.h"
|
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2013-08-27 02:05:20 +00:00
|
|
|
#include "js/OldDebugAPI.h"
|
2010-04-11 13:55:24 +00:00
|
|
|
#include "xpcprivate.h"
|
2012-05-18 08:29:40 +00:00
|
|
|
#include "XPCWrapper.h"
|
2014-07-29 15:47:52 +00:00
|
|
|
#include "nsIAppsService.h"
|
2014-05-16 22:59:36 +00:00
|
|
|
#include "nsILoadContext.h"
|
1999-08-20 09:51:02 +00:00
|
|
|
#include "nsIServiceManager.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsIScriptContext.h"
|
1999-08-20 09:51:02 +00:00
|
|
|
#include "nsIURL.h"
|
2006-05-02 18:54:19 +00:00
|
|
|
#include "nsINestedURI.h"
|
1999-08-20 09:51:02 +00:00
|
|
|
#include "nspr.h"
|
1999-08-29 21:58:42 +00:00
|
|
|
#include "nsJSPrincipals.h"
|
1999-09-01 00:54:35 +00:00
|
|
|
#include "nsSystemPrincipal.h"
|
2003-10-21 22:11:49 +00:00
|
|
|
#include "nsPrincipal.h"
|
2006-04-02 20:58:26 +00:00
|
|
|
#include "nsNullPrincipal.h"
|
2013-11-13 00:43:35 +00:00
|
|
|
#include "DomainPolicy.h"
|
1999-09-07 02:54:19 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2006-11-16 18:25:52 +00:00
|
|
|
#include "nsCRTGlue.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
1999-10-28 22:09:03 +00:00
|
|
|
#include "nsDOMCID.h"
|
2000-01-26 08:38:10 +00:00
|
|
|
#include "nsIXPConnect.h"
|
2000-02-10 04:56:56 +00:00
|
|
|
#include "nsTextFormatter.h"
|
|
|
|
#include "nsIStringBundle.h"
|
2000-04-26 03:50:07 +00:00
|
|
|
#include "nsNetUtil.h"
|
2003-10-21 22:11:49 +00:00
|
|
|
#include "nsIProperties.h"
|
2000-08-14 22:38:27 +00:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2000-04-26 03:50:07 +00:00
|
|
|
#include "nsIFile.h"
|
2007-09-06 07:02:57 +00:00
|
|
|
#include "nsIFileURL.h"
|
2000-04-26 03:50:07 +00:00
|
|
|
#include "nsIZipReader.h"
|
2000-08-16 04:01:02 +00:00
|
|
|
#include "nsIXPConnect.h"
|
2000-09-09 00:53:21 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2005-11-28 23:56:44 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2001-03-23 04:22:56 +00:00
|
|
|
#include "nsIDocShell.h"
|
2001-04-07 03:33:56 +00:00
|
|
|
#include "nsIPrompt.h"
|
|
|
|
#include "nsIWindowWatcher.h"
|
2001-04-17 01:21:44 +00:00
|
|
|
#include "nsIConsoleService.h"
|
2001-11-16 06:17:24 +00:00
|
|
|
#include "nsIJSRuntimeService.h"
|
2002-02-13 04:20:46 +00:00
|
|
|
#include "nsIObserverService.h"
|
2002-08-29 04:05:39 +00:00
|
|
|
#include "nsIContent.h"
|
2003-10-21 22:11:49 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2006-06-13 03:07:47 +00:00
|
|
|
#include "nsDOMJSUtils.h"
|
2005-09-14 04:16:27 +00:00
|
|
|
#include "nsAboutProtocolUtils.h"
|
2006-03-15 04:59:42 +00:00
|
|
|
#include "nsIClassInfo.h"
|
2006-04-25 03:24:43 +00:00
|
|
|
#include "nsIURIFixup.h"
|
|
|
|
#include "nsCDefaultURIFixup.h"
|
2008-04-12 21:26:19 +00:00
|
|
|
#include "nsIChromeRegistry.h"
|
2010-03-08 08:24:50 +00:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2010-08-05 02:15:55 +00:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2014-07-29 15:47:52 +00:00
|
|
|
#include "mozIApplication.h"
|
2011-06-20 03:00:16 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-05-03 04:35:38 +00:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-07-30 14:25:31 +00:00
|
|
|
#include <stdint.h>
|
2014-08-15 01:47:15 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2012-06-19 17:20:34 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2012-07-26 19:33:45 +00:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-09-25 19:33:01 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-11-13 00:43:31 +00:00
|
|
|
#include "nsJSUtils.h"
|
2014-07-10 06:56:36 +00:00
|
|
|
#include "nsILoadInfo.h"
|
2012-09-25 19:33:01 +00:00
|
|
|
|
|
|
|
// This should be probably defined on some other place... but I couldn't find it
|
|
|
|
#define WEBAPPS_PERM_NAME "webapps-manage"
|
2011-06-20 03:00:16 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-03-31 04:42:20 +00:00
|
|
|
using namespace mozilla::dom;
|
2000-02-10 04:56:56 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIIOService *nsScriptSecurityManager::sIOService = nullptr;
|
|
|
|
nsIStringBundle *nsScriptSecurityManager::sStrBundle = nullptr;
|
2005-06-07 21:57:56 +00:00
|
|
|
JSRuntime *nsScriptSecurityManager::sRuntime = 0;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsScriptSecurityManager::sStrictFileOriginPolicy = true;
|
1999-08-20 09:51:02 +00:00
|
|
|
|
2002-02-13 04:20:46 +00:00
|
|
|
///////////////////////////
|
|
|
|
// Convenience Functions //
|
|
|
|
///////////////////////////
|
1999-11-11 22:10:36 +00:00
|
|
|
|
2009-05-21 01:49:42 +00:00
|
|
|
class nsAutoInPrincipalDomainOriginSetter {
|
|
|
|
public:
|
|
|
|
nsAutoInPrincipalDomainOriginSetter() {
|
|
|
|
++sInPrincipalDomainOrigin;
|
|
|
|
}
|
|
|
|
~nsAutoInPrincipalDomainOriginSetter() {
|
|
|
|
--sInPrincipalDomainOrigin;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sInPrincipalDomainOrigin;
|
2009-05-21 01:49:42 +00:00
|
|
|
};
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t nsAutoInPrincipalDomainOriginSetter::sInPrincipalDomainOrigin;
|
2009-05-21 01:49:42 +00:00
|
|
|
|
2008-07-29 06:37:58 +00:00
|
|
|
static
|
|
|
|
nsresult
|
2009-07-27 01:27:33 +00:00
|
|
|
GetOriginFromURI(nsIURI* aURI, nsACString& aOrigin)
|
2008-07-29 06:37:58 +00:00
|
|
|
{
|
2009-05-21 19:46:05 +00:00
|
|
|
if (nsAutoInPrincipalDomainOriginSetter::sInPrincipalDomainOrigin > 1) {
|
|
|
|
// Allow a single recursive call to GetPrincipalDomainOrigin, since that
|
|
|
|
// might be happening on a different principal from the first call. But
|
|
|
|
// after that, cut off the recursion; it just indicates that something
|
|
|
|
// we're doing in this method causes us to reenter a security check here.
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2009-05-21 01:49:42 +00:00
|
|
|
nsAutoInPrincipalDomainOriginSetter autoSetter;
|
2008-07-29 06:37:58 +00:00
|
|
|
|
2009-07-27 01:27:33 +00:00
|
|
|
nsCOMPtr<nsIURI> uri = NS_GetInnermostURI(aURI);
|
2008-07-29 06:37:58 +00:00
|
|
|
NS_ENSURE_TRUE(uri, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString hostPort;
|
2008-07-29 06:37:58 +00:00
|
|
|
|
|
|
|
nsresult rv = uri->GetHostPort(hostPort);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString scheme;
|
2008-07-29 06:37:58 +00:00
|
|
|
rv = uri->GetScheme(scheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
aOrigin = scheme + NS_LITERAL_CSTRING("://") + hostPort;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Some URIs (e.g., nsSimpleURI) don't support host. Just
|
|
|
|
// get the full spec.
|
|
|
|
rv = uri->GetSpec(aOrigin);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-27 01:27:33 +00:00
|
|
|
static
|
|
|
|
nsresult
|
|
|
|
GetPrincipalDomainOrigin(nsIPrincipal* aPrincipal,
|
|
|
|
nsACString& aOrigin)
|
|
|
|
{
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
aPrincipal->GetDomain(getter_AddRefs(uri));
|
|
|
|
if (!uri) {
|
|
|
|
aPrincipal->GetURI(getter_AddRefs(uri));
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(uri, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
return GetOriginFromURI(uri, aOrigin);
|
|
|
|
}
|
|
|
|
|
2004-09-01 07:53:32 +00:00
|
|
|
inline void SetPendingException(JSContext *cx, const char *aMsg)
|
|
|
|
{
|
2008-03-20 08:19:15 +00:00
|
|
|
JS_ReportError(cx, "%s", aMsg);
|
2004-09-01 07:53:32 +00:00
|
|
|
}
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
inline void SetPendingException(JSContext *cx, const char16_t *aMsg)
|
2004-09-01 07:53:32 +00:00
|
|
|
{
|
2008-03-20 08:19:15 +00:00
|
|
|
JS_ReportError(cx, "%hs", aMsg);
|
2004-09-01 07:53:32 +00:00
|
|
|
}
|
|
|
|
|
2002-08-29 04:05:39 +00:00
|
|
|
// Helper class to get stuff from the ClassInfo and not waste extra time with
|
|
|
|
// virtual method calls for things it has already gotten
|
|
|
|
class ClassInfoData
|
2002-02-20 05:51:05 +00:00
|
|
|
{
|
2002-08-29 04:05:39 +00:00
|
|
|
public:
|
2003-06-27 03:10:49 +00:00
|
|
|
ClassInfoData(nsIClassInfo *aClassInfo, const char *aName)
|
2003-10-21 22:11:49 +00:00
|
|
|
: mClassInfo(aClassInfo),
|
2007-07-08 07:08:04 +00:00
|
|
|
mName(const_cast<char *>(aName)),
|
2011-10-17 14:59:28 +00:00
|
|
|
mDidGetFlags(false),
|
|
|
|
mMustFreeName(false)
|
2002-08-29 04:05:39 +00:00
|
|
|
{
|
|
|
|
}
|
2002-02-20 05:51:05 +00:00
|
|
|
|
2003-06-26 00:18:43 +00:00
|
|
|
~ClassInfoData()
|
|
|
|
{
|
|
|
|
if (mMustFreeName)
|
|
|
|
nsMemory::Free(mName);
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t GetFlags()
|
2002-08-29 04:05:39 +00:00
|
|
|
{
|
|
|
|
if (!mDidGetFlags) {
|
|
|
|
if (mClassInfo) {
|
|
|
|
nsresult rv = mClassInfo->GetFlags(&mFlags);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mFlags = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mFlags = 0;
|
|
|
|
}
|
2003-06-27 03:10:49 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mDidGetFlags = true;
|
2002-08-29 04:05:39 +00:00
|
|
|
}
|
2002-02-20 05:51:05 +00:00
|
|
|
|
2002-08-29 04:05:39 +00:00
|
|
|
return mFlags;
|
|
|
|
}
|
2002-08-28 08:19:43 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsDOMClass()
|
2002-08-29 04:05:39 +00:00
|
|
|
{
|
2007-11-12 21:47:11 +00:00
|
|
|
return !!(GetFlags() & nsIClassInfo::DOM_OBJECT);
|
2002-08-29 04:05:39 +00:00
|
|
|
}
|
2003-06-27 03:10:49 +00:00
|
|
|
|
2003-06-26 03:27:01 +00:00
|
|
|
const char* GetName()
|
2003-06-26 00:18:43 +00:00
|
|
|
{
|
2003-06-27 03:10:49 +00:00
|
|
|
if (!mName) {
|
|
|
|
if (mClassInfo) {
|
2003-06-26 00:18:43 +00:00
|
|
|
mClassInfo->GetClassDescription(&mName);
|
2003-06-27 03:10:49 +00:00
|
|
|
}
|
2003-06-26 03:27:01 +00:00
|
|
|
|
2003-06-27 03:10:49 +00:00
|
|
|
if (mName) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mMustFreeName = true;
|
2003-06-27 03:10:49 +00:00
|
|
|
} else {
|
2007-07-08 07:08:04 +00:00
|
|
|
mName = const_cast<char *>("UnnamedClass");
|
2003-06-27 03:10:49 +00:00
|
|
|
}
|
2003-06-26 00:18:43 +00:00
|
|
|
}
|
2003-06-27 03:10:49 +00:00
|
|
|
|
2003-06-26 00:18:43 +00:00
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
2002-08-29 04:05:39 +00:00
|
|
|
private:
|
|
|
|
nsIClassInfo *mClassInfo; // WEAK
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mFlags;
|
2003-06-27 03:10:49 +00:00
|
|
|
char *mName;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mDidGetFlags;
|
|
|
|
bool mMustFreeName;
|
2002-08-29 04:05:39 +00:00
|
|
|
};
|
2008-10-08 22:05:25 +00:00
|
|
|
|
2000-08-22 06:02:14 +00:00
|
|
|
JSContext *
|
2002-02-13 04:20:46 +00:00
|
|
|
nsScriptSecurityManager::GetCurrentJSContext()
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
{
|
2000-08-22 06:02:14 +00:00
|
|
|
// Get JSContext from stack.
|
2013-05-29 23:49:11 +00:00
|
|
|
return nsXPConnect::XPConnect()->GetCurrentJSContext();
|
2002-02-13 04:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *
|
|
|
|
nsScriptSecurityManager::GetSafeJSContext()
|
|
|
|
{
|
|
|
|
// Get JSContext from stack.
|
2013-05-29 23:49:11 +00:00
|
|
|
return nsXPConnect::XPConnect()->GetSafeJSContext();
|
2000-08-22 06:02:14 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 03:45:29 +00:00
|
|
|
/* static */
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2002-06-14 23:54:18 +00:00
|
|
|
nsScriptSecurityManager::SecurityCompareURIs(nsIURI* aSourceURI,
|
2006-11-14 22:46:45 +00:00
|
|
|
nsIURI* aTargetURI)
|
2002-06-14 23:54:18 +00:00
|
|
|
{
|
2008-08-28 01:15:32 +00:00
|
|
|
return NS_SecurityCompareURIs(aSourceURI, aTargetURI, sStrictFileOriginPolicy);
|
2002-06-14 23:54:18 +00:00
|
|
|
}
|
|
|
|
|
2008-10-08 13:16:27 +00:00
|
|
|
// SecurityHashURI is consistent with SecurityCompareURIs because NS_SecurityHashURI
|
|
|
|
// is consistent with NS_SecurityCompareURIs. See nsNetUtil.h.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2008-10-08 13:16:27 +00:00
|
|
|
nsScriptSecurityManager::SecurityHashURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
return NS_SecurityHashURI(aURI);
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:52 +00:00
|
|
|
uint16_t
|
|
|
|
nsScriptSecurityManager::AppStatusForPrincipal(nsIPrincipal *aPrin)
|
|
|
|
{
|
|
|
|
uint32_t appId = aPrin->GetAppId();
|
|
|
|
bool inMozBrowser = aPrin->GetIsInBrowserElement();
|
|
|
|
NS_WARN_IF_FALSE(appId != nsIScriptSecurityManager::UNKNOWN_APP_ID,
|
|
|
|
"Asking for app status on a principal with an unknown app id");
|
|
|
|
// Installed apps have a valid app id (not NO_APP_ID or UNKNOWN_APP_ID)
|
|
|
|
// and they are not inside a mozbrowser.
|
|
|
|
if (appId == nsIScriptSecurityManager::NO_APP_ID ||
|
|
|
|
appId == nsIScriptSecurityManager::UNKNOWN_APP_ID || inMozBrowser)
|
|
|
|
{
|
|
|
|
return nsIPrincipal::APP_STATUS_NOT_INSTALLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(appsService, nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIApplication> app;
|
|
|
|
appsService->GetAppByLocalId(appId, getter_AddRefs(app));
|
|
|
|
NS_ENSURE_TRUE(app, nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
uint16_t status = nsIPrincipal::APP_STATUS_INSTALLED;
|
|
|
|
NS_ENSURE_SUCCESS(app->GetAppStatus(&status),
|
|
|
|
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
nsAutoCString origin;
|
|
|
|
NS_ENSURE_SUCCESS(aPrin->GetOrigin(getter_Copies(origin)),
|
|
|
|
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
nsString appOrigin;
|
|
|
|
NS_ENSURE_SUCCESS(app->GetOrigin(appOrigin),
|
|
|
|
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
// We go from string -> nsIURI -> origin to be sure we
|
|
|
|
// compare two punny-encoded origins.
|
|
|
|
nsCOMPtr<nsIURI> appURI;
|
|
|
|
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(appURI), appOrigin),
|
|
|
|
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
nsAutoCString appOriginPunned;
|
|
|
|
NS_ENSURE_SUCCESS(nsPrincipal::GetOriginForURI(appURI, getter_Copies(appOriginPunned)),
|
|
|
|
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
|
|
|
|
|
|
|
|
if (!appOriginPunned.Equals(origin)) {
|
|
|
|
return nsIPrincipal::APP_STATUS_NOT_INSTALLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-11-22 18:27:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::GetChannelPrincipal(nsIChannel* aChannel,
|
|
|
|
nsIPrincipal** aPrincipal)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aChannel, "Must have channel!");
|
|
|
|
nsCOMPtr<nsISupports> owner;
|
|
|
|
aChannel->GetOwner(getter_AddRefs(owner));
|
|
|
|
if (owner) {
|
|
|
|
CallQueryInterface(owner, aPrincipal);
|
|
|
|
if (*aPrincipal) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 06:56:36 +00:00
|
|
|
// Check whether we have an nsILoadInfo that says what we should do.
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
if (loadInfo) {
|
|
|
|
if (loadInfo->GetLoadingSandboxed()) {
|
2014-07-29 15:47:52 +00:00
|
|
|
nsRefPtr<nsNullPrincipal> prin =
|
|
|
|
nsNullPrincipal::CreateWithInheritedAttributes(loadInfo->LoadingPrincipal());
|
|
|
|
NS_ENSURE_TRUE(prin, NS_ERROR_FAILURE);
|
|
|
|
prin.forget(aPrincipal);
|
|
|
|
return NS_OK;
|
2014-07-10 06:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (loadInfo->GetForceInheritPrincipal()) {
|
|
|
|
NS_ADDREF(*aPrincipal = loadInfo->LoadingPrincipal());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-22 18:27:54 +00:00
|
|
|
// OK, get the principal from the URI. Make sure this does the same thing
|
2013-03-26 15:31:53 +00:00
|
|
|
// as nsDocument::Reset and XULDocument::StartDocumentLoad.
|
2006-11-22 18:27:54 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2007-10-23 21:56:41 +00:00
|
|
|
nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-11-22 18:27:54 +00:00
|
|
|
|
2012-07-20 07:07:49 +00:00
|
|
|
|
2014-05-16 22:59:36 +00:00
|
|
|
nsCOMPtr<nsILoadContext> loadContext;
|
|
|
|
NS_QueryNotificationCallbacks(aChannel, loadContext);
|
|
|
|
|
|
|
|
if (loadContext) {
|
|
|
|
return GetLoadContextCodebasePrincipal(uri, loadContext, aPrincipal);
|
2012-07-20 07:07:49 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 18:32:36 +00:00
|
|
|
return GetCodebasePrincipalInternal(uri, UNKNOWN_APP_ID,
|
|
|
|
/* isInBrowserElement */ false, aPrincipal);
|
2006-11-22 18:27:54 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 15:12:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::IsSystemPrincipal(nsIPrincipal* aPrincipal,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aIsSystem)
|
2007-06-18 15:12:09 +00:00
|
|
|
{
|
|
|
|
*aIsSystem = (aPrincipal == mSystemPrincipal);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-11 22:10:36 +00:00
|
|
|
/////////////////////////////
|
|
|
|
// nsScriptSecurityManager //
|
|
|
|
/////////////////////////////
|
|
|
|
|
1999-09-07 20:40:20 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Methods implementing ISupports //
|
|
|
|
////////////////////////////////////
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsScriptSecurityManager,
|
|
|
|
nsIScriptSecurityManager,
|
|
|
|
nsIChannelEventSink,
|
|
|
|
nsIObserver)
|
1999-08-20 09:51:02 +00:00
|
|
|
|
1999-09-07 20:40:20 +00:00
|
|
|
///////////////////////////////////////////////////
|
|
|
|
// Methods implementing nsIScriptSecurityManager //
|
|
|
|
///////////////////////////////////////////////////
|
1999-08-20 09:51:02 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
///////////////// Security Checks /////////////////
|
2012-03-09 09:48:50 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
bool
|
2010-03-08 08:24:50 +00:00
|
|
|
nsScriptSecurityManager::ContentSecurityPolicyPermitsJSAction(JSContext *cx)
|
|
|
|
{
|
2014-05-06 22:43:03 +00:00
|
|
|
MOZ_ASSERT(cx == nsContentUtils::GetCurrentJSContext());
|
2014-05-13 09:58:00 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> subjectPrincipal = nsContentUtils::SubjectPrincipal();
|
2010-03-08 08:24:50 +00:00
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
2014-05-06 22:43:03 +00:00
|
|
|
nsresult rv = subjectPrincipal->GetCsp(getter_AddRefs(csp));
|
2010-03-08 08:24:50 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "CSP: Failed to get CSP from principal.");
|
|
|
|
|
|
|
|
// don't do anything unless there's a CSP
|
|
|
|
if (!csp)
|
2013-08-07 06:59:54 +00:00
|
|
|
return true;
|
2010-03-08 08:24:50 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool evalOK = true;
|
2012-10-15 20:54:58 +00:00
|
|
|
bool reportViolation = false;
|
|
|
|
rv = csp->GetAllowsEval(&reportViolation, &evalOK);
|
2010-03-08 08:24:50 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
NS_WARNING("CSP: failed to get allowsEval");
|
2013-08-07 06:59:54 +00:00
|
|
|
return true; // fail open to not break sites.
|
2010-03-08 08:24:50 +00:00
|
|
|
}
|
|
|
|
|
2012-10-15 20:54:58 +00:00
|
|
|
if (reportViolation) {
|
2011-01-31 18:09:44 +00:00
|
|
|
nsAutoString fileName;
|
2012-04-16 19:30:00 +00:00
|
|
|
unsigned lineNum = 0;
|
2011-01-31 18:09:44 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(scriptSample, "call to eval() or related function blocked by CSP");
|
|
|
|
|
2014-02-25 15:43:14 +00:00
|
|
|
JS::AutoFilename scriptFilename;
|
|
|
|
if (JS::DescribeScriptedCaller(cx, &scriptFilename, &lineNum)) {
|
|
|
|
if (const char *file = scriptFilename.get()) {
|
2012-04-16 19:30:00 +00:00
|
|
|
CopyUTF8toUTF16(nsDependentCString(file), fileName);
|
2011-01-31 18:09:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
csp->LogViolationDetails(nsIContentSecurityPolicy::VIOLATION_TYPE_EVAL,
|
|
|
|
fileName,
|
|
|
|
scriptSample,
|
2013-11-08 23:44:39 +00:00
|
|
|
lineNum,
|
2014-01-02 19:14:06 +00:00
|
|
|
EmptyString(),
|
2013-11-08 23:44:39 +00:00
|
|
|
EmptyString());
|
2011-01-31 18:09:44 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 08:24:50 +00:00
|
|
|
return evalOK;
|
|
|
|
}
|
|
|
|
|
2014-01-03 16:32:56 +00:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
nsScriptSecurityManager::JSPrincipalsSubsume(JSPrincipals *first,
|
|
|
|
JSPrincipals *second)
|
|
|
|
{
|
|
|
|
return nsJSPrincipals::get(first)->Subsumes(nsJSPrincipals::get(second));
|
|
|
|
}
|
|
|
|
|
2002-06-14 23:54:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::CheckSameOrigin(JSContext* cx,
|
|
|
|
nsIURI* aTargetURI)
|
|
|
|
{
|
2014-05-06 22:43:03 +00:00
|
|
|
MOZ_ASSERT_IF(cx, cx == nsContentUtils::GetCurrentJSContext());
|
2002-06-14 23:54:18 +00:00
|
|
|
|
|
|
|
// Get a principal from the context
|
2014-05-13 09:58:00 +00:00
|
|
|
nsIPrincipal* sourcePrincipal = nsContentUtils::SubjectPrincipal();
|
2003-10-21 22:11:49 +00:00
|
|
|
if (sourcePrincipal == mSystemPrincipal)
|
2002-06-14 23:54:18 +00:00
|
|
|
{
|
|
|
|
// This is a system (chrome) script, so allow access
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-07-09 00:10:02 +00:00
|
|
|
// Get the original URI from the source principal.
|
|
|
|
// This has the effect of ignoring any change to document.domain
|
|
|
|
// which must be done to avoid DNS spoofing (bug 154930)
|
2002-06-14 23:54:18 +00:00
|
|
|
nsCOMPtr<nsIURI> sourceURI;
|
2003-10-21 22:11:49 +00:00
|
|
|
sourcePrincipal->GetDomain(getter_AddRefs(sourceURI));
|
|
|
|
if (!sourceURI) {
|
|
|
|
sourcePrincipal->GetURI(getter_AddRefs(sourceURI));
|
|
|
|
NS_ENSURE_TRUE(sourceURI, NS_ERROR_FAILURE);
|
|
|
|
}
|
2002-06-14 23:54:18 +00:00
|
|
|
|
|
|
|
// Compare origins
|
2006-11-14 22:46:45 +00:00
|
|
|
if (!SecurityCompareURIs(sourceURI, aTargetURI))
|
2002-06-14 23:54:18 +00:00
|
|
|
{
|
|
|
|
ReportError(cx, NS_LITERAL_STRING("CheckSameOriginError"), sourceURI, aTargetURI);
|
2008-03-17 14:10:48 +00:00
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
2002-06-14 23:54:18 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::CheckSameOriginURI(nsIURI* aSourceURI,
|
2007-10-27 01:46:09 +00:00
|
|
|
nsIURI* aTargetURI,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool reportError)
|
2002-06-14 23:54:18 +00:00
|
|
|
{
|
2006-11-14 22:46:45 +00:00
|
|
|
if (!SecurityCompareURIs(aSourceURI, aTargetURI))
|
2002-06-14 23:54:18 +00:00
|
|
|
{
|
2007-10-27 01:46:09 +00:00
|
|
|
if (reportError) {
|
2012-07-30 14:20:58 +00:00
|
|
|
ReportError(nullptr, NS_LITERAL_STRING("CheckSameOriginError"),
|
2002-06-14 23:54:18 +00:00
|
|
|
aSourceURI, aTargetURI);
|
2007-10-27 01:46:09 +00:00
|
|
|
}
|
2002-06-14 23:54:18 +00:00
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
/*static*/ uint32_t
|
2008-10-08 13:16:27 +00:00
|
|
|
nsScriptSecurityManager::HashPrincipalByOrigin(nsIPrincipal* aPrincipal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
aPrincipal->GetDomain(getter_AddRefs(uri));
|
|
|
|
if (!uri)
|
|
|
|
aPrincipal->GetURI(getter_AddRefs(uri));
|
|
|
|
return SecurityHashURI(uri);
|
|
|
|
}
|
2003-06-18 23:48:57 +00:00
|
|
|
|
2012-10-24 17:50:25 +00:00
|
|
|
/* static */ bool
|
|
|
|
nsScriptSecurityManager::AppAttributesEqual(nsIPrincipal* aFirst,
|
|
|
|
nsIPrincipal* aSecond)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aFirst && aSecond, "Don't pass null pointers!");
|
|
|
|
|
|
|
|
uint32_t firstAppId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
|
|
|
|
if (!aFirst->GetUnknownAppId()) {
|
|
|
|
firstAppId = aFirst->GetAppId();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t secondAppId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
|
|
|
|
if (!aSecond->GetUnknownAppId()) {
|
|
|
|
secondAppId = aSecond->GetAppId();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((firstAppId == secondAppId) &&
|
|
|
|
(aFirst->GetIsInBrowserElement() == aSecond->GetIsInBrowserElement()));
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::CheckLoadURIFromScript(JSContext *cx, nsIURI *aURI)
|
|
|
|
{
|
|
|
|
// Get principal of currently executing script.
|
2014-05-06 22:43:03 +00:00
|
|
|
MOZ_ASSERT(cx == nsContentUtils::GetCurrentJSContext());
|
2014-05-13 09:58:00 +00:00
|
|
|
nsIPrincipal* principal = nsContentUtils::SubjectPrincipal();
|
2014-05-06 22:43:03 +00:00
|
|
|
nsresult rv = CheckLoadURIWithPrincipal(principal, aURI,
|
|
|
|
nsIScriptSecurityManager::STANDARD);
|
2006-04-02 20:58:26 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// OK to load
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
return NS_OK;
|
2006-04-02 20:58:26 +00:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
// See if we're attempting to load a file: URI. If so, let a
|
2011-12-30 17:35:52 +00:00
|
|
|
// UniversalXPConnect capability trump the above check.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isFile = false;
|
|
|
|
bool isRes = false;
|
2001-07-31 19:05:34 +00:00
|
|
|
if (NS_FAILED(aURI->SchemeIs("file", &isFile)) ||
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_FAILED(aURI->SchemeIs("resource", &isRes)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (isFile || isRes)
|
|
|
|
{
|
2014-05-19 11:39:00 +00:00
|
|
|
if (nsContentUtils::IsCallerChrome())
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report error.
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString spec;
|
2002-03-06 07:48:55 +00:00
|
|
|
if (NS_FAILED(aURI->GetAsciiSpec(spec)))
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString msg("Access to '");
|
2009-05-20 04:57:37 +00:00
|
|
|
msg.Append(spec);
|
|
|
|
msg.AppendLiteral("' from script denied");
|
|
|
|
SetPendingException(cx, msg.get());
|
2008-03-17 14:10:48 +00:00
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
}
|
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
/**
|
|
|
|
* Helper method to handle cases where a flag passed to
|
|
|
|
* CheckLoadURIWithPrincipal means denying loading if the given URI has certain
|
|
|
|
* nsIProtocolHandler flags set.
|
|
|
|
* @return if success, access is allowed. Otherwise, deny access
|
|
|
|
*/
|
|
|
|
static nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
DenyAccessIfURIHasFlags(nsIURI* aURI, uint32_t aURIFlags)
|
2006-11-10 23:49:08 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURI, "Must have URI!");
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool uriHasFlags;
|
2006-11-10 23:49:08 +00:00
|
|
|
nsresult rv =
|
|
|
|
NS_URIChainHasFlags(aURI, aURIFlags, &uriHasFlags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (uriHasFlags) {
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-25 16:55:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
|
|
|
|
nsIURI *aTargetURI,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags)
|
2004-04-25 16:55:27 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPrincipal, "CheckLoadURIWithPrincipal must have a principal");
|
2005-05-12 18:20:07 +00:00
|
|
|
// If someone passes a flag that we don't understand, we should
|
|
|
|
// fail, because they may need a security check that we don't
|
|
|
|
// provide.
|
2006-11-10 23:49:08 +00:00
|
|
|
NS_ENSURE_FALSE(aFlags & ~(nsIScriptSecurityManager::LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT |
|
2005-05-12 18:20:07 +00:00
|
|
|
nsIScriptSecurityManager::ALLOW_CHROME |
|
|
|
|
nsIScriptSecurityManager::DISALLOW_SCRIPT |
|
2012-09-13 14:16:17 +00:00
|
|
|
nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL |
|
|
|
|
nsIScriptSecurityManager::DONT_REPORT_ERRORS),
|
2005-05-12 18:20:07 +00:00
|
|
|
NS_ERROR_UNEXPECTED);
|
2004-04-25 16:55:27 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aPrincipal);
|
2009-01-01 23:45:23 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aTargetURI);
|
2004-04-25 16:55:27 +00:00
|
|
|
|
2012-03-14 18:55:47 +00:00
|
|
|
// If DISALLOW_INHERIT_PRINCIPAL is set, we prevent loading of URIs which
|
|
|
|
// would do such inheriting. That would be URIs that do not have their own
|
|
|
|
// security context. We do this even for the system principal.
|
|
|
|
if (aFlags & nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL) {
|
|
|
|
nsresult rv =
|
|
|
|
DenyAccessIfURIHasFlags(aTargetURI,
|
|
|
|
nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2004-04-25 16:55:27 +00:00
|
|
|
if (aPrincipal == mSystemPrincipal) {
|
|
|
|
// Allow access
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-03-14 18:55:47 +00:00
|
|
|
|
2004-04-25 16:55:27 +00:00
|
|
|
nsCOMPtr<nsIURI> sourceURI;
|
|
|
|
aPrincipal->GetURI(getter_AddRefs(sourceURI));
|
2007-08-07 02:09:16 +00:00
|
|
|
if (!sourceURI) {
|
2012-06-10 23:44:50 +00:00
|
|
|
nsCOMPtr<nsIExpandedPrincipal> expanded = do_QueryInterface(aPrincipal);
|
|
|
|
if (expanded) {
|
|
|
|
nsTArray< nsCOMPtr<nsIPrincipal> > *whiteList;
|
|
|
|
expanded->GetWhiteList(&whiteList);
|
|
|
|
for (uint32_t i = 0; i < whiteList->Length(); ++i) {
|
|
|
|
nsresult rv = CheckLoadURIWithPrincipal((*whiteList)[i],
|
|
|
|
aTargetURI,
|
|
|
|
aFlags);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Allow access if it succeeded with one of the white listed principals
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2013-04-27 23:49:43 +00:00
|
|
|
// None of our whitelisted principals worked.
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
2012-06-10 23:44:50 +00:00
|
|
|
}
|
|
|
|
NS_ERROR("Non-system principals or expanded principal passed to CheckLoadURIWithPrincipal "
|
2007-08-07 02:09:16 +00:00
|
|
|
"must have a URI!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2004-04-25 16:55:27 +00:00
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
// Automatic loads are not allowed from certain protocols.
|
|
|
|
if (aFlags & nsIScriptSecurityManager::LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT) {
|
|
|
|
nsresult rv =
|
|
|
|
DenyAccessIfURIHasFlags(sourceURI,
|
|
|
|
nsIProtocolHandler::URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2001-04-17 01:21:44 +00:00
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
// If either URI is a nested URI, get the base URI
|
|
|
|
nsCOMPtr<nsIURI> sourceBaseURI = NS_GetInnermostURI(sourceURI);
|
|
|
|
nsCOMPtr<nsIURI> targetBaseURI = NS_GetInnermostURI(aTargetURI);
|
|
|
|
|
2001-08-02 20:32:48 +00:00
|
|
|
//-- get the target scheme
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString targetScheme;
|
2006-11-10 23:49:08 +00:00
|
|
|
nsresult rv = targetBaseURI->GetScheme(targetScheme);
|
2001-08-02 20:32:48 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
//-- Some callers do not allow loading javascript:
|
|
|
|
if ((aFlags & nsIScriptSecurityManager::DISALLOW_SCRIPT) &&
|
|
|
|
targetScheme.EqualsLiteral("javascript"))
|
2003-05-29 21:51:34 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
|
2010-03-03 07:51:09 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(errorTag, "CheckLoadURIError");
|
2012-09-13 14:16:17 +00:00
|
|
|
bool reportErrors = !(aFlags & nsIScriptSecurityManager::DONT_REPORT_ERRORS);
|
2010-03-03 07:51:09 +00:00
|
|
|
|
|
|
|
// Check for uris that are only loadable by principals that subsume them
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasFlags;
|
2010-03-03 07:51:09 +00:00
|
|
|
rv = NS_URIChainHasFlags(targetBaseURI,
|
|
|
|
nsIProtocolHandler::URI_LOADABLE_BY_SUBSUMERS,
|
|
|
|
&hasFlags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (hasFlags) {
|
2012-08-20 18:34:33 +00:00
|
|
|
return aPrincipal->CheckMayLoad(targetBaseURI, true, false);
|
2010-03-03 07:51:09 +00:00
|
|
|
}
|
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
//-- get the source scheme
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString sourceScheme;
|
2007-01-26 04:33:02 +00:00
|
|
|
rv = sourceBaseURI->GetScheme(sourceScheme);
|
2006-11-10 23:49:08 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2008-03-28 03:46:15 +00:00
|
|
|
if (sourceScheme.LowerCaseEqualsLiteral(NS_NULLPRINCIPAL_SCHEME)) {
|
|
|
|
// A null principal can target its own URI.
|
|
|
|
if (sourceURI == aTargetURI) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (targetScheme.Equals(sourceScheme,
|
|
|
|
nsCaseInsensitiveCStringComparator()))
|
2006-03-15 11:03:25 +00:00
|
|
|
{
|
2006-06-19 21:08:45 +00:00
|
|
|
// every scheme can access another URI from the same scheme,
|
2012-09-25 19:33:01 +00:00
|
|
|
// as long as they don't represent null principals...
|
|
|
|
// Or they don't require an special permission to do so
|
|
|
|
// See bug#773886
|
|
|
|
|
|
|
|
bool hasFlags;
|
|
|
|
rv = NS_URIChainHasFlags(targetBaseURI,
|
|
|
|
nsIProtocolHandler::URI_CROSS_ORIGIN_NEEDS_WEBAPPS_PERM,
|
|
|
|
&hasFlags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (hasFlags) {
|
|
|
|
// In this case, we allow opening only if the source and target URIS
|
|
|
|
// are on the same domain, or the opening URI has the webapps
|
|
|
|
// permision granted
|
|
|
|
if (!SecurityCompareURIs(sourceBaseURI,targetBaseURI) &&
|
|
|
|
!nsContentUtils::IsExactSitePermAllow(aPrincipal,WEBAPPS_PERM_NAME)){
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
}
|
2006-03-15 11:03:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
// If the schemes don't match, the policy is specified by the protocol
|
|
|
|
// flags on the target URI. Note that the order of policy checks here is
|
|
|
|
// very important! We start from most restrictive and work our way down.
|
|
|
|
// Note that since we're working with the innermost URI, we can just use
|
|
|
|
// the methods that work on chains of nested URIs and they will only look
|
|
|
|
// at the flags for our one URI.
|
|
|
|
|
|
|
|
// Check for system target URI
|
|
|
|
rv = DenyAccessIfURIHasFlags(targetBaseURI,
|
|
|
|
nsIProtocolHandler::URI_DANGEROUS_TO_LOAD);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Deny access, since the origin principal is not system
|
2012-09-13 14:16:17 +00:00
|
|
|
if (reportErrors) {
|
|
|
|
ReportError(nullptr, errorTag, sourceURI, aTargetURI);
|
|
|
|
}
|
2006-11-10 23:49:08 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2005-09-09 18:43:45 +00:00
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
// Check for chrome target URI
|
|
|
|
rv = NS_URIChainHasFlags(targetBaseURI,
|
|
|
|
nsIProtocolHandler::URI_IS_UI_RESOURCE,
|
|
|
|
&hasFlags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (hasFlags) {
|
|
|
|
if (aFlags & nsIScriptSecurityManager::ALLOW_CHROME) {
|
2008-04-12 21:26:19 +00:00
|
|
|
if (!targetScheme.EqualsLiteral("chrome")) {
|
|
|
|
// for now don't change behavior for resource: or moz-icon:
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allow load only if chrome package is whitelisted
|
|
|
|
nsCOMPtr<nsIXULChromeRegistry> reg(do_GetService(
|
|
|
|
NS_CHROMEREGISTRY_CONTRACTID));
|
|
|
|
if (reg) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool accessAllowed = false;
|
2008-04-12 21:26:19 +00:00
|
|
|
reg->AllowContentToAccess(targetBaseURI, &accessAllowed);
|
|
|
|
if (accessAllowed) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2006-11-10 23:49:08 +00:00
|
|
|
}
|
2005-09-09 18:43:45 +00:00
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
// resource: and chrome: are equivalent, securitywise
|
|
|
|
// That's bogus!! Fix this. But watch out for
|
|
|
|
// the view-source stylesheet?
|
2011-09-29 06:19:26 +00:00
|
|
|
bool sourceIsChrome;
|
2006-11-10 23:49:08 +00:00
|
|
|
rv = NS_URIChainHasFlags(sourceBaseURI,
|
|
|
|
nsIProtocolHandler::URI_IS_UI_RESOURCE,
|
|
|
|
&sourceIsChrome);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (sourceIsChrome) {
|
|
|
|
return NS_OK;
|
1999-09-07 02:54:19 +00:00
|
|
|
}
|
2012-09-13 14:16:17 +00:00
|
|
|
if (reportErrors) {
|
|
|
|
ReportError(nullptr, errorTag, sourceURI, aTargetURI);
|
|
|
|
}
|
2006-11-10 23:49:08 +00:00
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
1999-09-07 20:40:20 +00:00
|
|
|
}
|
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
// Check for target URI pointing to a file
|
|
|
|
rv = NS_URIChainHasFlags(targetBaseURI,
|
|
|
|
nsIProtocolHandler::URI_IS_LOCAL_FILE,
|
|
|
|
&hasFlags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (hasFlags) {
|
2014-05-09 16:59:22 +00:00
|
|
|
// Allow domains that were whitelisted in the prefs. In 99.9% of cases,
|
|
|
|
// this array is empty.
|
|
|
|
for (size_t i = 0; i < mFileURIWhitelist.Length(); ++i) {
|
|
|
|
if (SecurityCompareURIs(mFileURIWhitelist[i], sourceURI)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
// resource: and chrome: are equivalent, securitywise
|
|
|
|
// That's bogus!! Fix this. But watch out for
|
|
|
|
// the view-source stylesheet?
|
2011-09-29 06:19:26 +00:00
|
|
|
bool sourceIsChrome;
|
2006-11-10 23:49:08 +00:00
|
|
|
rv = NS_URIChainHasFlags(sourceURI,
|
|
|
|
nsIProtocolHandler::URI_IS_UI_RESOURCE,
|
|
|
|
&sourceIsChrome);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (sourceIsChrome) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-13 14:16:17 +00:00
|
|
|
if (reportErrors) {
|
|
|
|
ReportError(nullptr, errorTag, sourceURI, aTargetURI);
|
|
|
|
}
|
2006-11-10 23:49:08 +00:00
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
2000-03-11 06:32:42 +00:00
|
|
|
|
2006-11-10 23:49:08 +00:00
|
|
|
// OK, everyone is allowed to load this, since unflagged handlers are
|
|
|
|
// deprecated but treated as URI_LOADABLE_BY_ANYONE. But check whether we
|
|
|
|
// need to warn. At some point we'll want to make this warning into an
|
|
|
|
// error and treat unflagged handlers as URI_DANGEROUS_TO_LOAD.
|
|
|
|
rv = NS_URIChainHasFlags(targetBaseURI,
|
|
|
|
nsIProtocolHandler::URI_LOADABLE_BY_ANYONE,
|
|
|
|
&hasFlags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!hasFlags) {
|
|
|
|
nsXPIDLString message;
|
|
|
|
NS_ConvertASCIItoUTF16 ucsTargetScheme(targetScheme);
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* formatStrings[] = { ucsTargetScheme.get() };
|
2006-11-10 23:49:08 +00:00
|
|
|
rv = sStrBundle->
|
2013-12-13 01:50:01 +00:00
|
|
|
FormatStringFromName(MOZ_UTF16("ProtocolFlagError"),
|
2006-11-10 23:49:08 +00:00
|
|
|
formatStrings,
|
2011-10-11 05:50:08 +00:00
|
|
|
ArrayLength(formatStrings),
|
2006-11-10 23:49:08 +00:00
|
|
|
getter_Copies(message));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIConsoleService> console(
|
|
|
|
do_GetService("@mozilla.org/consoleservice;1"));
|
|
|
|
NS_ENSURE_TRUE(console, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
console->LogStringMessage(message.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-11 06:32:42 +00:00
|
|
|
return NS_OK;
|
1999-09-01 00:54:35 +00:00
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
nsresult
|
2002-06-14 23:54:18 +00:00
|
|
|
nsScriptSecurityManager::ReportError(JSContext* cx, const nsAString& messageTag,
|
|
|
|
nsIURI* aSource, nsIURI* aTarget)
|
2001-04-17 01:21:44 +00:00
|
|
|
{
|
2002-06-14 23:54:18 +00:00
|
|
|
nsresult rv;
|
|
|
|
NS_ENSURE_TRUE(aSource && aTarget, NS_ERROR_NULL_POINTER);
|
2001-04-17 01:21:44 +00:00
|
|
|
|
2002-06-14 23:54:18 +00:00
|
|
|
// Get the source URL spec
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString sourceSpec;
|
2002-06-14 23:54:18 +00:00
|
|
|
rv = aSource->GetAsciiSpec(sourceSpec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Get the target URL spec
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString targetSpec;
|
2002-06-14 23:54:18 +00:00
|
|
|
rv = aTarget->GetAsciiSpec(targetSpec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Localize the error message
|
|
|
|
nsXPIDLString message;
|
2006-02-03 14:18:39 +00:00
|
|
|
NS_ConvertASCIItoUTF16 ucsSourceSpec(sourceSpec);
|
|
|
|
NS_ConvertASCIItoUTF16 ucsTargetSpec(targetSpec);
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t *formatStrings[] = { ucsSourceSpec.get(), ucsTargetSpec.get() };
|
2003-07-29 05:28:00 +00:00
|
|
|
rv = sStrBundle->FormatStringFromName(PromiseFlatString(messageTag).get(),
|
|
|
|
formatStrings,
|
2011-10-11 05:50:08 +00:00
|
|
|
ArrayLength(formatStrings),
|
2003-07-29 05:28:00 +00:00
|
|
|
getter_Copies(message));
|
2002-06-14 23:54:18 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// If a JS context was passed in, set a JS exception.
|
|
|
|
// Otherwise, print the error message directly to the JS console
|
|
|
|
// and to standard output
|
|
|
|
if (cx)
|
2001-04-17 01:21:44 +00:00
|
|
|
{
|
2004-09-01 07:53:32 +00:00
|
|
|
SetPendingException(cx, message.get());
|
2001-04-17 01:21:44 +00:00
|
|
|
}
|
2002-06-14 23:54:18 +00:00
|
|
|
else // Print directly to the console
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIConsoleService> console(
|
|
|
|
do_GetService("@mozilla.org/consoleservice;1"));
|
|
|
|
NS_ENSURE_TRUE(console, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
console->LogStringMessage(message.get());
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2001-04-17 01:21:44 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 22:15:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::CheckLoadURIStrWithPrincipal(nsIPrincipal* aPrincipal,
|
|
|
|
const nsACString& aTargetURIStr,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags)
|
2006-08-21 22:15:20 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2001-04-17 01:21:44 +00:00
|
|
|
nsCOMPtr<nsIURI> target;
|
2005-02-02 07:17:53 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(target), aTargetURIStr,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr, nullptr, sIOService);
|
2001-04-17 01:21:44 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-04-25 03:24:43 +00:00
|
|
|
|
2006-08-21 22:15:20 +00:00
|
|
|
rv = CheckLoadURIWithPrincipal(aPrincipal, target, aFlags);
|
2013-10-09 02:32:38 +00:00
|
|
|
if (rv == NS_ERROR_DOM_BAD_URI) {
|
|
|
|
// Don't warn because NS_ERROR_DOM_BAD_URI is one of the expected
|
|
|
|
// return values.
|
|
|
|
return rv;
|
|
|
|
}
|
2006-04-25 03:24:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Now start testing fixup -- since aTargetURIStr is a string, not
|
|
|
|
// an nsIURI, we may well end up fixing it up before loading.
|
|
|
|
// Note: This needs to stay in sync with the nsIURIFixup api.
|
|
|
|
nsCOMPtr<nsIURIFixup> fixup = do_GetService(NS_URIFIXUP_CONTRACTID);
|
|
|
|
if (!fixup) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t flags[] = {
|
2006-04-25 03:24:43 +00:00
|
|
|
nsIURIFixup::FIXUP_FLAG_NONE,
|
2014-01-12 20:02:27 +00:00
|
|
|
nsIURIFixup::FIXUP_FLAG_FIX_SCHEME_TYPOS,
|
2006-04-25 03:24:43 +00:00
|
|
|
nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP,
|
|
|
|
nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI,
|
|
|
|
nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP |
|
|
|
|
nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI
|
|
|
|
};
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(flags); ++i) {
|
2013-05-01 11:04:21 +00:00
|
|
|
rv = fixup->CreateFixupURI(aTargetURIStr, flags[i], nullptr,
|
2006-04-25 03:24:43 +00:00
|
|
|
getter_AddRefs(target));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-08-21 22:15:20 +00:00
|
|
|
rv = CheckLoadURIWithPrincipal(aPrincipal, target, aFlags);
|
2013-10-09 02:32:38 +00:00
|
|
|
if (rv == NS_ERROR_DOM_BAD_URI) {
|
|
|
|
// Don't warn because NS_ERROR_DOM_BAD_URI is one of the expected
|
|
|
|
// return values.
|
|
|
|
return rv;
|
|
|
|
}
|
2006-04-25 03:24:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2001-04-17 01:21:44 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 00:43:35 +00:00
|
|
|
bool
|
|
|
|
nsScriptSecurityManager::ScriptAllowed(JSObject *aGlobal)
|
2000-01-18 21:54:01 +00:00
|
|
|
{
|
2013-11-13 00:43:35 +00:00
|
|
|
MOZ_ASSERT(aGlobal);
|
|
|
|
MOZ_ASSERT(JS_IsGlobalObject(aGlobal) || js::IsOuterObject(aGlobal));
|
2002-07-02 23:26:08 +00:00
|
|
|
|
2013-11-13 00:43:35 +00:00
|
|
|
// Check the bits on the compartment private.
|
Bug 913734 - Stop consulting domain policies in CAPS. r=mrbkap
The whole LookupPolicy juggernaut is basically a mechanism for setting custom
per-(protocol, origin, property, action) access control in the preferences
service.
There are two sets of preferences currently in all.js. One of them is set up
for mailnews, for the mailbox:, imap:, and news: protocols. According to jst,
this was designed as a whack-a-mole security mechanism for javascript running
in HTML email. IIUC, we no longer allow JS to run at all in mailnews, so this
is obsolete.
The other mechanism appears to be our old-fashioned implementation of the
same-origin policy, which has been obsoleted by the new compartment
architecture.
In addition, most of this stuff was obsoleted by the new dom bindings, since
these DOM classes no longer go through XPCWrappedNativeJSOps, and thus no
longer trigger these security checks at all.
We stop using the infrastructure in this patch, and rip it out in the next one.
2013-12-14 03:15:43 +00:00
|
|
|
return xpc::Scriptability::Get(aGlobal).Allowed();
|
2013-11-13 00:43:31 +00:00
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
///////////////// Principals ///////////////////////
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::GetSystemPrincipal(nsIPrincipal **result)
|
|
|
|
{
|
2003-10-21 22:11:49 +00:00
|
|
|
NS_ADDREF(*result = mSystemPrincipal);
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-01-27 01:42:20 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsScriptSecurityManager::CreateCodebasePrincipal(nsIURI* aURI, uint32_t aAppId,
|
2012-07-19 22:32:08 +00:00
|
|
|
bool aInMozBrowser,
|
|
|
|
nsIPrincipal **result)
|
1999-09-01 00:54:35 +00:00
|
|
|
{
|
2006-04-02 20:58:26 +00:00
|
|
|
// I _think_ it's safe to not create null principals here based on aURI.
|
|
|
|
// At least all the callers would do the right thing in those cases, as far
|
|
|
|
// as I can tell. --bz
|
2010-03-03 07:51:09 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURIWithPrincipal> uriPrinc = do_QueryInterface(aURI);
|
|
|
|
if (uriPrinc) {
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
uriPrinc->GetPrincipal(getter_AddRefs(principal));
|
|
|
|
if (!principal || principal == mSystemPrincipal) {
|
|
|
|
return CallCreateInstance(NS_NULLPRINCIPAL_CONTRACTID, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
principal.forget(result);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
nsRefPtr<nsPrincipal> codebase = new nsPrincipal();
|
1999-09-01 00:54:35 +00:00
|
|
|
if (!codebase)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-10-21 22:11:49 +00:00
|
|
|
|
2012-10-22 06:29:56 +00:00
|
|
|
nsresult rv = codebase->Init(aURI, aAppId, aInMozBrowser);
|
2003-10-21 22:11:49 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
NS_ADDREF(*result = codebase);
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-01-27 01:42:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-07-21 07:29:40 +00:00
|
|
|
nsScriptSecurityManager::GetSimpleCodebasePrincipal(nsIURI* aURI,
|
2012-07-20 03:28:08 +00:00
|
|
|
nsIPrincipal** aPrincipal)
|
|
|
|
{
|
2012-07-21 07:29:40 +00:00
|
|
|
return GetCodebasePrincipalInternal(aURI,
|
|
|
|
nsIScriptSecurityManager::UNKNOWN_APP_ID,
|
|
|
|
false, aPrincipal);
|
2012-07-20 03:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::GetNoAppCodebasePrincipal(nsIURI* aURI,
|
|
|
|
nsIPrincipal** aPrincipal)
|
|
|
|
{
|
|
|
|
return GetCodebasePrincipalInternal(aURI, nsIScriptSecurityManager::NO_APP_ID,
|
2012-07-21 07:29:40 +00:00
|
|
|
false, aPrincipal);
|
2012-07-20 03:28:08 +00:00
|
|
|
}
|
|
|
|
|
2012-10-30 21:24:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::GetCodebasePrincipal(nsIURI* aURI,
|
|
|
|
nsIPrincipal** aPrincipal)
|
|
|
|
{
|
|
|
|
return GetNoAppCodebasePrincipal(aURI, aPrincipal);
|
|
|
|
}
|
|
|
|
|
2012-07-20 03:28:08 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::GetAppCodebasePrincipal(nsIURI* aURI,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aAppId,
|
2012-07-20 03:28:08 +00:00
|
|
|
bool aInMozBrowser,
|
|
|
|
nsIPrincipal** aPrincipal)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID,
|
|
|
|
NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
return GetCodebasePrincipalInternal(aURI, aAppId, aInMozBrowser, aPrincipal);
|
|
|
|
}
|
|
|
|
|
2014-05-16 22:59:36 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::
|
|
|
|
GetLoadContextCodebasePrincipal(nsIURI* aURI,
|
|
|
|
nsILoadContext* aLoadContext,
|
|
|
|
nsIPrincipal** aPrincipal)
|
|
|
|
{
|
|
|
|
uint32_t appId;
|
|
|
|
aLoadContext->GetAppId(&appId);
|
|
|
|
bool isInBrowserElement;
|
|
|
|
aLoadContext->GetIsInBrowserElement(&isInBrowserElement);
|
|
|
|
return GetCodebasePrincipalInternal(aURI,
|
|
|
|
appId,
|
|
|
|
isInBrowserElement,
|
|
|
|
aPrincipal);
|
|
|
|
}
|
|
|
|
|
2012-07-20 07:06:24 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::GetDocShellCodebasePrincipal(nsIURI* aURI,
|
|
|
|
nsIDocShell* aDocShell,
|
|
|
|
nsIPrincipal** aPrincipal)
|
|
|
|
{
|
2012-11-10 18:32:36 +00:00
|
|
|
return GetCodebasePrincipalInternal(aURI,
|
|
|
|
aDocShell->GetAppId(),
|
|
|
|
aDocShell->GetIsInBrowserElement(),
|
2012-07-20 07:06:24 +00:00
|
|
|
aPrincipal);
|
|
|
|
}
|
|
|
|
|
2012-07-20 03:28:08 +00:00
|
|
|
nsresult
|
|
|
|
nsScriptSecurityManager::GetCodebasePrincipalInternal(nsIURI *aURI,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aAppId,
|
2012-07-21 07:29:40 +00:00
|
|
|
bool aInMozBrowser,
|
|
|
|
nsIPrincipal **result)
|
2001-01-27 01:42:20 +00:00
|
|
|
{
|
2007-08-07 02:09:16 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2012-07-20 03:28:08 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool inheritsPrincipal;
|
2006-05-02 18:54:19 +00:00
|
|
|
nsresult rv =
|
|
|
|
NS_URIChainHasFlags(aURI,
|
2006-11-10 23:49:08 +00:00
|
|
|
nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
|
|
|
|
&inheritsPrincipal);
|
|
|
|
if (NS_FAILED(rv) || inheritsPrincipal) {
|
2006-05-02 18:54:19 +00:00
|
|
|
return CallCreateInstance(NS_NULLPRINCIPAL_CONTRACTID, result);
|
|
|
|
}
|
2012-07-19 22:32:08 +00:00
|
|
|
|
2001-11-16 06:17:24 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
2012-07-20 03:28:08 +00:00
|
|
|
rv = CreateCodebasePrincipal(aURI, aAppId, aInMozBrowser,
|
|
|
|
getter_AddRefs(principal));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-10-21 22:11:49 +00:00
|
|
|
NS_IF_ADDREF(*result = principal);
|
2000-03-31 00:31:18 +00:00
|
|
|
|
1999-08-29 21:58:42 +00:00
|
|
|
return NS_OK;
|
1999-08-20 09:51:02 +00:00
|
|
|
}
|
|
|
|
|
2002-02-20 05:51:05 +00:00
|
|
|
// static
|
2005-04-10 23:27:07 +00:00
|
|
|
nsIPrincipal*
|
2013-11-13 00:43:35 +00:00
|
|
|
nsScriptSecurityManager::doGetObjectPrincipal(JSObject *aObj)
|
2012-06-28 21:47:55 +00:00
|
|
|
{
|
|
|
|
JSCompartment *compartment = js::GetObjectCompartment(aObj);
|
|
|
|
JSPrincipals *principals = JS_GetCompartmentPrincipals(compartment);
|
2013-09-17 22:29:11 +00:00
|
|
|
return nsJSPrincipals::get(principals);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-02-13 04:20:46 +00:00
|
|
|
nsScriptSecurityManager::CanCreateWrapper(JSContext *cx,
|
2001-07-31 19:05:34 +00:00
|
|
|
const nsIID &aIID,
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsISupports *aObj,
|
2013-12-14 03:15:43 +00:00
|
|
|
nsIClassInfo *aClassInfo)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
{
|
|
|
|
// XXX Special case for nsIXPCException ?
|
2012-07-30 14:20:58 +00:00
|
|
|
ClassInfoData objClassInfo = ClassInfoData(aClassInfo, nullptr);
|
2003-07-29 05:28:00 +00:00
|
|
|
if (objClassInfo.IsDOMClass())
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
1999-11-20 07:28:34 +00:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2013-12-05 03:15:40 +00:00
|
|
|
// We give remote-XUL whitelisted domains a free pass here. See bug 932906.
|
2014-06-03 01:04:21 +00:00
|
|
|
if (!xpc::AllowContentXBLScope(js::GetContextCompartment(cx)))
|
2013-12-05 03:15:40 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-19 11:39:00 +00:00
|
|
|
if (nsContentUtils::IsCallerChrome())
|
2001-08-14 00:18:58 +00:00
|
|
|
{
|
2014-01-16 23:45:40 +00:00
|
|
|
return NS_OK;
|
2003-10-21 22:11:49 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 23:45:40 +00:00
|
|
|
//-- Access denied, report an error
|
|
|
|
NS_ConvertUTF8toUTF16 strName("CreateWrapperDenied");
|
|
|
|
nsAutoCString origin;
|
2014-05-13 09:58:00 +00:00
|
|
|
nsIPrincipal* subjectPrincipal = nsContentUtils::SubjectPrincipal();
|
2014-05-06 22:43:03 +00:00
|
|
|
GetPrincipalDomainOrigin(subjectPrincipal, origin);
|
2014-01-16 23:45:40 +00:00
|
|
|
NS_ConvertUTF8toUTF16 originUnicode(origin);
|
|
|
|
NS_ConvertUTF8toUTF16 classInfoName(objClassInfo.GetName());
|
|
|
|
const char16_t* formatStrings[] = {
|
|
|
|
classInfoName.get(),
|
|
|
|
originUnicode.get()
|
|
|
|
};
|
|
|
|
uint32_t length = ArrayLength(formatStrings);
|
|
|
|
if (originUnicode.IsEmpty()) {
|
|
|
|
--length;
|
|
|
|
} else {
|
|
|
|
strName.AppendLiteral("ForOrigin");
|
|
|
|
}
|
|
|
|
nsXPIDLString errorMsg;
|
2014-05-06 22:43:03 +00:00
|
|
|
nsresult rv = sStrBundle->FormatStringFromName(strName.get(),
|
|
|
|
formatStrings,
|
|
|
|
length,
|
|
|
|
getter_Copies(errorMsg));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-01-16 23:45:40 +00:00
|
|
|
|
|
|
|
SetPendingException(cx, errorMsg.get());
|
|
|
|
return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED;
|
1999-11-20 07:28:34 +00:00
|
|
|
}
|
|
|
|
|
2000-05-16 03:40:51 +00:00
|
|
|
NS_IMETHODIMP
|
2002-02-13 04:20:46 +00:00
|
|
|
nsScriptSecurityManager::CanCreateInstance(JSContext *cx,
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
const nsCID &aCID)
|
2000-05-16 03:40:51 +00:00
|
|
|
{
|
2014-05-19 11:39:00 +00:00
|
|
|
if (nsContentUtils::IsCallerChrome()) {
|
2014-01-16 23:45:40 +00:00
|
|
|
return NS_OK;
|
2001-08-14 00:18:58 +00:00
|
|
|
}
|
2014-01-16 23:45:40 +00:00
|
|
|
|
|
|
|
//-- Access denied, report an error
|
|
|
|
nsAutoCString errorMsg("Permission denied to create instance of class. CID=");
|
|
|
|
char cidStr[NSID_LENGTH];
|
|
|
|
aCID.ToProvidedString(cidStr);
|
|
|
|
errorMsg.Append(cidStr);
|
|
|
|
SetPendingException(cx, errorMsg.get());
|
|
|
|
return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-02-13 04:20:46 +00:00
|
|
|
nsScriptSecurityManager::CanGetService(JSContext *cx,
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
const nsCID &aCID)
|
|
|
|
{
|
2014-05-19 11:39:00 +00:00
|
|
|
if (nsContentUtils::IsCallerChrome()) {
|
2014-01-16 23:45:40 +00:00
|
|
|
return NS_OK;
|
2001-08-14 00:18:58 +00:00
|
|
|
}
|
2003-10-21 22:11:49 +00:00
|
|
|
|
2014-01-16 23:45:40 +00:00
|
|
|
//-- Access denied, report an error
|
|
|
|
nsAutoCString errorMsg("Permission denied to get service. CID=");
|
|
|
|
char cidStr[NSID_LENGTH];
|
|
|
|
aCID.ToProvidedString(cidStr);
|
|
|
|
errorMsg.Append(cidStr);
|
|
|
|
SetPendingException(cx, errorMsg.get());
|
|
|
|
return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
}
|
|
|
|
|
2005-11-08 20:47:16 +00:00
|
|
|
/////////////////////////////////////////////
|
|
|
|
// Method implementing nsIChannelEventSink //
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
NS_IMETHODIMP
|
2010-08-05 02:15:55 +00:00
|
|
|
nsScriptSecurityManager::AsyncOnChannelRedirect(nsIChannel* oldChannel,
|
|
|
|
nsIChannel* newChannel,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t redirFlags,
|
2010-08-05 02:15:55 +00:00
|
|
|
nsIAsyncVerifyRedirectCallback *cb)
|
2005-11-08 20:47:16 +00:00
|
|
|
{
|
2006-11-22 18:27:54 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> oldPrincipal;
|
|
|
|
GetChannelPrincipal(oldChannel, getter_AddRefs(oldPrincipal));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> newURI;
|
2005-11-08 20:47:16 +00:00
|
|
|
newChannel->GetURI(getter_AddRefs(newURI));
|
2008-11-26 01:50:04 +00:00
|
|
|
nsCOMPtr<nsIURI> newOriginalURI;
|
|
|
|
newChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));
|
2005-11-08 20:47:16 +00:00
|
|
|
|
2008-11-26 01:50:04 +00:00
|
|
|
NS_ENSURE_STATE(oldPrincipal && newURI && newOriginalURI);
|
2005-11-08 20:47:16 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint32_t flags =
|
2006-11-10 23:49:08 +00:00
|
|
|
nsIScriptSecurityManager::LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT |
|
|
|
|
nsIScriptSecurityManager::DISALLOW_SCRIPT;
|
2008-11-26 01:50:04 +00:00
|
|
|
nsresult rv = CheckLoadURIWithPrincipal(oldPrincipal, newURI, flags);
|
|
|
|
if (NS_SUCCEEDED(rv) && newOriginalURI != newURI) {
|
|
|
|
rv = CheckLoadURIWithPrincipal(oldPrincipal, newOriginalURI, flags);
|
|
|
|
}
|
2010-08-05 02:15:55 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
cb->OnRedirectVerifyCallback(NS_OK);
|
|
|
|
return NS_OK;
|
2005-11-08 20:47:16 +00:00
|
|
|
}
|
|
|
|
|
2005-02-06 12:39:31 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
/////////////////////////////////////
|
|
|
|
// Method implementing nsIObserver //
|
|
|
|
/////////////////////////////////////
|
2011-06-20 03:00:16 +00:00
|
|
|
const char sJSEnabledPrefName[] = "javascript.enabled";
|
|
|
|
const char sFileOriginPolicyPrefName[] =
|
|
|
|
"security.fileuri.strict_origin_policy";
|
2001-10-02 21:56:51 +00:00
|
|
|
|
2011-06-20 03:00:16 +00:00
|
|
|
static const char* kObservedPrefs[] = {
|
|
|
|
sJSEnabledPrefName,
|
|
|
|
sFileOriginPolicyPrefName,
|
2014-05-09 16:59:22 +00:00
|
|
|
"capability.policy.",
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr
|
2011-06-20 03:00:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_IMETHODIMP
|
2002-02-13 04:20:46 +00:00
|
|
|
nsScriptSecurityManager::Observe(nsISupports* aObject, const char* aTopic,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* aMessage)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
{
|
2014-05-09 16:59:22 +00:00
|
|
|
ScriptSecurityPrefChanged();
|
|
|
|
return NS_OK;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
}
|
2000-05-16 03:40:51 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
/////////////////////////////////////////////
|
|
|
|
// Constructor, Destructor, Initialization //
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
nsScriptSecurityManager::nsScriptSecurityManager(void)
|
2013-12-14 03:15:43 +00:00
|
|
|
: mPrefInitialized(false)
|
|
|
|
, mIsJavaScriptEnabled(false)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
{
|
2013-07-18 17:59:53 +00:00
|
|
|
static_assert(sizeof(intptr_t) == sizeof(void*),
|
|
|
|
"intptr_t and void* have different lengths on this platform. "
|
|
|
|
"This may cause a security failure with the SecurityLevel union.");
|
2003-01-17 01:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsScriptSecurityManager::Init()
|
|
|
|
{
|
2009-01-08 04:42:15 +00:00
|
|
|
InitPrefs();
|
2001-11-16 06:17:24 +00:00
|
|
|
|
2010-04-11 13:55:24 +00:00
|
|
|
nsresult rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
|
2003-10-21 22:11:49 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-05-14 09:24:41 +00:00
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
|
|
|
if (!bundleService)
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-07-29 05:28:00 +00:00
|
|
|
|
2005-03-08 17:21:36 +00:00
|
|
|
rv = bundleService->CreateBundle("chrome://global/locale/security/caps.properties", &sStrBundle);
|
2003-07-29 05:28:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-04-02 21:10:23 +00:00
|
|
|
// Create our system principal singleton
|
|
|
|
nsRefPtr<nsSystemPrincipal> system = new nsSystemPrincipal();
|
|
|
|
NS_ENSURE_TRUE(system, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
mSystemPrincipal = system;
|
|
|
|
|
2001-11-16 06:17:24 +00:00
|
|
|
//-- Register security check callback in the JS engine
|
|
|
|
// Currently this is used to control access to function.caller
|
2013-05-29 23:49:11 +00:00
|
|
|
rv = nsXPConnect::XPConnect()->GetRuntime(&sRuntime);
|
2003-01-17 01:00:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-11-16 06:17:24 +00:00
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
static const JSSecurityCallbacks securityCallbacks = {
|
2014-01-03 16:32:56 +00:00
|
|
|
ContentSecurityPolicyPermitsJSAction,
|
|
|
|
JSPrincipalsSubsume,
|
2008-09-05 23:26:04 +00:00
|
|
|
};
|
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
MOZ_ASSERT(!JS_GetSecurityCallbacks(sRuntime));
|
|
|
|
JS_SetSecurityCallbacks(sRuntime, &securityCallbacks);
|
|
|
|
JS_InitDestroyPrincipalsCallback(sRuntime, nsJSPrincipals::Destroy);
|
2001-11-16 06:17:24 +00:00
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
JS_SetTrustedPrincipals(sRuntime, system);
|
2011-06-30 16:26:56 +00:00
|
|
|
|
2003-01-17 01:00:15 +00:00
|
|
|
return NS_OK;
|
2000-05-16 03:40:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 19:33:45 +00:00
|
|
|
static StaticRefPtr<nsScriptSecurityManager> gScriptSecMan;
|
2003-01-17 01:00:15 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsScriptSecurityManager::~nsScriptSecurityManager(void)
|
|
|
|
{
|
2011-06-20 03:00:16 +00:00
|
|
|
Preferences::RemoveObservers(this, kObservedPrefs);
|
2013-11-13 00:43:35 +00:00
|
|
|
if (mDomainPolicy)
|
|
|
|
mDomainPolicy->Deactivate();
|
|
|
|
MOZ_ASSERT(!mDomainPolicy);
|
2002-02-13 04:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScriptSecurityManager::Shutdown()
|
|
|
|
{
|
2005-06-07 21:57:56 +00:00
|
|
|
if (sRuntime) {
|
2013-04-03 00:16:25 +00:00
|
|
|
JS_SetSecurityCallbacks(sRuntime, nullptr);
|
|
|
|
JS_SetTrustedPrincipals(sRuntime, nullptr);
|
2012-07-30 14:20:58 +00:00
|
|
|
sRuntime = nullptr;
|
2005-06-07 21:57:56 +00:00
|
|
|
}
|
2003-07-24 05:15:20 +00:00
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
NS_IF_RELEASE(sIOService);
|
2003-07-29 05:28:00 +00:00
|
|
|
NS_IF_RELEASE(sStrBundle);
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
|
|
|
nsScriptSecurityManager *
|
|
|
|
nsScriptSecurityManager::GetScriptSecurityManager()
|
1999-10-28 22:09:03 +00:00
|
|
|
{
|
2014-05-07 06:17:43 +00:00
|
|
|
return gScriptSecMan;
|
|
|
|
}
|
2003-01-17 01:00:15 +00:00
|
|
|
|
2014-05-07 06:17:43 +00:00
|
|
|
/* static */ void
|
|
|
|
nsScriptSecurityManager::InitStatics()
|
|
|
|
{
|
|
|
|
nsRefPtr<nsScriptSecurityManager> ssManager = new nsScriptSecurityManager();
|
|
|
|
nsresult rv = ssManager->Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_CRASH();
|
2000-02-11 04:18:39 +00:00
|
|
|
}
|
2014-05-07 06:17:43 +00:00
|
|
|
|
|
|
|
ClearOnShutdown(&gScriptSecMan);
|
|
|
|
gScriptSecMan = ssManager;
|
1999-10-28 22:09:03 +00:00
|
|
|
}
|
|
|
|
|
2001-08-07 03:59:29 +00:00
|
|
|
// Currently this nsGenericFactory constructor is used only from FastLoad
|
|
|
|
// (XPCOM object deserialization) code, when "creating" the system principal
|
|
|
|
// singleton.
|
2001-08-07 04:45:27 +00:00
|
|
|
nsSystemPrincipal *
|
2001-08-07 03:59:29 +00:00
|
|
|
nsScriptSecurityManager::SystemPrincipalSingletonConstructor()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIPrincipal *sysprin = nullptr;
|
2003-01-17 01:00:15 +00:00
|
|
|
if (gScriptSecMan)
|
2006-04-05 16:48:51 +00:00
|
|
|
NS_ADDREF(sysprin = gScriptSecMan->mSystemPrincipal);
|
2007-07-08 07:08:04 +00:00
|
|
|
return static_cast<nsSystemPrincipal*>(sysprin);
|
2001-08-07 03:59:29 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 16:59:22 +00:00
|
|
|
struct IsWhitespace {
|
|
|
|
static bool Test(char aChar) { return NS_IsAsciiWhitespace(aChar); };
|
|
|
|
};
|
|
|
|
struct IsWhitespaceOrComma {
|
|
|
|
static bool Test(char aChar) { return aChar == ',' || NS_IsAsciiWhitespace(aChar); };
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Predicate>
|
|
|
|
uint32_t SkipPast(const nsCString& str, uint32_t base)
|
|
|
|
{
|
|
|
|
while (base < str.Length() && Predicate::Test(str[base])) {
|
|
|
|
++base;
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Predicate>
|
|
|
|
uint32_t SkipUntil(const nsCString& str, uint32_t base)
|
|
|
|
{
|
|
|
|
while (base < str.Length() && !Predicate::Test(str[base])) {
|
|
|
|
++base;
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
inline void
|
2007-09-06 07:02:57 +00:00
|
|
|
nsScriptSecurityManager::ScriptSecurityPrefChanged()
|
2000-01-06 00:59:18 +00:00
|
|
|
{
|
2014-05-09 16:59:22 +00:00
|
|
|
MOZ_ASSERT(mPrefInitialized);
|
2011-06-20 03:00:16 +00:00
|
|
|
mIsJavaScriptEnabled =
|
|
|
|
Preferences::GetBool(sJSEnabledPrefName, mIsJavaScriptEnabled);
|
|
|
|
sStrictFileOriginPolicy =
|
2011-09-29 06:19:26 +00:00
|
|
|
Preferences::GetBool(sFileOriginPolicyPrefName, false);
|
2014-05-09 16:59:22 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Rebuild the set of principals for which we allow file:// URI loads. This
|
|
|
|
// implements a small subset of an old pref-based CAPS people that people
|
|
|
|
// have come to depend on. See bug 995943.
|
|
|
|
//
|
|
|
|
|
|
|
|
mFileURIWhitelist.Clear();
|
|
|
|
auto policies = mozilla::Preferences::GetCString("capability.policy.policynames");
|
|
|
|
for (uint32_t base = SkipPast<IsWhitespaceOrComma>(policies, 0), bound = 0;
|
|
|
|
base < policies.Length();
|
|
|
|
base = SkipPast<IsWhitespaceOrComma>(policies, bound))
|
|
|
|
{
|
|
|
|
// Grab the current policy name.
|
|
|
|
bound = SkipUntil<IsWhitespaceOrComma>(policies, base);
|
|
|
|
auto policyName = Substring(policies, base, bound - base);
|
|
|
|
|
|
|
|
// Figure out if this policy allows loading file:// URIs. If not, we can skip it.
|
|
|
|
nsCString checkLoadURIPrefName = NS_LITERAL_CSTRING("capability.policy.") +
|
|
|
|
policyName +
|
|
|
|
NS_LITERAL_CSTRING(".checkloaduri.enabled");
|
|
|
|
if (!Preferences::GetString(checkLoadURIPrefName.get()).LowerCaseEqualsLiteral("allaccess")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grab the list of domains associated with this policy.
|
|
|
|
nsCString domainPrefName = NS_LITERAL_CSTRING("capability.policy.") +
|
|
|
|
policyName +
|
|
|
|
NS_LITERAL_CSTRING(".sites");
|
|
|
|
auto siteList = Preferences::GetCString(domainPrefName.get());
|
|
|
|
AddSitesToFileURIWhitelist(siteList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScriptSecurityManager::AddSitesToFileURIWhitelist(const nsCString& aSiteList)
|
|
|
|
{
|
|
|
|
for (uint32_t base = SkipPast<IsWhitespace>(aSiteList, 0), bound = 0;
|
|
|
|
base < aSiteList.Length();
|
|
|
|
base = SkipPast<IsWhitespace>(aSiteList, bound))
|
|
|
|
{
|
|
|
|
// Grab the current site.
|
|
|
|
bound = SkipUntil<IsWhitespace>(aSiteList, base);
|
|
|
|
auto site = Substring(aSiteList, base, bound - base);
|
|
|
|
|
|
|
|
// Convert it to a URI and add it to our list.
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), site, nullptr, nullptr, sIOService);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mFileURIWhitelist.AppendElement(uri);
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIConsoleService> console(do_GetService("@mozilla.org/consoleservice;1"));
|
|
|
|
if (console) {
|
|
|
|
nsAutoString msg = NS_LITERAL_STRING("Unable to to add site to file:// URI whitelist: ") +
|
|
|
|
NS_ConvertASCIItoUTF16(site);
|
|
|
|
console->LogStringMessage(msg.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-10 04:56:56 +00:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsresult
|
2000-07-26 04:53:01 +00:00
|
|
|
nsScriptSecurityManager::InitPrefs()
|
1999-09-15 04:05:43 +00:00
|
|
|
{
|
2011-06-20 03:00:16 +00:00
|
|
|
nsIPrefBranch* branch = Preferences::GetRootBranch();
|
|
|
|
NS_ENSURE_TRUE(branch, NS_ERROR_FAILURE);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mPrefInitialized = true;
|
2000-07-26 04:53:01 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
// Set the initial value of the "javascript.enabled" prefs
|
2007-09-06 07:02:57 +00:00
|
|
|
ScriptSecurityPrefChanged();
|
2011-06-20 03:00:16 +00:00
|
|
|
|
2002-02-13 04:20:46 +00:00
|
|
|
// set observer callbacks in case the value of the prefs change
|
2011-06-20 03:00:16 +00:00
|
|
|
Preferences::AddStrongObservers(this, kObservedPrefs);
|
|
|
|
|
1999-11-11 22:10:36 +00:00
|
|
|
return NS_OK;
|
1999-09-15 04:05:43 +00:00
|
|
|
}
|
2002-02-13 04:20:46 +00:00
|
|
|
|
2012-07-20 05:44:03 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
void
|
2013-09-11 04:18:36 +00:00
|
|
|
GetJarPrefix(uint32_t aAppId, bool aInMozBrowser, nsACString& aJarPrefix)
|
2012-07-19 04:25:19 +00:00
|
|
|
{
|
2012-07-20 05:44:03 +00:00
|
|
|
MOZ_ASSERT(aAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID);
|
2012-07-19 04:25:19 +00:00
|
|
|
|
2012-07-20 05:44:03 +00:00
|
|
|
if (aAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
|
|
|
|
aAppId = nsIScriptSecurityManager::NO_APP_ID;
|
2012-07-19 04:25:19 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 04:18:36 +00:00
|
|
|
aJarPrefix.Truncate();
|
2012-07-20 05:44:03 +00:00
|
|
|
|
2012-07-19 04:25:19 +00:00
|
|
|
// Fallback.
|
|
|
|
if (aAppId == nsIScriptSecurityManager::NO_APP_ID && !aInMozBrowser) {
|
2012-07-20 05:44:03 +00:00
|
|
|
return;
|
2012-07-19 04:25:19 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 04:18:36 +00:00
|
|
|
// aJarPrefix = appId + "+" + { 't', 'f' } + "+";
|
|
|
|
aJarPrefix.AppendInt(aAppId);
|
|
|
|
aJarPrefix.Append('+');
|
|
|
|
aJarPrefix.Append(aInMozBrowser ? 't' : 'f');
|
|
|
|
aJarPrefix.Append('+');
|
2012-07-19 04:25:19 +00:00
|
|
|
|
2012-07-20 05:44:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-09-11 04:18:36 +00:00
|
|
|
nsScriptSecurityManager::GetJarPrefix(uint32_t aAppId,
|
|
|
|
bool aInMozBrowser,
|
|
|
|
nsACString& aJarPrefix)
|
2012-07-20 05:44:03 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID);
|
|
|
|
|
2013-09-11 04:18:36 +00:00
|
|
|
mozilla::GetJarPrefix(aAppId, aInMozBrowser, aJarPrefix);
|
2012-07-19 04:25:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-11-13 00:43:35 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::GetDomainPolicyActive(bool *aRv)
|
|
|
|
{
|
|
|
|
*aRv = !!mDomainPolicy;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::ActivateDomainPolicy(nsIDomainPolicy** aRv)
|
|
|
|
{
|
|
|
|
// We only allow one domain policy at a time. The holder of the previous
|
|
|
|
// policy must explicitly deactivate it first.
|
|
|
|
if (mDomainPolicy) {
|
|
|
|
return NS_ERROR_SERVICE_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2013-12-14 03:15:44 +00:00
|
|
|
mDomainPolicy = new DomainPolicy();
|
2013-11-13 00:43:35 +00:00
|
|
|
nsCOMPtr<nsIDomainPolicy> ptr = mDomainPolicy;
|
|
|
|
ptr.forget(aRv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intentionally non-scriptable. Script must have a reference to the
|
|
|
|
// nsIDomainPolicy to deactivate it.
|
|
|
|
void
|
|
|
|
nsScriptSecurityManager::DeactivateDomainPolicy()
|
|
|
|
{
|
|
|
|
mDomainPolicy = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptSecurityManager::PolicyAllowsScript(nsIURI* aURI, bool *aRv)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Compute our rule. If we don't have any domain policy set up that might
|
|
|
|
// provide exceptions to this rule, we're done.
|
|
|
|
*aRv = mIsJavaScriptEnabled;
|
|
|
|
if (!mDomainPolicy) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have a domain policy. Grab the appropriate set of exceptions to the
|
|
|
|
// rule (either the blacklist or the whitelist, depending on whether script
|
|
|
|
// is enabled or disabled by default).
|
|
|
|
nsCOMPtr<nsIDomainSet> exceptions;
|
|
|
|
nsCOMPtr<nsIDomainSet> superExceptions;
|
|
|
|
if (*aRv) {
|
|
|
|
mDomainPolicy->GetBlacklist(getter_AddRefs(exceptions));
|
|
|
|
mDomainPolicy->GetSuperBlacklist(getter_AddRefs(superExceptions));
|
|
|
|
} else {
|
|
|
|
mDomainPolicy->GetWhitelist(getter_AddRefs(exceptions));
|
|
|
|
mDomainPolicy->GetSuperWhitelist(getter_AddRefs(superExceptions));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool contains;
|
|
|
|
rv = exceptions->Contains(aURI, &contains);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (contains) {
|
|
|
|
*aRv = !*aRv;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
rv = superExceptions->ContainsSuperDomain(aURI, &contains);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (contains) {
|
|
|
|
*aRv = !*aRv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|