nsIScriptSecurityManager.idl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsISupports.idl"
  6. #include "nsIPrincipal.idl"
  7. interface nsIURI;
  8. interface nsIChannel;
  9. interface nsIClassInfo;
  10. interface nsIDocShell;
  11. interface nsIDomainPolicy;
  12. interface nsILoadContext;
  13. %{ C++
  14. #include "jspubtd.h"
  15. namespace mozilla {
  16. namespace dom {
  17. class DomainPolicyClone;
  18. }
  19. }
  20. %}
  21. [ptr] native JSContextPtr(JSContext);
  22. [ptr] native JSObjectPtr(JSObject);
  23. [ptr] native DomainPolicyClonePtr(mozilla::dom::DomainPolicyClone);
  24. [scriptable, uuid(51daad87-3a0c-44cc-b620-7356801c9022)]
  25. interface nsIScriptSecurityManager : nsISupports
  26. {
  27. /**
  28. * For each of these hooks returning NS_OK means 'let the action continue'.
  29. * Returning an error code means 'veto the action'. XPConnect will return
  30. * false to the js engine if the action is vetoed. The implementor of this
  31. * interface is responsible for setting a JS exception into the JSContext
  32. * if that is appropriate.
  33. */
  34. [noscript] void canCreateWrapper(in JSContextPtr aJSContext,
  35. in nsIIDRef aIID,
  36. in nsISupports aObj,
  37. in nsIClassInfo aClassInfo);
  38. [noscript] void canCreateInstance(in JSContextPtr aJSContext,
  39. in nsCIDRef aCID);
  40. [noscript] void canGetService(in JSContextPtr aJSContext,
  41. in nsCIDRef aCID);
  42. /**
  43. * Check that the script currently running in context "cx" can load "uri".
  44. *
  45. * Will return error code NS_ERROR_DOM_BAD_URI if the load request
  46. * should be denied.
  47. *
  48. * @param cx the JSContext of the script causing the load
  49. * @param uri the URI that is being loaded
  50. */
  51. [noscript] void checkLoadURIFromScript(in JSContextPtr cx, in nsIURI uri);
  52. /**
  53. * Default CheckLoadURI permissions
  54. */
  55. // Default permissions
  56. const unsigned long STANDARD = 0;
  57. // Indicate that the load is a load of a new document that is not
  58. // user-triggered. Here "user-triggered" could be broadly interpreted --
  59. // for example, scripted sets of window.location.href might be treated as
  60. // "user-triggered" in some circumstances. A typical example of a load
  61. // that is not user-triggered is a <meta> refresh load. If this flag is
  62. // set, the load will be denied if the originating principal's URI has the
  63. // nsIProtocolHandler::URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT flag set.
  64. const unsigned long LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT = 1 << 0;
  65. // Allow the loading of chrome URLs by non-chrome URLs. Use with great
  66. // care! This will actually allow the loading of any URI which has the
  67. // nsIProtocolHandler::URI_IS_UI_RESOURCE protocol handler flag set. Ths
  68. // probably means at least chrome: and resource:.
  69. const unsigned long ALLOW_CHROME = 1 << 1;
  70. // Don't allow URLs which would inherit the caller's principal (such as
  71. // javascript: or data:) to load. See
  72. // nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT.
  73. const unsigned long DISALLOW_INHERIT_PRINCIPAL = 1 << 2;
  74. // Alias for DISALLOW_INHERIT_PRINCIPAL for backwards compat with
  75. // JS-implemented extensions.
  76. const unsigned long DISALLOW_SCRIPT_OR_DATA = DISALLOW_INHERIT_PRINCIPAL;
  77. // Don't allow javascript: URLs to load
  78. // WARNING: Support for this value was added in Mozilla 1.7.8 and
  79. // Firefox 1.0.4. Use in prior versions WILL BE IGNORED.
  80. // When using this, make sure that you actually want DISALLOW_SCRIPT, not
  81. // DISALLOW_INHERIT_PRINCIPAL
  82. const unsigned long DISALLOW_SCRIPT = 1 << 3;
  83. // Do not report errors if we just want to check if a principal can load
  84. // a URI to not unnecessarily spam the error console.
  85. const unsigned long DONT_REPORT_ERRORS = 1 << 4;
  86. /**
  87. * Check that content with principal aPrincipal can load "uri".
  88. *
  89. * Will return error code NS_ERROR_DOM_BAD_URI if the load request
  90. * should be denied.
  91. *
  92. * @param aPrincipal the principal identifying the actor causing the load
  93. * @param uri the URI that is being loaded
  94. * @param flags the permission set, see above
  95. */
  96. void checkLoadURIWithPrincipal(in nsIPrincipal aPrincipal,
  97. in nsIURI uri,
  98. in unsigned long flags);
  99. /**
  100. * Similar to checkLoadURIWithPrincipal but there are two differences:
  101. *
  102. * 1) The URI is a string, not a URI object.
  103. * 2) This function assumes that the URI may still be subject to fixup (and
  104. * hence will check whether fixed-up versions of the URI are allowed to
  105. * load as well); if any of the versions of this URI is not allowed, this
  106. * function will return error code NS_ERROR_DOM_BAD_URI.
  107. */
  108. void checkLoadURIStrWithPrincipal(in nsIPrincipal aPrincipal,
  109. in AUTF8String uri,
  110. in unsigned long flags);
  111. ///////////////// Principals ///////////////////////
  112. /**
  113. * Return the all-powerful system principal.
  114. */
  115. nsIPrincipal getSystemPrincipal();
  116. /**
  117. * Returns a principal that has the given information.
  118. * @param appId is the app id of the principal. It can't be UNKNOWN_APP_ID.
  119. * @param inMozBrowser is true if the principal has to be considered as
  120. * inside a mozbrowser frame.
  121. *
  122. * @deprecated use createCodebasePrincipal instead.
  123. */
  124. [deprecated] nsIPrincipal getAppCodebasePrincipal(in nsIURI uri,
  125. in unsigned long appId,
  126. in boolean inMozBrowser);
  127. /**
  128. * Returns a principal that has the appId and inMozBrowser of the load
  129. * context.
  130. * @param loadContext to get appId/inMozBrowser from.
  131. */
  132. nsIPrincipal getLoadContextCodebasePrincipal(in nsIURI uri,
  133. in nsILoadContext loadContext);
  134. /**
  135. * Returns a principal that has the appId and inMozBrowser of the docshell
  136. * inside a mozbrowser frame.
  137. * @param docShell to get appId/inMozBrowser from.
  138. */
  139. nsIPrincipal getDocShellCodebasePrincipal(in nsIURI uri,
  140. in nsIDocShell docShell);
  141. /**
  142. * Returns a principal with that has the same origin as uri and is not part
  143. * of an appliction.
  144. * The returned principal will have appId = NO_APP_ID.
  145. *
  146. * @deprecated use createCodebasePrincipal instead.
  147. */
  148. [deprecated] nsIPrincipal getNoAppCodebasePrincipal(in nsIURI uri);
  149. /**
  150. * Legacy method for getting a principal with no origin attributes.
  151. *
  152. * @deprecated use createCodebasePrincipal instead.
  153. */
  154. [deprecated] nsIPrincipal getCodebasePrincipal(in nsIURI uri);
  155. /**
  156. * Returns a principal whose origin is composed of |uri| and |originAttributes|.
  157. * See nsIPrincipal.idl for a description of origin attributes, and
  158. * ChromeUtils.webidl for a list of origin attributes and their defaults.
  159. */
  160. [implicit_jscontext]
  161. nsIPrincipal createCodebasePrincipal(in nsIURI uri, in jsval originAttributes);
  162. /**
  163. * Returns a principal whose origin is the one we pass in.
  164. * See nsIPrincipal.idl for a description of origin attributes, and
  165. * ChromeUtils.webidl for a list of origin attributes and their defaults.
  166. */
  167. nsIPrincipal createCodebasePrincipalFromOrigin(in ACString origin);
  168. /**
  169. * Returns a unique nonce principal with |originAttributes|.
  170. * See nsIPrincipal.idl for a description of origin attributes, and
  171. * ChromeUtils.webidl for a list of origin attributes and their defaults.
  172. */
  173. [implicit_jscontext]
  174. nsIPrincipal createNullPrincipal(in jsval originAttributes);
  175. /**
  176. * Returns OK if aSourceURI and target have the same "origin"
  177. * (scheme, host, and port).
  178. * ReportError flag suppresses error reports for functions that
  179. * don't need reporting.
  180. */
  181. void checkSameOriginURI(in nsIURI aSourceURI,
  182. in nsIURI aTargetURI,
  183. in boolean reportError);
  184. /**
  185. * Get the principal for the given channel. This will typically be the
  186. * channel owner if there is one, and the codebase principal for the
  187. * channel's URI otherwise. aChannel must not be null.
  188. */
  189. nsIPrincipal getChannelResultPrincipal(in nsIChannel aChannel);
  190. /**
  191. * Temporary API until bug 1220687 is fixed.
  192. *
  193. * Returns the same value as getChannelResultPrincipal, but ignoring
  194. * sandboxing. Specifically, if sandboxing would have prevented the
  195. * channel's triggering principal from being returned by
  196. * getChannelResultPrincipal, the triggering principal will be returned
  197. * by this method.
  198. *
  199. * Note that this method only ignores sandboxing of the channel in
  200. * question, it does not ignore sandboxing of any channels further up a
  201. * document chain. The triggering principal itself may still be the null
  202. * principal due to sandboxing further up a document chain. In that regard
  203. * the ignoring of sandboxing is limited.
  204. */
  205. [noscript, nostdcall]
  206. nsIPrincipal getChannelResultPrincipalIfNotSandboxed(in nsIChannel aChannel);
  207. /**
  208. * Get the codebase principal for the channel's URI.
  209. * aChannel must not be null.
  210. */
  211. nsIPrincipal getChannelURIPrincipal(in nsIChannel aChannel);
  212. /**
  213. * Check whether a given principal is a system principal. This allows us
  214. * to avoid handing back the system principal to script while allowing
  215. * script to check whether a given principal is system.
  216. */
  217. boolean isSystemPrincipal(in nsIPrincipal aPrincipal);
  218. %{C++
  219. bool IsSystemPrincipal(nsIPrincipal* aPrincipal) {
  220. bool isSystem = false;
  221. IsSystemPrincipal(aPrincipal, &isSystem);
  222. return isSystem;
  223. }
  224. %}
  225. const unsigned long NO_APP_ID = 0;
  226. const unsigned long UNKNOWN_APP_ID = 4294967295; // UINT32_MAX
  227. const unsigned long SAFEBROWSING_APP_ID = 4294967294; // UINT32_MAX - 1
  228. const unsigned long DEFAULT_USER_CONTEXT_ID = 0;
  229. /**
  230. * Per-domain controls to enable and disable script. This system is designed
  231. * to be used by at most one consumer, and enforces this with its semantics.
  232. *
  233. * Initially, domainPolicyActive is false. When activateDomainPolicy() is
  234. * invoked, domainPolicyActive becomes true, and subsequent calls to
  235. * activateDomainPolicy() will fail until deactivate() is invoked on the
  236. * nsIDomainPolicy returned from activateDomainPolicy(). At this point,
  237. * domainPolicyActive becomes false again, and a new consumer may acquire
  238. * control of the system by invoking activateDomainPolicy().
  239. */
  240. nsIDomainPolicy activateDomainPolicy();
  241. readonly attribute boolean domainPolicyActive;
  242. /**
  243. * Only the parent process can directly access domain policies, child
  244. * processes only have a read-only mirror to the one in the parent.
  245. * For child processes the mirror is updated via messages
  246. * and ContentChild will hold the DomainPolicy by calling
  247. * ActivateDomainPolicyInternal directly. New consumer to this
  248. * function should not be addded.
  249. */
  250. [noscript] nsIDomainPolicy activateDomainPolicyInternal();
  251. /**
  252. * This function is for internal use only. Every time a child process is spawned, we
  253. * must clone any active domain policies in the parent to the new child.
  254. */
  255. [noscript, notxpcom] void cloneDomainPolicy(in DomainPolicyClonePtr aClone);
  256. /**
  257. * Query mechanism for the above policy.
  258. *
  259. * If domainPolicyEnabled is false, this simply returns the current value
  260. * of javascript.enabled. Otherwise, it returns the same value, but taking
  261. * the various blacklist/whitelist exceptions into account.
  262. */
  263. bool policyAllowsScript(in nsIURI aDomain);
  264. };
  265. %{C++
  266. #define NS_SCRIPTSECURITYMANAGER_CONTRACTID "@mozilla.org/scriptsecuritymanager;1"
  267. %}