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/. */
|
2000-02-10 04:56:56 +00:00
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
#ifndef nsScriptSecurityManager_h__
|
|
|
|
#define nsScriptSecurityManager_h__
|
1999-08-20 09:51:02 +00:00
|
|
|
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2000-01-18 21:54:01 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2005-11-08 20:47:16 +00: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 16:46:42 +00:00
|
|
|
#include "nsIObserver.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "plstr.h"
|
2013-08-28 02:59:14 +00:00
|
|
|
#include "js/TypeDecls.h"
|
2000-08-22 06:02:14 +00:00
|
|
|
|
2013-07-30 14:25:31 +00:00
|
|
|
#include <stdint.h>
|
2012-04-12 00:17:44 +00:00
|
|
|
|
2014-05-09 16:59:22 +00:00
|
|
|
class nsCString;
|
2003-10-21 22:11:49 +00:00
|
|
|
class nsIIOService;
|
2003-07-29 05:28:00 +00:00
|
|
|
class nsIStringBundle;
|
2001-08-07 03:59:29 +00:00
|
|
|
class nsSystemPrincipal;
|
2006-02-24 04:38:46 +00:00
|
|
|
|
2002-02-13 04:20:46 +00:00
|
|
|
/////////////////////////////
|
|
|
|
// nsScriptSecurityManager //
|
|
|
|
/////////////////////////////
|
1999-08-20 09:51:02 +00:00
|
|
|
#define NS_SCRIPTSECURITYMANAGER_CID \
|
|
|
|
{ 0x7ee2a4c0, 0x4b93, 0x17d3, \
|
|
|
|
{ 0xba, 0x18, 0x00, 0x60, 0xb0, 0xf1, 0x99, 0xa2 }}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsScriptSecurityManager final : public nsIScriptSecurityManager,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIObserver
|
1999-09-07 02:54:19 +00:00
|
|
|
{
|
1999-08-20 09:51:02 +00:00
|
|
|
public:
|
2002-02-13 04:20:46 +00:00
|
|
|
static void Shutdown();
|
2014-05-07 06:17:43 +00:00
|
|
|
|
1999-08-29 21:58:42 +00:00
|
|
|
NS_DEFINE_STATIC_CID_ACCESSOR(NS_SCRIPTSECURITYMANAGER_CID)
|
2014-05-07 06:17:43 +00:00
|
|
|
|
1999-08-29 21:58:42 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISCRIPTSECURITYMANAGER
|
2005-11-08 20:47:16 +00: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 16:46:42 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
2001-04-17 01:21:44 +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
|
|
|
static nsScriptSecurityManager*
|
1999-08-29 21:58:42 +00:00
|
|
|
GetScriptSecurityManager();
|
2000-08-22 06:02:14 +00:00
|
|
|
|
2014-05-07 06:17:43 +00:00
|
|
|
// Invoked exactly once, by XPConnect.
|
|
|
|
static void InitStatics();
|
|
|
|
|
2001-08-07 03:59:29 +00:00
|
|
|
static nsSystemPrincipal*
|
|
|
|
SystemPrincipalSingletonConstructor();
|
|
|
|
|
2002-02-13 04:20:46 +00:00
|
|
|
JSContext* GetCurrentJSContext();
|
|
|
|
|
|
|
|
JSContext* GetSafeJSContext();
|
2001-04-17 01:21:44 +00:00
|
|
|
|
2008-02-27 03:45:29 +00: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 06:19:26 +00:00
|
|
|
static bool SecurityCompareURIs(nsIURI* aSourceURI, nsIURI* aTargetURI);
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t SecurityHashURI(nsIURI* aURI);
|
2008-02-27 03:45:29 +00:00
|
|
|
|
2014-07-29 15:47:52 +00:00
|
|
|
static uint16_t AppStatusForPrincipal(nsIPrincipal *aPrin);
|
|
|
|
|
2008-02-27 03:45:29 +00:00
|
|
|
static nsresult
|
|
|
|
ReportError(JSContext* cx, const nsAString& messageTag,
|
|
|
|
nsIURI* aSource, nsIURI* aTarget);
|
2008-10-08 13:16:27 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t
|
2008-10-08 13:16:27 +00:00
|
|
|
HashPrincipalByOrigin(nsIPrincipal* aPrincipal);
|
2008-03-22 16:50:47 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2008-03-22 16:50:47 +00:00
|
|
|
GetStrictFileOriginPolicy()
|
|
|
|
{
|
|
|
|
return sStrictFileOriginPolicy;
|
|
|
|
}
|
|
|
|
|
2013-11-13 00:43:35 +00:00
|
|
|
void DeactivateDomainPolicy();
|
|
|
|
|
1999-08-20 09:51:02 +00:00
|
|
|
private:
|
2000-01-18 21:54:01 +00:00
|
|
|
|
2003-01-17 02:00:01 +00:00
|
|
|
// GetScriptSecurityManager is the only call that can make one
|
|
|
|
nsScriptSecurityManager();
|
|
|
|
virtual ~nsScriptSecurityManager();
|
|
|
|
|
2010-03-08 08:24:50 +00:00
|
|
|
// Decides, based on CSP, whether or not eval() and stuff can be executed.
|
2013-08-08 22:53:04 +00:00
|
|
|
static bool
|
2010-03-08 08:24:50 +00:00
|
|
|
ContentSecurityPolicyPermitsJSAction(JSContext *cx);
|
|
|
|
|
2014-01-03 16:32:56 +00:00
|
|
|
static bool
|
|
|
|
JSPrincipalsSubsume(JSPrincipals *first, JSPrincipals *second);
|
|
|
|
|
2005-04-10 23:27:07 +00:00
|
|
|
// Returns null if a principal cannot be found; generally callers
|
|
|
|
// should error out at that point.
|
2013-11-13 00:43:35 +00:00
|
|
|
static nsIPrincipal* doGetObjectPrincipal(JSObject* obj);
|
2005-04-10 23:27:07 +00:00
|
|
|
|
2012-07-20 03:28:08 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
GetCodebasePrincipalInternal(nsIURI* aURI, uint32_t aAppId,
|
2012-07-21 07:29:40 +00:00
|
|
|
bool aInMozBrowser,
|
|
|
|
nsIPrincipal** result);
|
2012-07-20 03:28:08 +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
|
2012-08-22 15:56:38 +00:00
|
|
|
CreateCodebasePrincipal(nsIURI* aURI, uint32_t aAppId, bool aInMozBrowser,
|
2012-07-19 22:32:08 +00:00
|
|
|
nsIPrincipal** result);
|
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
|
|
|
|
2003-01-17 02:00:01 +00:00
|
|
|
nsresult
|
|
|
|
Init();
|
2009-05-13 22:01: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
|
|
|
nsresult
|
|
|
|
InitPrefs();
|
2000-11-30 05:32:08 +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
|
|
|
inline void
|
2007-09-06 07:02:57 +00:00
|
|
|
ScriptSecurityPrefChanged();
|
2000-01-06 00:59:18 +00:00
|
|
|
|
2014-05-09 16:59:22 +00:00
|
|
|
inline void
|
|
|
|
AddSitesToFileURIWhitelist(const nsCString& aSiteList);
|
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mPrefInitialized;
|
|
|
|
bool mIsJavaScriptEnabled;
|
2014-05-09 16:59:22 +00:00
|
|
|
nsTArray<nsCOMPtr<nsIURI>> mFileURIWhitelist;
|
2008-02-27 03:45:29 +00:00
|
|
|
|
2013-11-13 00:43:35 +00:00
|
|
|
// This machinery controls new-style domain policies. The old-style
|
|
|
|
// policy machinery will be removed soon.
|
|
|
|
nsCOMPtr<nsIDomainPolicy> mDomainPolicy;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sStrictFileOriginPolicy;
|
1999-10-28 22:09:03 +00:00
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
static nsIIOService *sIOService;
|
2003-07-29 05:28:00 +00:00
|
|
|
static nsIStringBundle *sStrBundle;
|
2005-06-07 21:57:56 +00:00
|
|
|
static JSRuntime *sRuntime;
|
2003-07-24 05:15:20 +00:00
|
|
|
};
|
2003-10-21 22:11:49 +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-20 05:44:03 +00:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
#endif // nsScriptSecurityManager_h__
|