Source code

Revision control

Other Tools

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
6
#include "nsISupports.idl"
7
#include "nsIPrincipal.idl"
8
interface nsIURI;
9
interface nsIChannel;
10
interface nsIClassInfo;
11
interface nsIDocShell;
12
interface nsIDomainPolicy;
13
interface nsILoadContext;
14
15
%{ C++
16
#include "jspubtd.h"
17
18
namespace mozilla {
19
namespace dom {
20
class DomainPolicyClone;
21
}
22
}
23
%}
24
25
[ptr] native JSContextPtr(JSContext);
26
[ptr] native JSObjectPtr(JSObject);
27
[ptr] native DomainPolicyClonePtr(mozilla::dom::DomainPolicyClone);
28
29
[scriptable, builtinclass, uuid(51daad87-3a0c-44cc-b620-7356801c9022)]
30
interface nsIScriptSecurityManager : nsISupports
31
{
32
/**
33
* For each of these hooks returning NS_OK means 'let the action continue'.
34
* Returning an error code means 'veto the action'. XPConnect will return
35
* false to the js engine if the action is vetoed. The implementor of this
36
* interface is responsible for setting a JS exception into the JSContext
37
* if that is appropriate.
38
*/
39
[noscript] void canCreateWrapper(in JSContextPtr aJSContext,
40
in nsIIDRef aIID,
41
in nsISupports aObj,
42
in nsIClassInfo aClassInfo);
43
44
[noscript] void canCreateInstance(in JSContextPtr aJSContext,
45
in nsCIDRef aCID);
46
47
[noscript] void canGetService(in JSContextPtr aJSContext,
48
in nsCIDRef aCID);
49
50
/**
51
* Check that the script currently running in context "cx" can load "uri".
52
*
53
* Will return error code NS_ERROR_DOM_BAD_URI if the load request
54
* should be denied.
55
*
56
* @param cx the JSContext of the script causing the load
57
* @param uri the URI that is being loaded
58
*/
59
[noscript] void checkLoadURIFromScript(in JSContextPtr cx, in nsIURI uri);
60
61
/**
62
* Default CheckLoadURI permissions
63
*/
64
// Default permissions
65
const unsigned long STANDARD = 0;
66
67
// Indicate that the load is a load of a new document that is not
68
// user-triggered. Here "user-triggered" could be broadly interpreted --
69
// for example, scripted sets of window.location.href might be treated as
70
// "user-triggered" in some circumstances. A typical example of a load
71
// that is not user-triggered is a <meta> refresh load. If this flag is
72
// set, the load will be denied if the originating principal's URI has the
73
// nsIProtocolHandler::URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT flag set.
74
const unsigned long LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT = 1 << 0;
75
76
// Allow the loading of chrome URLs by non-chrome URLs. Use with great
77
// care! This will actually allow the loading of any URI which has the
78
// nsIProtocolHandler::URI_IS_UI_RESOURCE protocol handler flag set. Ths
79
// probably means at least chrome: and resource:.
80
const unsigned long ALLOW_CHROME = 1 << 1;
81
82
// Don't allow URLs which would inherit the caller's principal (such as
83
// javascript: or data:) to load. See
84
// nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT.
85
const unsigned long DISALLOW_INHERIT_PRINCIPAL = 1 << 2;
86
87
// Alias for DISALLOW_INHERIT_PRINCIPAL for backwards compat with
88
// JS-implemented extensions.
89
const unsigned long DISALLOW_SCRIPT_OR_DATA = DISALLOW_INHERIT_PRINCIPAL;
90
91
// Don't allow javascript: URLs to load
92
// WARNING: Support for this value was added in Mozilla 1.7.8 and
93
// Firefox 1.0.4. Use in prior versions WILL BE IGNORED.
94
// When using this, make sure that you actually want DISALLOW_SCRIPT, not
95
// DISALLOW_INHERIT_PRINCIPAL
96
const unsigned long DISALLOW_SCRIPT = 1 << 3;
97
98
// Do not report errors if we just want to check if a principal can load
99
// a URI to not unnecessarily spam the error console.
100
const unsigned long DONT_REPORT_ERRORS = 1 << 4;
101
102
/**
103
* Check that content with principal aPrincipal can load "uri".
104
*
105
* Will return error code NS_ERROR_DOM_BAD_URI if the load request
106
* should be denied.
107
*
108
* @param aPrincipal the principal identifying the actor causing the load
109
* @param uri the URI that is being loaded
110
* @param flags the permission set, see above
111
* @param innerWindowID the window ID for error reporting. If this is 0
112
* (which happens automatically if it's not passed from JS), errors
113
* will only appear in the browser console, not window-associated
114
* consoles like the web console.
115
*/
116
void checkLoadURIWithPrincipal(in nsIPrincipal aPrincipal,
117
in nsIURI uri,
118
in unsigned long flags,
119
[optional] in unsigned long long innerWindowID);
120
121
/**
122
* Similar to checkLoadURIWithPrincipal but there are two differences:
123
*
124
* 1) The URI is a string, not a URI object.
125
* 2) This function assumes that the URI may still be subject to fixup (and
126
* hence will check whether fixed-up versions of the URI are allowed to
127
* load as well); if any of the versions of this URI is not allowed, this
128
* function will return error code NS_ERROR_DOM_BAD_URI.
129
*/
130
void checkLoadURIStrWithPrincipal(in nsIPrincipal aPrincipal,
131
in AUTF8String uri,
132
in unsigned long flags);
133
134
/**
135
* Returns true if the URI is from a domain that is allow-listed through
136
* prefs to be allowed to use file:// URIs.
137
* @param aUri the URI to be tested
138
*/
139
bool inFileURIAllowlist(in nsIURI aUri);
140
141
///////////////// Principals ///////////////////////
142
143
/**
144
* Return the all-powerful system principal.
145
*/
146
nsIPrincipal getSystemPrincipal();
147
148
/**
149
* Returns a principal that has the OriginAttributes of the load context.
150
* @param loadContext to get the OriginAttributes from.
151
*/
152
nsIPrincipal getLoadContextContentPrincipal(in nsIURI uri,
153
in nsILoadContext loadContext);
154
155
/**
156
* Returns a principal that has the OriginAttributes of the docshell.
157
* @param docShell to get the OriginAttributes from.
158
*/
159
nsIPrincipal getDocShellContentPrincipal(in nsIURI uri,
160
in nsIDocShell docShell);
161
162
/**
163
* If this is a content principal, return a copy with different
164
* origin attributes.
165
*/
166
[implicit_jscontext]
167
nsIPrincipal principalWithOA(in nsIPrincipal principal,
168
in jsval originAttributes);
169
170
/**
171
* Returns a principal whose origin is composed of |uri| and |originAttributes|.
172
* See nsIPrincipal.idl for a description of origin attributes, and
173
* ChromeUtils.webidl for a list of origin attributes and their defaults.
174
*/
175
[implicit_jscontext]
176
nsIPrincipal createContentPrincipal(in nsIURI uri, in jsval originAttributes);
177
178
/**
179
* Returns a principal whose origin is the one we pass in.
180
* See nsIPrincipal.idl for a description of origin attributes, and
181
* ChromeUtils.webidl for a list of origin attributes and their defaults.
182
*/
183
nsIPrincipal createContentPrincipalFromOrigin(in ACString origin);
184
185
/**
186
* Takes a principal and returns a string representation of it or a nullptr if it can't be serialized.
187
* Example output: `{"1": {"0": "https://mozilla.com", "2": "^privateBrowsingId=1"}}`
188
*/
189
ACString principalToJSON(in nsIPrincipal principal);
190
191
/**
192
* Takes a string of the following format:
193
* `{"1": {"0": "https://mozilla.com", "2": "^privateBrowsingId=1"}}`
194
* and turns it into a principal or a nullptr on error.
195
*/
196
nsIPrincipal JSONToPrincipal(in ACString json);
197
198
/**
199
* Returns a unique nonce principal with |originAttributes|.
200
* See nsIPrincipal.idl for a description of origin attributes, and
201
* ChromeUtils.webidl for a list of origin attributes and their defaults.
202
*/
203
[implicit_jscontext]
204
nsIPrincipal createNullPrincipal(in jsval originAttributes);
205
206
/**
207
* Returns OK if aSourceURI and target have the same "origin"
208
* (scheme, host, and port).
209
* ReportError flag suppresses error reports for functions that
210
* don't need reporting.
211
* FromPrivateWindow indicates whether the error occurs in a private
212
* window or not.
213
*/
214
void checkSameOriginURI(in nsIURI aSourceURI,
215
in nsIURI aTargetURI,
216
in boolean reportError,
217
in boolean fromPrivateWindow);
218
219
/**
220
* Get the principal for the given channel. This will typically be the
221
* channel owner if there is one, and the content principal for the
222
* channel's URI otherwise. aChannel must not be null.
223
*/
224
nsIPrincipal getChannelResultPrincipal(in nsIChannel aChannel);
225
226
/**
227
* Get the storage principal for the given channel. This is basically the
228
* same of getChannelResultPrincipal() execept for trackers, where we
229
* return a principal with a different OriginAttributes.
230
*/
231
nsIPrincipal getChannelResultStoragePrincipal(in nsIChannel aChannel);
232
233
/**
234
* This method does getChannelResultPrincipal() +
235
* getChannelResultStoragePrincipal().
236
* This method is mainly done for Document::Reset(). There are no other
237
* reasons to use this method.
238
*/
239
void getChannelResultPrincipals(in nsIChannel aChannel,
240
out nsIPrincipal aPrincipal,
241
out nsIPrincipal aStoragePrincipal);
242
243
/**
244
* Temporary API until bug 1220687 is fixed.
245
*
246
* Returns the same value as getChannelResultPrincipal, but ignoring
247
* sandboxing. Specifically, if sandboxing would have prevented the
248
* channel's triggering principal from being returned by
249
* getChannelResultPrincipal, the triggering principal will be returned
250
* by this method.
251
*
252
* Note that this method only ignores sandboxing of the channel in
253
* question, it does not ignore sandboxing of any channels further up a
254
* document chain. The triggering principal itself may still be the null
255
* principal due to sandboxing further up a document chain. In that regard
256
* the ignoring of sandboxing is limited.
257
*/
258
[noscript, nostdcall]
259
nsIPrincipal getChannelResultPrincipalIfNotSandboxed(in nsIChannel aChannel);
260
261
/**
262
* Get the content principal for the channel's URI.
263
* aChannel must not be null.
264
*/
265
nsIPrincipal getChannelURIPrincipal(in nsIChannel aChannel);
266
267
const unsigned long DEFAULT_USER_CONTEXT_ID = 0;
268
269
const unsigned long DEFAULT_PRIVATE_BROWSING_ID = 0;
270
271
/**
272
* Per-domain controls to enable and disable script. This system is designed
273
* to be used by at most one consumer, and enforces this with its semantics.
274
*
275
* Initially, domainPolicyActive is false. When activateDomainPolicy() is
276
* invoked, domainPolicyActive becomes true, and subsequent calls to
277
* activateDomainPolicy() will fail until deactivate() is invoked on the
278
* nsIDomainPolicy returned from activateDomainPolicy(). At this point,
279
* domainPolicyActive becomes false again, and a new consumer may acquire
280
* control of the system by invoking activateDomainPolicy().
281
*/
282
nsIDomainPolicy activateDomainPolicy();
283
readonly attribute boolean domainPolicyActive;
284
285
/**
286
* Only the parent process can directly access domain policies, child
287
* processes only have a read-only mirror to the one in the parent.
288
* For child processes the mirror is updated via messages
289
* and ContentChild will hold the DomainPolicy by calling
290
* ActivateDomainPolicyInternal directly. New consumer to this
291
* function should not be addded.
292
*/
293
[noscript] nsIDomainPolicy activateDomainPolicyInternal();
294
295
/**
296
* This function is for internal use only. Every time a child process is spawned, we
297
* must clone any active domain policies in the parent to the new child.
298
*/
299
[noscript, notxpcom] void cloneDomainPolicy(in DomainPolicyClonePtr aClone);
300
301
/**
302
* Query mechanism for the above policy.
303
*
304
* If domainPolicyEnabled is false, this simply returns the current value
305
* of javascript.enabled. Otherwise, it returns the same value, but taking
306
* the various blocklist/allowlist exceptions into account.
307
*/
308
bool policyAllowsScript(in nsIURI aDomain);
309
};
310
311
%{C++
312
#define NS_SCRIPTSECURITYMANAGER_CONTRACTID "@mozilla.org/scriptsecuritymanager;1"
313
%}