2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 15:39:55 +00:00
|
|
|
/* vim: set ts=4 et sw=2 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"
|
2015-07-20 01:42:16 +00:00
|
|
|
|
|
|
|
#include "mozilla/Maybe.h"
|
1999-08-20 09:51:02 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2000-01-18 21:54:01 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2015-07-20 01:42:16 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2017-08-16 23:48:52 +00:00
|
|
|
#include "nsStringFwd.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
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
class nsIIOService;
|
2003-07-29 05:28:00 +00:00
|
|
|
class nsIStringBundle;
|
2006-02-24 04:38:46 +00:00
|
|
|
|
2015-05-15 20:43:11 +00:00
|
|
|
namespace mozilla {
|
2017-01-12 16:38:48 +00:00
|
|
|
class OriginAttributes;
|
2018-07-17 19:38:19 +00:00
|
|
|
class SystemPrincipal;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace mozilla
|
2015-05-15 20:43:11 +00:00
|
|
|
|
2022-05-19 14:13:50 +00:00
|
|
|
namespace JS {
|
2022-06-07 12:32:55 +00:00
|
|
|
enum class RuntimeCode;
|
|
|
|
} // namespace JS
|
2022-05-19 14:13:50 +00:00
|
|
|
|
2002-02-13 04:20:46 +00:00
|
|
|
/////////////////////////////
|
|
|
|
// nsScriptSecurityManager //
|
|
|
|
/////////////////////////////
|
1999-08-20 09:51:02 +00:00
|
|
|
#define NS_SCRIPTSECURITYMANAGER_CID \
|
2018-11-30 10:46:48 +00:00
|
|
|
{ \
|
1999-08-20 09:51:02 +00:00
|
|
|
0x7ee2a4c0, 0x4b93, 0x17d3, { \
|
|
|
|
0xba, 0x18, 0x00, 0x60, 0xb0, 0xf1, 0x99, 0xa2 \
|
|
|
|
} \
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
1999-08-20 09:51:02 +00:00
|
|
|
|
2018-07-05 21:53:14 +00:00
|
|
|
class nsScriptSecurityManager final : public nsIScriptSecurityManager {
|
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
|
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* 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();
|
|
|
|
|
2019-11-22 12:40:17 +00:00
|
|
|
void InitJSCallbacks(JSContext* aCx);
|
2019-11-27 20:57:43 +00:00
|
|
|
|
|
|
|
// This has to be static because it is called after gScriptSecMan is cleared.
|
|
|
|
static void ClearJSCallbacks(JSContext* aCx);
|
2019-11-22 12:40:17 +00:00
|
|
|
|
2018-07-17 19:38:19 +00:00
|
|
|
static already_AddRefed<mozilla::SystemPrincipal>
|
2001-08-07 03:59:29 +00:00
|
|
|
SystemPrincipalSingletonConstructor();
|
|
|
|
|
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);
|
2024-03-22 12:27:38 +00:00
|
|
|
static bool IsHttpOrHttpsAndCrossOrigin(nsIURI* aUriA, nsIURI* aUriB);
|
2008-02-27 03:45:29 +00:00
|
|
|
|
2018-09-25 05:25:05 +00:00
|
|
|
static nsresult ReportError(const char* aMessageTag, nsIURI* aSource,
|
2019-12-12 16:41:26 +00:00
|
|
|
nsIURI* aTarget, bool aFromPrivateWindow,
|
|
|
|
uint64_t aInnerWindowID = 0);
|
2020-01-06 15:30:35 +00:00
|
|
|
static nsresult ReportError(const char* aMessageTag,
|
|
|
|
const nsACString& sourceSpec,
|
|
|
|
const nsACString& targetSpec,
|
|
|
|
bool aFromPrivateWindow,
|
|
|
|
uint64_t aInnerWindowID = 0);
|
|
|
|
|
|
|
|
static uint32_t HashPrincipalByOrigin(nsIPrincipal* aPrincipal);
|
2008-10-08 13:16:27 +00:00
|
|
|
|
2008-03-22 16:50:47 +00:00
|
|
|
static bool GetStrictFileOriginPolicy() { return sStrictFileOriginPolicy; }
|
|
|
|
|
2013-11-13 00:43:35 +00:00
|
|
|
void DeactivateDomainPolicy();
|
|
|
|
|
1999-08-20 09:51:02 +00:00
|
|
|
private:
|
2003-01-17 02:00:01 +00:00
|
|
|
// GetScriptSecurityManager is the only call that can make one
|
|
|
|
nsScriptSecurityManager();
|
|
|
|
virtual ~nsScriptSecurityManager();
|
2000-01-18 21:54:01 +00:00
|
|
|
|
2003-01-17 02:00:01 +00:00
|
|
|
// Decides, based on CSP, whether or not eval() and stuff can be executed.
|
|
|
|
static bool ContentSecurityPolicyPermitsJSAction(JSContext* cx,
|
2022-05-19 14:13:50 +00:00
|
|
|
JS::RuntimeCode kind,
|
|
|
|
JS::Handle<JSString*> aCode);
|
2003-01-17 02:00:01 +00:00
|
|
|
|
2018-07-16 15:58:04 +00:00
|
|
|
static bool JSPrincipalsSubsume(JSPrincipals* first, JSPrincipals* second);
|
2010-03-08 08:24:50 +00:00
|
|
|
|
2014-01-03 16:32:56 +00:00
|
|
|
nsresult Init();
|
|
|
|
|
2003-01-17 02:00:01 +00:00
|
|
|
nsresult InitPrefs();
|
2009-05-13 22:01:01 +00:00
|
|
|
|
2019-11-01 02:57:20 +00:00
|
|
|
static void ScriptSecurityPrefChanged(const char* aPref, void* aSelf);
|
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
|
|
|
void ScriptSecurityPrefChanged(const char* aPref = nullptr);
|
2000-11-30 05:32:08 +00:00
|
|
|
|
2018-07-05 21:53:14 +00:00
|
|
|
inline void AddSitesToFileURIAllowlist(const nsCString& aSiteList);
|
2000-01-06 00:59:18 +00:00
|
|
|
|
2018-10-31 17:56:43 +00:00
|
|
|
nsresult GetChannelResultPrincipal(nsIChannel* aChannel,
|
|
|
|
nsIPrincipal** aPrincipal,
|
|
|
|
bool aIgnoreSandboxing);
|
2014-05-09 16:59:22 +00:00
|
|
|
|
2016-04-28 10:13:09 +00:00
|
|
|
nsresult CheckLoadURIFlags(nsIURI* aSourceURI, nsIURI* aTargetURI,
|
|
|
|
nsIURI* aSourceBaseURI, nsIURI* aTargetBaseURI,
|
2019-12-12 16:41:19 +00:00
|
|
|
uint32_t aFlags, bool aFromPrivateWindow,
|
|
|
|
uint64_t aInnerWindowID);
|
2016-04-28 10:13:09 +00:00
|
|
|
|
2016-07-13 11:05:22 +00:00
|
|
|
// Returns the file URI allowlist, initializing it if it has not been
|
2018-09-25 05:25:05 +00:00
|
|
|
// initialized.
|
|
|
|
const nsTArray<nsCOMPtr<nsIURI>>& EnsureFileURIAllowlist();
|
2016-07-13 11:05:22 +00:00
|
|
|
|
2018-10-31 17:56:43 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
|
|
|
|
bool mPrefInitialized;
|
|
|
|
bool mIsJavaScriptEnabled;
|
2016-10-03 04:43:17 +00:00
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
// List of URIs whose domains and sub-domains are allowlisted to allow
|
|
|
|
// access to file: URIs. Lazily initialized; isNothing() when not yet
|
2016-10-03 04:43:17 +00:00
|
|
|
// initialized.
|
2003-10-21 22:11:49 +00:00
|
|
|
mozilla::Maybe<nsTArray<nsCOMPtr<nsIURI>>> mFileURIAllowlist;
|
2016-10-03 04:43:17 +00:00
|
|
|
|
2018-10-31 17:56:43 +00:00
|
|
|
// This machinery controls new-style domain policies. The old-style
|
2016-10-03 04:43:17 +00:00
|
|
|
// policy machinery will be removed soon.
|
2018-10-31 17:56:43 +00:00
|
|
|
nsCOMPtr<nsIDomainPolicy> mDomainPolicy;
|
2008-02-27 03:45:29 +00:00
|
|
|
|
2022-12-02 00:53:50 +00:00
|
|
|
static std::atomic<bool> sStrictFileOriginPolicy;
|
2013-11-13 00:43:35 +00:00
|
|
|
|
2023-09-22 12:49:44 +00:00
|
|
|
static mozilla::StaticRefPtr<nsIIOService> sIOService;
|
2003-07-29 05:28:00 +00:00
|
|
|
static nsIStringBundle* sStrBundle;
|
2003-07-24 05:15:20 +00:00
|
|
|
};
|
2003-10-21 22:11:49 +00:00
|
|
|
|
|
|
|
#endif // nsScriptSecurityManager_h__
|