2013-01-03 09:47:50 +04: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 15:12:37 +04: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/. */
|
2000-02-10 07:56:56 +03:00
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
#ifndef nsScriptSecurityManager_h__
|
|
|
|
#define nsScriptSecurityManager_h__
|
1999-08-20 13:51:02 +04:00
|
|
|
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
2015-07-20 04:42:16 +03:00
|
|
|
|
|
|
|
#include "nsIAddonPolicyService.h"
|
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
#include "nsIAddonPolicyService.h"
|
1999-08-20 13:51:02 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2000-01-19 00:54:01 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2005-11-08 23:47:16 +03:00
|
|
|
#include "nsIChannelEventSink.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 20:46:42 +04:00
|
|
|
#include "nsIObserver.h"
|
2015-07-20 04:42:16 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "plstr.h"
|
2013-08-28 06:59:14 +04:00
|
|
|
#include "js/TypeDecls.h"
|
2000-08-22 10:02:14 +04:00
|
|
|
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
2012-04-12 04:17:44 +04:00
|
|
|
|
2014-05-09 20:59:22 +04:00
|
|
|
class nsCString;
|
2003-10-22 02:11:49 +04:00
|
|
|
class nsIIOService;
|
2003-07-29 09:28:00 +04:00
|
|
|
class nsIStringBundle;
|
2001-08-07 07:59:29 +04:00
|
|
|
class nsSystemPrincipal;
|
2006-02-24 07:38:46 +03:00
|
|
|
|
2015-05-15 23:43:11 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class OriginAttributes;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2015-05-15 23:43:11 +03:00
|
|
|
|
2002-02-13 07:20:46 +03:00
|
|
|
/////////////////////////////
|
|
|
|
// nsScriptSecurityManager //
|
|
|
|
/////////////////////////////
|
1999-08-20 13:51:02 +04:00
|
|
|
#define NS_SCRIPTSECURITYMANAGER_CID \
|
|
|
|
{ 0x7ee2a4c0, 0x4b93, 0x17d3, \
|
|
|
|
{ 0xba, 0x18, 0x00, 0x60, 0xb0, 0xf1, 0x99, 0xa2 }}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsScriptSecurityManager final : public nsIScriptSecurityManager,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIObserver
|
1999-09-07 06:54:19 +04:00
|
|
|
{
|
1999-08-20 13:51:02 +04:00
|
|
|
public:
|
2002-02-13 07:20:46 +03:00
|
|
|
static void Shutdown();
|
2014-05-07 10:17:43 +04:00
|
|
|
|
1999-08-30 01:58:42 +04:00
|
|
|
NS_DEFINE_STATIC_CID_ACCESSOR(NS_SCRIPTSECURITYMANAGER_CID)
|
2014-05-07 10:17:43 +04:00
|
|
|
|
1999-08-30 01:58:42 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISCRIPTSECURITYMANAGER
|
2005-11-08 23:47:16 +03:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
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 20:46:42 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
2001-04-17 05:21:44 +04: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 20:46:42 +04:00
|
|
|
static nsScriptSecurityManager*
|
1999-08-30 01:58:42 +04:00
|
|
|
GetScriptSecurityManager();
|
2000-08-22 10:02:14 +04:00
|
|
|
|
2014-05-07 10:17:43 +04:00
|
|
|
// Invoked exactly once, by XPConnect.
|
|
|
|
static void InitStatics();
|
|
|
|
|
2001-08-07 07:59:29 +04:00
|
|
|
static nsSystemPrincipal*
|
|
|
|
SystemPrincipalSingletonConstructor();
|
|
|
|
|
2002-02-13 07:20:46 +03:00
|
|
|
JSContext* GetCurrentJSContext();
|
|
|
|
|
|
|
|
JSContext* GetSafeJSContext();
|
2001-04-17 05:21:44 +04:00
|
|
|
|
2008-02-27 06:45:29 +03:00
|
|
|
/**
|
|
|
|
* Utility method for comparing two URIs. For security purposes, two URIs
|
|
|
|
* are equivalent if their schemes, hosts, and ports (if any) match. This
|
|
|
|
* method returns true if aSubjectURI and aObjectURI have the same origin,
|
|
|
|
* false otherwise.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool SecurityCompareURIs(nsIURI* aSourceURI, nsIURI* aTargetURI);
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t SecurityHashURI(nsIURI* aURI);
|
2008-02-27 06:45:29 +03:00
|
|
|
|
2014-07-29 19:47:52 +04:00
|
|
|
static uint16_t AppStatusForPrincipal(nsIPrincipal *aPrin);
|
|
|
|
|
2008-02-27 06:45:29 +03:00
|
|
|
static nsresult
|
|
|
|
ReportError(JSContext* cx, const nsAString& messageTag,
|
|
|
|
nsIURI* aSource, nsIURI* aTarget);
|
2008-10-08 17:16:27 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t
|
2008-10-08 17:16:27 +04:00
|
|
|
HashPrincipalByOrigin(nsIPrincipal* aPrincipal);
|
2008-03-22 19:50:47 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2008-03-22 19:50:47 +03:00
|
|
|
GetStrictFileOriginPolicy()
|
|
|
|
{
|
|
|
|
return sStrictFileOriginPolicy;
|
|
|
|
}
|
|
|
|
|
2013-11-13 04:43:35 +04:00
|
|
|
void DeactivateDomainPolicy();
|
|
|
|
|
1999-08-20 13:51:02 +04:00
|
|
|
private:
|
2000-01-19 00:54:01 +03:00
|
|
|
|
2003-01-17 05:00:01 +03:00
|
|
|
// GetScriptSecurityManager is the only call that can make one
|
|
|
|
nsScriptSecurityManager();
|
|
|
|
virtual ~nsScriptSecurityManager();
|
|
|
|
|
2010-03-08 11:24:50 +03:00
|
|
|
// Decides, based on CSP, whether or not eval() and stuff can be executed.
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2010-03-08 11:24:50 +03:00
|
|
|
ContentSecurityPolicyPermitsJSAction(JSContext *cx);
|
|
|
|
|
2014-01-03 20:32:56 +04:00
|
|
|
static bool
|
|
|
|
JSPrincipalsSubsume(JSPrincipals *first, JSPrincipals *second);
|
|
|
|
|
2005-04-11 03:27:07 +04:00
|
|
|
// Returns null if a principal cannot be found; generally callers
|
|
|
|
// should error out at that point.
|
2013-11-13 04:43:35 +04:00
|
|
|
static nsIPrincipal* doGetObjectPrincipal(JSObject* obj);
|
2005-04-11 03:27:07 +04:00
|
|
|
|
2003-01-17 05:00:01 +03:00
|
|
|
nsresult
|
|
|
|
Init();
|
2009-05-14 02:01:01 +04: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 20:46:42 +04:00
|
|
|
nsresult
|
|
|
|
InitPrefs();
|
2000-11-30 08:32:08 +03: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 20:46:42 +04:00
|
|
|
inline void
|
2007-09-06 11:02:57 +04:00
|
|
|
ScriptSecurityPrefChanged();
|
2000-01-06 03:59:18 +03:00
|
|
|
|
2014-05-09 20:59:22 +04:00
|
|
|
inline void
|
|
|
|
AddSitesToFileURIWhitelist(const nsCString& aSiteList);
|
|
|
|
|
2015-07-21 00:46:58 +03:00
|
|
|
// If aURI is a moz-extension:// URI, set mAddonId to the associated addon.
|
|
|
|
nsresult MaybeSetAddonIdFromURI(mozilla::OriginAttributes& aAttrs, nsIURI* aURI);
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mPrefInitialized;
|
|
|
|
bool mIsJavaScriptEnabled;
|
2014-05-09 20:59:22 +04:00
|
|
|
nsTArray<nsCOMPtr<nsIURI>> mFileURIWhitelist;
|
2008-02-27 06:45:29 +03:00
|
|
|
|
2013-11-13 04:43:35 +04:00
|
|
|
// This machinery controls new-style domain policies. The old-style
|
|
|
|
// policy machinery will be removed soon.
|
|
|
|
nsCOMPtr<nsIDomainPolicy> mDomainPolicy;
|
|
|
|
|
2015-07-20 04:42:16 +03:00
|
|
|
// Cached addon policy service. We can't generate this in Init() because
|
|
|
|
// that's too early to get a service.
|
|
|
|
mozilla::Maybe<nsCOMPtr<nsIAddonPolicyService>> mAddonPolicyService;
|
|
|
|
nsIAddonPolicyService* GetAddonPolicyService()
|
|
|
|
{
|
|
|
|
if (mAddonPolicyService.isNothing()) {
|
|
|
|
mAddonPolicyService.emplace(do_GetService("@mozilla.org/addons/policy-service;1"));
|
|
|
|
}
|
|
|
|
return mAddonPolicyService.ref();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sStrictFileOriginPolicy;
|
1999-10-29 02:09:03 +04:00
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
static nsIIOService *sIOService;
|
2003-07-29 09:28:00 +04:00
|
|
|
static nsIStringBundle *sStrBundle;
|
2005-06-08 01:57:56 +04:00
|
|
|
static JSRuntime *sRuntime;
|
2003-07-24 09:15:20 +04:00
|
|
|
};
|
2003-10-22 02:11:49 +04:00
|
|
|
|
2012-07-20 09:44:03 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
void
|
2013-09-11 08:18:36 +04:00
|
|
|
GetJarPrefix(uint32_t aAppid,
|
|
|
|
bool aInMozBrowser,
|
|
|
|
nsACString& aJarPrefix);
|
2012-07-20 09:44:03 +04:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
#endif // nsScriptSecurityManager_h__
|