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 "mozilla/Maybe.h"
|
1999-08-20 13:51:02 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2000-01-19 00:54:01 +03:00
|
|
|
#include "nsCOMPtr.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"
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.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
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
class nsIIOService;
|
2003-07-29 09:28:00 +04:00
|
|
|
class nsIStringBundle;
|
2017-03-22 13:39:08 +03:00
|
|
|
class SystemPrincipal;
|
2006-02-24 07:38:46 +03:00
|
|
|
|
2015-05-15 23:43:11 +03:00
|
|
|
namespace mozilla {
|
2017-01-12 19:38:48 +03:00
|
|
|
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 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
|
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();
|
|
|
|
|
2017-10-17 07:08:42 +03:00
|
|
|
static already_AddRefed<SystemPrincipal>
|
2001-08-07 07:59:29 +04:00
|
|
|
SystemPrincipalSingletonConstructor();
|
|
|
|
|
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
|
|
|
|
2016-10-24 14:52:00 +03:00
|
|
|
static nsresult
|
2017-07-12 08:13:37 +03:00
|
|
|
ReportError(JSContext* cx, const char* aMessageTag,
|
2008-02-27 06:45:29 +03:00
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
2016-04-28 13:13:09 +03:00
|
|
|
nsresult GetChannelResultPrincipal(nsIChannel* aChannel,
|
|
|
|
nsIPrincipal** aPrincipal,
|
|
|
|
bool aIgnoreSandboxing);
|
|
|
|
|
2016-07-13 14:05:22 +03:00
|
|
|
nsresult
|
|
|
|
CheckLoadURIFlags(nsIURI* aSourceURI, nsIURI* aTargetURI, nsIURI* aSourceBaseURI,
|
|
|
|
nsIURI* aTargetBaseURI, uint32_t aFlags);
|
|
|
|
|
2016-10-03 07:43:17 +03:00
|
|
|
// Returns the file URI whitelist, initializing it if it has not been
|
|
|
|
// initialized.
|
|
|
|
const nsTArray<nsCOMPtr<nsIURI>>& EnsureFileURIWhitelist();
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mPrefInitialized;
|
|
|
|
bool mIsJavaScriptEnabled;
|
2016-10-03 07:43:17 +03:00
|
|
|
|
|
|
|
// List of URIs whose domains and sub-domains are whitelisted to allow
|
|
|
|
// access to file: URIs. Lazily initialized; isNothing() when not yet
|
|
|
|
// initialized.
|
|
|
|
mozilla::Maybe<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;
|
|
|
|
|
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;
|
2016-08-11 15:39:22 +03:00
|
|
|
static JSContext *sContext;
|
2003-07-24 09:15:20 +04:00
|
|
|
};
|
2003-10-22 02:11:49 +04:00
|
|
|
|
|
|
|
#endif // nsScriptSecurityManager_h__
|