Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "mozilla/LoadInfo.h"
8 :
9 : #include "mozilla/Assertions.h"
10 : #include "mozilla/dom/ClientIPCTypes.h"
11 : #include "mozilla/dom/ClientSource.h"
12 : #include "mozilla/dom/PerformanceStorage.h"
13 : #include "mozilla/dom/TabChild.h"
14 : #include "mozilla/dom/ToJSValue.h"
15 : #include "mozIThirdPartyUtil.h"
16 : #include "nsFrameLoader.h"
17 : #include "nsIContentSecurityPolicy.h"
18 : #include "nsIDocShell.h"
19 : #include "nsIDocument.h"
20 : #include "nsIFrameLoaderOwner.h"
21 : #include "nsIInterfaceRequestorUtils.h"
22 : #include "nsISupportsImpl.h"
23 : #include "nsISupportsUtils.h"
24 : #include "nsContentUtils.h"
25 : #include "nsDocShell.h"
26 : #include "nsGlobalWindow.h"
27 : #include "nsMixedContentBlocker.h"
28 : #include "NullPrincipal.h"
29 : #include "nsRedirectHistoryEntry.h"
30 : #include "LoadInfo.h"
31 :
32 : using namespace mozilla::dom;
33 :
34 : namespace mozilla {
35 : namespace net {
36 :
37 : static uint64_t
38 0 : FindTopOuterWindowID(nsPIDOMWindowOuter* aOuter)
39 : {
40 0 : nsCOMPtr<nsPIDOMWindowOuter> outer = aOuter;
41 0 : while (nsCOMPtr<nsPIDOMWindowOuter> parent = outer->GetScriptableParentOrNull()) {
42 0 : outer = parent;
43 : }
44 0 : return outer->WindowID();
45 : }
46 :
47 0 : LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
48 : nsIPrincipal* aTriggeringPrincipal,
49 : nsINode* aLoadingContext,
50 : nsSecurityFlags aSecurityFlags,
51 : nsContentPolicyType aContentPolicyType,
52 : const Maybe<mozilla::dom::ClientInfo>& aLoadingClientInfo,
53 0 : const Maybe<mozilla::dom::ServiceWorkerDescriptor>& aController)
54 : : mLoadingPrincipal(aLoadingContext ?
55 : aLoadingContext->NodePrincipal() : aLoadingPrincipal)
56 : , mTriggeringPrincipal(aTriggeringPrincipal ?
57 0 : aTriggeringPrincipal : mLoadingPrincipal.get())
58 : , mPrincipalToInherit(nullptr)
59 : , mClientInfo(aLoadingClientInfo)
60 : , mController(aController)
61 0 : , mLoadingContext(do_GetWeakReference(aLoadingContext))
62 : , mContextForTopLevelLoad(nullptr)
63 : , mSecurityFlags(aSecurityFlags)
64 : , mInternalContentPolicyType(aContentPolicyType)
65 : , mTainting(LoadTainting::Basic)
66 : , mUpgradeInsecureRequests(false)
67 : , mBrowserUpgradeInsecureRequests(false)
68 : , mBrowserWouldUpgradeInsecureRequests(false)
69 : , mVerifySignedContent(false)
70 : , mEnforceSRI(false)
71 : , mForceAllowDataURI(false)
72 : , mAllowInsecureRedirectToDataURI(false)
73 : , mSkipContentPolicyCheckForWebRequest(false)
74 : , mOriginalFrameSrcLoad(false)
75 : , mForceInheritPrincipalDropped(false)
76 : , mInnerWindowID(0)
77 : , mOuterWindowID(0)
78 : , mParentOuterWindowID(0)
79 : , mTopOuterWindowID(0)
80 : , mFrameOuterWindowID(0)
81 : , mEnforceSecurity(false)
82 : , mInitialSecurityCheckDone(false)
83 : , mIsThirdPartyContext(false)
84 : , mIsDocshellReload(false)
85 : , mForcePreflight(false)
86 : , mIsPreflight(false)
87 : , mLoadTriggeredFromExternal(false)
88 0 : , mServiceWorkerTaintingSynthesized(false)
89 : {
90 0 : MOZ_ASSERT(mLoadingPrincipal);
91 0 : MOZ_ASSERT(mTriggeringPrincipal);
92 :
93 : #ifdef DEBUG
94 : // TYPE_DOCUMENT loads initiated by javascript tests will go through
95 : // nsIOService and use the wrong constructor. Don't enforce the
96 : // !TYPE_DOCUMENT check in those cases
97 0 : bool skipContentTypeCheck = false;
98 0 : skipContentTypeCheck = Preferences::GetBool("network.loadinfo.skip_type_assertion");
99 : #endif
100 :
101 : // This constructor shouldn't be used for TYPE_DOCUMENT loads that don't
102 : // have a loadingPrincipal
103 0 : MOZ_ASSERT(skipContentTypeCheck || mLoadingPrincipal ||
104 : mInternalContentPolicyType != nsIContentPolicy::TYPE_DOCUMENT);
105 :
106 : // We should only get an explicit controller for subresource requests.
107 0 : MOZ_DIAGNOSTIC_ASSERT(
108 : aController.isNothing() ||
109 : !nsContentUtils::IsNonSubresourceInternalPolicyType(mInternalContentPolicyType));
110 :
111 : // TODO(bug 1259873): Above, we initialize mIsThirdPartyContext to false meaning
112 : // that consumers of LoadInfo that don't pass a context or pass a context from
113 : // which we can't find a window will default to assuming that they're 1st
114 : // party. It would be nice if we could default "safe" and assume that we are
115 : // 3rd party until proven otherwise.
116 :
117 : // if consumers pass both, aLoadingContext and aLoadingPrincipal
118 : // then the loadingPrincipal must be the same as the node's principal
119 0 : MOZ_ASSERT(!aLoadingContext || !aLoadingPrincipal ||
120 : aLoadingContext->NodePrincipal() == aLoadingPrincipal);
121 :
122 : // if the load is sandboxed, we can not also inherit the principal
123 0 : if (mSecurityFlags & nsILoadInfo::SEC_SANDBOXED) {
124 0 : mForceInheritPrincipalDropped =
125 0 : (mSecurityFlags & nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL);
126 0 : mSecurityFlags &= ~nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
127 : }
128 :
129 0 : if (aLoadingContext) {
130 : // Ensure that all network requests for a window client have the ClientInfo
131 : // properly set. Workers must currently pass the loading ClientInfo explicitly.
132 : // We allow main thread requests to explicitly pass the value as well.
133 0 : if (mClientInfo.isNothing()) {
134 0 : mClientInfo = aLoadingContext->OwnerDoc()->GetClientInfo();
135 : }
136 :
137 : // For subresource loads set the service worker based on the calling
138 : // context's controller. Workers must currently pass the controller in
139 : // explicitly. We allow main thread requests to explicitly pass the value
140 : // as well, but otherwise extract from the loading context here.
141 0 : if (mController.isNothing() &&
142 0 : !nsContentUtils::IsNonSubresourceInternalPolicyType(mInternalContentPolicyType)) {
143 0 : mController = aLoadingContext->OwnerDoc()->GetController();
144 : }
145 :
146 0 : nsCOMPtr<nsPIDOMWindowOuter> contextOuter = aLoadingContext->OwnerDoc()->GetWindow();
147 0 : if (contextOuter) {
148 0 : ComputeIsThirdPartyContext(contextOuter);
149 0 : mOuterWindowID = contextOuter->WindowID();
150 0 : nsCOMPtr<nsPIDOMWindowOuter> parent = contextOuter->GetScriptableParent();
151 0 : mParentOuterWindowID = parent ? parent->WindowID() : mOuterWindowID;
152 0 : mTopOuterWindowID = FindTopOuterWindowID(contextOuter);
153 : }
154 :
155 0 : mInnerWindowID = aLoadingContext->OwnerDoc()->InnerWindowID();
156 0 : mAncestorPrincipals = aLoadingContext->OwnerDoc()->AncestorPrincipals();
157 0 : mAncestorOuterWindowIDs = aLoadingContext->OwnerDoc()->AncestorOuterWindowIDs();
158 0 : MOZ_DIAGNOSTIC_ASSERT(mAncestorPrincipals.Length() == mAncestorOuterWindowIDs.Length());
159 :
160 : // When the element being loaded is a frame, we choose the frame's window
161 : // for the window ID and the frame element's window as the parent
162 : // window. This is the behavior that Chrome exposes to add-ons.
163 : // NB: If the frameLoaderOwner doesn't have a frame loader, then the load
164 : // must be coming from an object (such as a plugin) that's loaded into it
165 : // instead of a document being loaded. In that case, treat this object like
166 : // any other non-document-loading element.
167 : nsCOMPtr<nsIFrameLoaderOwner> frameLoaderOwner =
168 0 : do_QueryInterface(aLoadingContext);
169 0 : RefPtr<nsFrameLoader> fl = frameLoaderOwner ?
170 0 : frameLoaderOwner->GetFrameLoader() : nullptr;
171 0 : if (fl) {
172 0 : nsCOMPtr<nsIDocShell> docShell = fl->GetDocShell(IgnoreErrors());
173 0 : if (docShell) {
174 0 : nsCOMPtr<nsPIDOMWindowOuter> outerWindow = do_GetInterface(docShell);
175 0 : if (outerWindow) {
176 0 : mFrameOuterWindowID = outerWindow->WindowID();
177 : }
178 : }
179 : }
180 :
181 : // if the document forces all requests to be upgraded from http to https, then
182 : // we should do that for all requests. If it only forces preloads to be upgraded
183 : // then we should enforce upgrade insecure requests only for preloads.
184 0 : mUpgradeInsecureRequests =
185 0 : aLoadingContext->OwnerDoc()->GetUpgradeInsecureRequests(false) ||
186 0 : (nsContentUtils::IsPreloadType(mInternalContentPolicyType) &&
187 0 : aLoadingContext->OwnerDoc()->GetUpgradeInsecureRequests(true));
188 :
189 : uint32_t externalType =
190 0 : nsContentUtils::InternalContentPolicyTypeToExternal(mInternalContentPolicyType);
191 0 : if (nsContentUtils::IsUpgradableDisplayType(externalType)) {
192 0 : nsCOMPtr<nsIURI> uri;
193 0 : mLoadingPrincipal->GetURI(getter_AddRefs(uri));
194 0 : if (uri) {
195 : // Checking https not secure context as http://localhost can't be upgraded
196 : bool isHttpsScheme;
197 0 : nsresult rv = uri->SchemeIs("https", &isHttpsScheme);
198 0 : if (NS_SUCCEEDED(rv) && isHttpsScheme) {
199 0 : if (nsMixedContentBlocker::ShouldUpgradeMixedDisplayContent()) {
200 0 : mBrowserUpgradeInsecureRequests = true;
201 : } else {
202 0 : mBrowserWouldUpgradeInsecureRequests = true;
203 : }
204 : }
205 : }
206 : }
207 : // if owner doc has content signature, we enforce SRI
208 0 : nsCOMPtr<nsIChannel> channel = aLoadingContext->OwnerDoc()->GetChannel();
209 0 : if (channel) {
210 0 : nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
211 0 : if (loadInfo) {
212 0 : mEnforceSRI = loadInfo->GetVerifySignedContent();
213 : }
214 : }
215 : }
216 :
217 : // If CSP requires SRI (require-sri-for), then store that information
218 : // in the loadInfo so we can enforce SRI before loading the subresource.
219 0 : if (!mEnforceSRI) {
220 : // do not look into the CSP if already true:
221 : // a CSP saying that SRI isn't needed should not
222 : // overrule GetVerifySignedContent
223 0 : if (aLoadingPrincipal) {
224 0 : nsCOMPtr<nsIContentSecurityPolicy> csp;
225 0 : aLoadingPrincipal->GetCsp(getter_AddRefs(csp));
226 : uint32_t externalType =
227 0 : nsContentUtils::InternalContentPolicyTypeToExternal(aContentPolicyType);
228 : // csp could be null if loading principal is system principal
229 0 : if (csp) {
230 0 : csp->RequireSRIForType(externalType, &mEnforceSRI);
231 : }
232 : // if CSP is delivered via a meta tag, it's speculatively available
233 : // as 'preloadCSP'. If we are preloading a script or style, we have
234 : // to apply that speculative 'preloadCSP' for such loads.
235 0 : if (!mEnforceSRI && nsContentUtils::IsPreloadType(aContentPolicyType)) {
236 0 : nsCOMPtr<nsIContentSecurityPolicy> preloadCSP;
237 0 : aLoadingPrincipal->GetPreloadCsp(getter_AddRefs(preloadCSP));
238 0 : if (preloadCSP) {
239 0 : preloadCSP->RequireSRIForType(externalType, &mEnforceSRI);
240 : }
241 : }
242 : }
243 : }
244 :
245 0 : mOriginAttributes = mLoadingPrincipal->OriginAttributesRef();
246 :
247 : // We need to do this after inheriting the document's origin attributes
248 : // above, in case the loading principal ends up being the system principal.
249 0 : if (aLoadingContext) {
250 : nsCOMPtr<nsILoadContext> loadContext =
251 0 : aLoadingContext->OwnerDoc()->GetLoadContext();
252 0 : nsCOMPtr<nsIDocShell> docShell = aLoadingContext->OwnerDoc()->GetDocShell();
253 0 : if (loadContext && docShell &&
254 0 : docShell->ItemType() == nsIDocShellTreeItem::typeContent) {
255 : bool usePrivateBrowsing;
256 0 : nsresult rv = loadContext->GetUsePrivateBrowsing(&usePrivateBrowsing);
257 0 : if (NS_SUCCEEDED(rv)) {
258 0 : mOriginAttributes.SyncAttributesWithPrivateBrowsing(usePrivateBrowsing);
259 : }
260 : }
261 : }
262 :
263 : // For chrome docshell, the mPrivateBrowsingId remains 0 even its
264 : // UsePrivateBrowsing() is true, so we only update the mPrivateBrowsingId in
265 : // origin attributes if the type of the docshell is content.
266 0 : if (aLoadingContext) {
267 0 : nsCOMPtr<nsIDocShell> docShell = aLoadingContext->OwnerDoc()->GetDocShell();
268 0 : if (docShell) {
269 0 : if (docShell->ItemType() == nsIDocShellTreeItem::typeChrome) {
270 0 : MOZ_ASSERT(mOriginAttributes.mPrivateBrowsingId == 0,
271 : "chrome docshell shouldn't have mPrivateBrowsingId set.");
272 : }
273 : }
274 : }
275 0 : }
276 :
277 : /* Constructor takes an outer window, but no loadingNode or loadingPrincipal.
278 : * This constructor should only be used for TYPE_DOCUMENT loads, since they
279 : * have a null loadingNode and loadingPrincipal.
280 : */
281 0 : LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
282 : nsIPrincipal* aTriggeringPrincipal,
283 : nsISupports* aContextForTopLevelLoad,
284 0 : nsSecurityFlags aSecurityFlags)
285 : : mLoadingPrincipal(nullptr)
286 : , mTriggeringPrincipal(aTriggeringPrincipal)
287 : , mPrincipalToInherit(nullptr)
288 0 : , mContextForTopLevelLoad(do_GetWeakReference(aContextForTopLevelLoad))
289 : , mSecurityFlags(aSecurityFlags)
290 : , mInternalContentPolicyType(nsIContentPolicy::TYPE_DOCUMENT)
291 : , mTainting(LoadTainting::Basic)
292 : , mUpgradeInsecureRequests(false)
293 : , mBrowserUpgradeInsecureRequests(false)
294 : , mBrowserWouldUpgradeInsecureRequests(false)
295 : , mVerifySignedContent(false)
296 : , mEnforceSRI(false)
297 : , mForceAllowDataURI(false)
298 : , mAllowInsecureRedirectToDataURI(false)
299 : , mSkipContentPolicyCheckForWebRequest(false)
300 : , mOriginalFrameSrcLoad(false)
301 : , mForceInheritPrincipalDropped(false)
302 : , mInnerWindowID(0)
303 : , mOuterWindowID(0)
304 : , mParentOuterWindowID(0)
305 : , mTopOuterWindowID(0)
306 : , mFrameOuterWindowID(0)
307 : , mEnforceSecurity(false)
308 : , mInitialSecurityCheckDone(false)
309 : , mIsThirdPartyContext(false) // NB: TYPE_DOCUMENT implies not third-party.
310 : , mIsDocshellReload(false)
311 : , mForcePreflight(false)
312 : , mIsPreflight(false)
313 : , mLoadTriggeredFromExternal(false)
314 0 : , mServiceWorkerTaintingSynthesized(false)
315 : {
316 : // Top-level loads are never third-party
317 : // Grab the information we can out of the window.
318 0 : MOZ_ASSERT(aOuterWindow);
319 0 : MOZ_ASSERT(mTriggeringPrincipal);
320 :
321 : // if the load is sandboxed, we can not also inherit the principal
322 0 : if (mSecurityFlags & nsILoadInfo::SEC_SANDBOXED) {
323 0 : mForceInheritPrincipalDropped =
324 0 : (mSecurityFlags & nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL);
325 0 : mSecurityFlags &= ~nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
326 : }
327 :
328 : // NB: Ignore the current inner window since we're navigating away from it.
329 0 : mOuterWindowID = aOuterWindow->WindowID();
330 :
331 : // TODO We can have a parent without a frame element in some cases dealing
332 : // with the hidden window.
333 0 : nsCOMPtr<nsPIDOMWindowOuter> parent = aOuterWindow->GetScriptableParent();
334 0 : mParentOuterWindowID = parent ? parent->WindowID() : 0;
335 0 : mTopOuterWindowID = FindTopOuterWindowID(aOuterWindow);
336 :
337 : // get the docshell from the outerwindow, and then get the originattributes
338 0 : nsCOMPtr<nsIDocShell> docShell = aOuterWindow->GetDocShell();
339 0 : MOZ_ASSERT(docShell);
340 0 : mOriginAttributes = nsDocShell::Cast(docShell)->GetOriginAttributes();
341 0 : mAncestorPrincipals = nsDocShell::Cast(docShell)->AncestorPrincipals();
342 0 : mAncestorOuterWindowIDs = nsDocShell::Cast(docShell)->AncestorOuterWindowIDs();
343 0 : MOZ_DIAGNOSTIC_ASSERT(mAncestorPrincipals.Length() == mAncestorOuterWindowIDs.Length());
344 :
345 : #ifdef DEBUG
346 0 : if (docShell->ItemType() == nsIDocShellTreeItem::typeChrome) {
347 0 : MOZ_ASSERT(mOriginAttributes.mPrivateBrowsingId == 0,
348 : "chrome docshell shouldn't have mPrivateBrowsingId set.");
349 : }
350 : #endif
351 0 : }
352 :
353 0 : LoadInfo::LoadInfo(const LoadInfo& rhs)
354 : : mLoadingPrincipal(rhs.mLoadingPrincipal)
355 : , mTriggeringPrincipal(rhs.mTriggeringPrincipal)
356 : , mPrincipalToInherit(rhs.mPrincipalToInherit)
357 : , mSandboxedLoadingPrincipal(rhs.mSandboxedLoadingPrincipal)
358 : , mResultPrincipalURI(rhs.mResultPrincipalURI)
359 : , mClientInfo(rhs.mClientInfo)
360 : // mReservedClientSource must be handled specially during redirect
361 : // mReservedClientInfo must be handled specially during redirect
362 : // mInitialClientInfo must be handled specially during redirect
363 : , mController(rhs.mController)
364 : , mPerformanceStorage(rhs.mPerformanceStorage)
365 : , mLoadingContext(rhs.mLoadingContext)
366 : , mContextForTopLevelLoad(rhs.mContextForTopLevelLoad)
367 0 : , mSecurityFlags(rhs.mSecurityFlags)
368 0 : , mInternalContentPolicyType(rhs.mInternalContentPolicyType)
369 0 : , mTainting(rhs.mTainting)
370 0 : , mUpgradeInsecureRequests(rhs.mUpgradeInsecureRequests)
371 0 : , mBrowserUpgradeInsecureRequests(rhs.mBrowserUpgradeInsecureRequests)
372 0 : , mBrowserWouldUpgradeInsecureRequests(rhs.mBrowserWouldUpgradeInsecureRequests)
373 0 : , mVerifySignedContent(rhs.mVerifySignedContent)
374 0 : , mEnforceSRI(rhs.mEnforceSRI)
375 0 : , mForceAllowDataURI(rhs.mForceAllowDataURI)
376 0 : , mAllowInsecureRedirectToDataURI(rhs.mAllowInsecureRedirectToDataURI)
377 0 : , mSkipContentPolicyCheckForWebRequest(rhs.mSkipContentPolicyCheckForWebRequest)
378 0 : , mOriginalFrameSrcLoad(rhs.mOriginalFrameSrcLoad)
379 0 : , mForceInheritPrincipalDropped(rhs.mForceInheritPrincipalDropped)
380 0 : , mInnerWindowID(rhs.mInnerWindowID)
381 0 : , mOuterWindowID(rhs.mOuterWindowID)
382 0 : , mParentOuterWindowID(rhs.mParentOuterWindowID)
383 0 : , mTopOuterWindowID(rhs.mTopOuterWindowID)
384 0 : , mFrameOuterWindowID(rhs.mFrameOuterWindowID)
385 0 : , mEnforceSecurity(rhs.mEnforceSecurity)
386 0 : , mInitialSecurityCheckDone(rhs.mInitialSecurityCheckDone)
387 0 : , mIsThirdPartyContext(rhs.mIsThirdPartyContext)
388 0 : , mIsDocshellReload(rhs.mIsDocshellReload)
389 : , mOriginAttributes(rhs.mOriginAttributes)
390 : , mRedirectChainIncludingInternalRedirects(
391 : rhs.mRedirectChainIncludingInternalRedirects)
392 : , mRedirectChain(rhs.mRedirectChain)
393 : , mAncestorPrincipals(rhs.mAncestorPrincipals)
394 : , mAncestorOuterWindowIDs(rhs.mAncestorOuterWindowIDs)
395 : , mCorsUnsafeHeaders(rhs.mCorsUnsafeHeaders)
396 0 : , mForcePreflight(rhs.mForcePreflight)
397 0 : , mIsPreflight(rhs.mIsPreflight)
398 0 : , mLoadTriggeredFromExternal(rhs.mLoadTriggeredFromExternal)
399 : // mServiceWorkerTaintingSynthesized must be handled specially during redirect
400 0 : , mServiceWorkerTaintingSynthesized(false)
401 : {
402 0 : }
403 :
404 0 : LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
405 : nsIPrincipal* aTriggeringPrincipal,
406 : nsIPrincipal* aPrincipalToInherit,
407 : nsIPrincipal* aSandboxedLoadingPrincipal,
408 : nsIURI* aResultPrincipalURI,
409 : const Maybe<ClientInfo>& aClientInfo,
410 : const Maybe<ClientInfo>& aReservedClientInfo,
411 : const Maybe<ClientInfo>& aInitialClientInfo,
412 : const Maybe<ServiceWorkerDescriptor>& aController,
413 : nsSecurityFlags aSecurityFlags,
414 : nsContentPolicyType aContentPolicyType,
415 : LoadTainting aTainting,
416 : bool aUpgradeInsecureRequests,
417 : bool aBrowserUpgradeInsecureRequests,
418 : bool aBrowserWouldUpgradeInsecureRequests,
419 : bool aVerifySignedContent,
420 : bool aEnforceSRI,
421 : bool aForceAllowDataURI,
422 : bool aAllowInsecureRedirectToDataURI,
423 : bool aSkipContentPolicyCheckForWebRequest,
424 : bool aForceInheritPrincipalDropped,
425 : uint64_t aInnerWindowID,
426 : uint64_t aOuterWindowID,
427 : uint64_t aParentOuterWindowID,
428 : uint64_t aTopOuterWindowID,
429 : uint64_t aFrameOuterWindowID,
430 : bool aEnforceSecurity,
431 : bool aInitialSecurityCheckDone,
432 : bool aIsThirdPartyContext,
433 : bool aIsDocshellReload,
434 : const OriginAttributes& aOriginAttributes,
435 : RedirectHistoryArray& aRedirectChainIncludingInternalRedirects,
436 : RedirectHistoryArray& aRedirectChain,
437 : nsTArray<nsCOMPtr<nsIPrincipal>>&& aAncestorPrincipals,
438 : const nsTArray<uint64_t>& aAncestorOuterWindowIDs,
439 : const nsTArray<nsCString>& aCorsUnsafeHeaders,
440 : bool aForcePreflight,
441 : bool aIsPreflight,
442 : bool aLoadTriggeredFromExternal,
443 0 : bool aServiceWorkerTaintingSynthesized)
444 : : mLoadingPrincipal(aLoadingPrincipal)
445 : , mTriggeringPrincipal(aTriggeringPrincipal)
446 : , mPrincipalToInherit(aPrincipalToInherit)
447 : , mResultPrincipalURI(aResultPrincipalURI)
448 : , mClientInfo(aClientInfo)
449 : , mReservedClientInfo(aReservedClientInfo)
450 : , mInitialClientInfo(aInitialClientInfo)
451 : , mController(aController)
452 : , mSecurityFlags(aSecurityFlags)
453 : , mInternalContentPolicyType(aContentPolicyType)
454 : , mTainting(aTainting)
455 : , mUpgradeInsecureRequests(aUpgradeInsecureRequests)
456 : , mBrowserUpgradeInsecureRequests(aBrowserUpgradeInsecureRequests)
457 : , mBrowserWouldUpgradeInsecureRequests(aBrowserWouldUpgradeInsecureRequests)
458 : , mVerifySignedContent(aVerifySignedContent)
459 : , mEnforceSRI(aEnforceSRI)
460 : , mForceAllowDataURI(aForceAllowDataURI)
461 : , mAllowInsecureRedirectToDataURI(aAllowInsecureRedirectToDataURI)
462 : , mSkipContentPolicyCheckForWebRequest(aSkipContentPolicyCheckForWebRequest)
463 : , mOriginalFrameSrcLoad(false)
464 : , mForceInheritPrincipalDropped(aForceInheritPrincipalDropped)
465 : , mInnerWindowID(aInnerWindowID)
466 : , mOuterWindowID(aOuterWindowID)
467 : , mParentOuterWindowID(aParentOuterWindowID)
468 : , mTopOuterWindowID(aTopOuterWindowID)
469 : , mFrameOuterWindowID(aFrameOuterWindowID)
470 : , mEnforceSecurity(aEnforceSecurity)
471 : , mInitialSecurityCheckDone(aInitialSecurityCheckDone)
472 : , mIsThirdPartyContext(aIsThirdPartyContext)
473 : , mIsDocshellReload(aIsDocshellReload)
474 : , mOriginAttributes(aOriginAttributes)
475 0 : , mAncestorPrincipals(std::move(aAncestorPrincipals))
476 : , mAncestorOuterWindowIDs(aAncestorOuterWindowIDs)
477 : , mCorsUnsafeHeaders(aCorsUnsafeHeaders)
478 : , mForcePreflight(aForcePreflight)
479 : , mIsPreflight(aIsPreflight)
480 : , mLoadTriggeredFromExternal(aLoadTriggeredFromExternal)
481 0 : , mServiceWorkerTaintingSynthesized(aServiceWorkerTaintingSynthesized)
482 : {
483 : // Only top level TYPE_DOCUMENT loads can have a null loadingPrincipal
484 0 : MOZ_ASSERT(mLoadingPrincipal || aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT);
485 0 : MOZ_ASSERT(mTriggeringPrincipal);
486 :
487 0 : mRedirectChainIncludingInternalRedirects.SwapElements(
488 0 : aRedirectChainIncludingInternalRedirects);
489 :
490 0 : mRedirectChain.SwapElements(aRedirectChain);
491 0 : }
492 :
493 : void
494 75 : LoadInfo::ComputeIsThirdPartyContext(nsPIDOMWindowOuter* aOuterWindow)
495 : {
496 : nsContentPolicyType type =
497 0 : nsContentUtils::InternalContentPolicyTypeToExternal(mInternalContentPolicyType);
498 75 : if (type == nsIContentPolicy::TYPE_DOCUMENT) {
499 : // Top-level loads are never third-party.
500 0 : mIsThirdPartyContext = false;
501 0 : return;
502 : }
503 :
504 0 : nsCOMPtr<mozIThirdPartyUtil> util(do_GetService(THIRDPARTYUTIL_CONTRACTID));
505 1 : if (NS_WARN_IF(!util)) {
506 0 : return;
507 : }
508 :
509 75 : util->IsThirdPartyWindow(aOuterWindow, nullptr, &mIsThirdPartyContext);
510 : }
511 :
512 177153 : NS_IMPL_ISUPPORTS(LoadInfo, nsILoadInfo)
513 :
514 : already_AddRefed<nsILoadInfo>
515 0 : LoadInfo::Clone() const
516 : {
517 0 : RefPtr<LoadInfo> copy(new LoadInfo(*this));
518 0 : return copy.forget();
519 : }
520 :
521 : already_AddRefed<nsILoadInfo>
522 0 : LoadInfo::CloneWithNewSecFlags(nsSecurityFlags aSecurityFlags) const
523 : {
524 0 : RefPtr<LoadInfo> copy(new LoadInfo(*this));
525 0 : copy->mSecurityFlags = aSecurityFlags;
526 0 : return copy.forget();
527 : }
528 :
529 : already_AddRefed<nsILoadInfo>
530 0 : LoadInfo::CloneForNewRequest() const
531 : {
532 0 : RefPtr<LoadInfo> copy(new LoadInfo(*this));
533 0 : copy->mEnforceSecurity = false;
534 0 : copy->mInitialSecurityCheckDone = false;
535 0 : copy->mRedirectChainIncludingInternalRedirects.Clear();
536 0 : copy->mRedirectChain.Clear();
537 0 : copy->mResultPrincipalURI = nullptr;
538 0 : return copy.forget();
539 : }
540 :
541 : NS_IMETHODIMP
542 0 : LoadInfo::GetLoadingPrincipal(nsIPrincipal** aLoadingPrincipal)
543 : {
544 0 : NS_IF_ADDREF(*aLoadingPrincipal = mLoadingPrincipal);
545 0 : return NS_OK;
546 : }
547 :
548 : nsIPrincipal*
549 765 : LoadInfo::LoadingPrincipal()
550 : {
551 1530 : return mLoadingPrincipal;
552 : }
553 :
554 : NS_IMETHODIMP
555 0 : LoadInfo::GetTriggeringPrincipal(nsIPrincipal** aTriggeringPrincipal)
556 : {
557 0 : NS_ADDREF(*aTriggeringPrincipal = mTriggeringPrincipal);
558 0 : return NS_OK;
559 : }
560 :
561 : nsIPrincipal*
562 614 : LoadInfo::TriggeringPrincipal()
563 : {
564 1228 : return mTriggeringPrincipal;
565 : }
566 :
567 : NS_IMETHODIMP
568 0 : LoadInfo::GetPrincipalToInherit(nsIPrincipal** aPrincipalToInherit)
569 : {
570 0 : NS_IF_ADDREF(*aPrincipalToInherit = mPrincipalToInherit);
571 0 : return NS_OK;
572 : }
573 :
574 : NS_IMETHODIMP
575 5 : LoadInfo::SetPrincipalToInherit(nsIPrincipal* aPrincipalToInherit)
576 : {
577 0 : MOZ_ASSERT(aPrincipalToInherit, "must be a valid principal to inherit");
578 0 : mPrincipalToInherit = aPrincipalToInherit;
579 5 : return NS_OK;
580 : }
581 :
582 : nsIPrincipal*
583 2 : LoadInfo::PrincipalToInherit()
584 : {
585 4 : return mPrincipalToInherit;
586 : }
587 :
588 : nsIPrincipal*
589 72 : LoadInfo::FindPrincipalToInherit(nsIChannel* aChannel)
590 : {
591 144 : if (mPrincipalToInherit) {
592 : return mPrincipalToInherit;
593 : }
594 :
595 0 : nsCOMPtr<nsIURI> uri = mResultPrincipalURI;
596 0 : if (!uri) {
597 140 : Unused << aChannel->GetOriginalURI(getter_AddRefs(uri));
598 : }
599 :
600 0 : auto prin = BasePrincipal::Cast(mTriggeringPrincipal);
601 70 : return prin->PrincipalToInherit(uri);
602 : }
603 :
604 : NS_IMETHODIMP
605 3 : LoadInfo::GetSandboxedLoadingPrincipal(nsIPrincipal** aPrincipal)
606 : {
607 1 : if (!(mSecurityFlags & nsILoadInfo::SEC_SANDBOXED)) {
608 0 : *aPrincipal = nullptr;
609 0 : return NS_OK;
610 : }
611 :
612 0 : if (!mSandboxedLoadingPrincipal) {
613 4 : if (mLoadingPrincipal) {
614 : mSandboxedLoadingPrincipal =
615 4 : NullPrincipal::CreateWithInheritedAttributes(mLoadingPrincipal);
616 : } else {
617 0 : OriginAttributes attrs(mOriginAttributes);
618 0 : mSandboxedLoadingPrincipal = NullPrincipal::Create(attrs);
619 : }
620 : }
621 6 : MOZ_ASSERT(mSandboxedLoadingPrincipal);
622 :
623 0 : nsCOMPtr<nsIPrincipal> copy(mSandboxedLoadingPrincipal);
624 3 : copy.forget(aPrincipal);
625 : return NS_OK;
626 : }
627 :
628 : NS_IMETHODIMP
629 62 : LoadInfo::GetLoadingDocument(nsIDocument** aResult)
630 : {
631 0 : nsCOMPtr<nsINode> node = do_QueryReferent(mLoadingContext);
632 0 : if (node) {
633 0 : nsCOMPtr<nsIDocument> context = node->OwnerDoc();
634 2 : context.forget(aResult);
635 : }
636 62 : return NS_OK;
637 : }
638 :
639 : nsINode*
640 637 : LoadInfo::LoadingNode()
641 : {
642 0 : nsCOMPtr<nsINode> node = do_QueryReferent(mLoadingContext);
643 1274 : return node;
644 : }
645 :
646 : already_AddRefed<nsISupports>
647 54 : LoadInfo::ContextForTopLevelLoad()
648 : {
649 : // Most likely you want to query LoadingNode() instead of
650 : // ContextForTopLevelLoad() if this assertion fires.
651 54 : MOZ_ASSERT(mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT,
652 : "should only query this context for top level document loads");
653 0 : nsCOMPtr<nsISupports> context = do_QueryReferent(mContextForTopLevelLoad);
654 108 : return context.forget();
655 : }
656 :
657 : already_AddRefed<nsISupports>
658 631 : LoadInfo::GetLoadingContext()
659 : {
660 0 : nsCOMPtr<nsISupports> context;
661 0 : if (mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) {
662 54 : context = ContextForTopLevelLoad();
663 : }
664 : else {
665 577 : context = LoadingNode();
666 : }
667 1262 : return context.forget();
668 : }
669 :
670 : NS_IMETHODIMP
671 0 : LoadInfo::GetLoadingContextXPCOM(nsISupports** aResult)
672 : {
673 0 : nsCOMPtr<nsISupports> context = GetLoadingContext();
674 0 : context.forget(aResult);
675 0 : return NS_OK;
676 : }
677 :
678 : NS_IMETHODIMP
679 0 : LoadInfo::GetSecurityFlags(nsSecurityFlags* aResult)
680 : {
681 0 : *aResult = mSecurityFlags;
682 0 : return NS_OK;
683 : }
684 :
685 : NS_IMETHODIMP
686 2202 : LoadInfo::GetSecurityMode(uint32_t* aFlags)
687 : {
688 2202 : *aFlags = (mSecurityFlags &
689 : (nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS |
690 : nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED |
691 : nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS |
692 : nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL |
693 : nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS));
694 2202 : return NS_OK;
695 : }
696 :
697 : NS_IMETHODIMP
698 2 : LoadInfo::GetIsInThirdPartyContext(bool* aIsInThirdPartyContext)
699 : {
700 0 : *aIsInThirdPartyContext = mIsThirdPartyContext;
701 2 : return NS_OK;
702 : }
703 :
704 : static const uint32_t sCookiePolicyMask =
705 : nsILoadInfo::SEC_COOKIES_DEFAULT |
706 : nsILoadInfo::SEC_COOKIES_INCLUDE |
707 : nsILoadInfo::SEC_COOKIES_SAME_ORIGIN |
708 : nsILoadInfo::SEC_COOKIES_OMIT;
709 :
710 : NS_IMETHODIMP
711 532 : LoadInfo::GetCookiePolicy(uint32_t *aResult)
712 : {
713 0 : uint32_t policy = mSecurityFlags & sCookiePolicyMask;
714 0 : if (policy == nsILoadInfo::SEC_COOKIES_DEFAULT) {
715 513 : policy = (mSecurityFlags & SEC_REQUIRE_CORS_DATA_INHERITS) ?
716 : nsILoadInfo::SEC_COOKIES_SAME_ORIGIN : nsILoadInfo::SEC_COOKIES_INCLUDE;
717 : }
718 :
719 0 : *aResult = policy;
720 532 : return NS_OK;
721 : }
722 :
723 : void
724 0 : LoadInfo::SetIncludeCookiesSecFlag()
725 : {
726 0 : MOZ_ASSERT(!mEnforceSecurity,
727 : "Request should not have been opened yet");
728 0 : MOZ_ASSERT((mSecurityFlags & sCookiePolicyMask) ==
729 : nsILoadInfo::SEC_COOKIES_DEFAULT);
730 0 : mSecurityFlags = (mSecurityFlags & ~sCookiePolicyMask) |
731 : nsILoadInfo::SEC_COOKIES_INCLUDE;
732 0 : }
733 :
734 : NS_IMETHODIMP
735 100 : LoadInfo::GetForceInheritPrincipal(bool* aInheritPrincipal)
736 : {
737 0 : *aInheritPrincipal =
738 0 : (mSecurityFlags & nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL);
739 100 : return NS_OK;
740 : }
741 :
742 : NS_IMETHODIMP
743 137 : LoadInfo::GetForceInheritPrincipalOverruleOwner(bool* aInheritPrincipal)
744 : {
745 0 : *aInheritPrincipal =
746 0 : (mSecurityFlags & nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL_OVERRULE_OWNER);
747 137 : return NS_OK;
748 : }
749 :
750 : NS_IMETHODIMP
751 1075 : LoadInfo::GetLoadingSandboxed(bool* aLoadingSandboxed)
752 : {
753 0 : *aLoadingSandboxed = (mSecurityFlags & nsILoadInfo::SEC_SANDBOXED);
754 1075 : return NS_OK;
755 : }
756 :
757 : NS_IMETHODIMP
758 107 : LoadInfo::GetAboutBlankInherits(bool* aResult)
759 : {
760 0 : *aResult =
761 0 : (mSecurityFlags & nsILoadInfo::SEC_ABOUT_BLANK_INHERITS);
762 107 : return NS_OK;
763 : }
764 :
765 : NS_IMETHODIMP
766 31 : LoadInfo::GetAllowChrome(bool* aResult)
767 : {
768 0 : *aResult =
769 0 : (mSecurityFlags & nsILoadInfo::SEC_ALLOW_CHROME);
770 31 : return NS_OK;
771 : }
772 :
773 : NS_IMETHODIMP
774 31 : LoadInfo::GetDisallowScript(bool* aResult)
775 : {
776 0 : *aResult =
777 0 : (mSecurityFlags & nsILoadInfo::SEC_DISALLOW_SCRIPT);
778 31 : return NS_OK;
779 : }
780 :
781 :
782 : NS_IMETHODIMP
783 0 : LoadInfo::GetDontFollowRedirects(bool* aResult)
784 : {
785 0 : *aResult =
786 0 : (mSecurityFlags & nsILoadInfo::SEC_DONT_FOLLOW_REDIRECTS);
787 0 : return NS_OK;
788 : }
789 :
790 : NS_IMETHODIMP
791 4 : LoadInfo::GetLoadErrorPage(bool* aResult)
792 : {
793 0 : *aResult =
794 0 : (mSecurityFlags & nsILoadInfo::SEC_LOAD_ERROR_PAGE);
795 4 : return NS_OK;
796 : }
797 :
798 : NS_IMETHODIMP
799 0 : LoadInfo::GetIsDocshellReload(bool* aResult)
800 : {
801 0 : *aResult = mIsDocshellReload;
802 0 : return NS_OK;
803 : }
804 :
805 : NS_IMETHODIMP
806 10 : LoadInfo::SetIsDocshellReload(bool aValue)
807 : {
808 0 : mIsDocshellReload = aValue;
809 10 : return NS_OK;
810 : }
811 :
812 : NS_IMETHODIMP
813 2816 : LoadInfo::GetExternalContentPolicyType(nsContentPolicyType* aResult)
814 : {
815 0 : *aResult = nsContentUtils::InternalContentPolicyTypeToExternal(mInternalContentPolicyType);
816 2816 : return NS_OK;
817 : }
818 :
819 : nsContentPolicyType
820 1166 : LoadInfo::InternalContentPolicyType()
821 : {
822 1166 : return mInternalContentPolicyType;
823 : }
824 :
825 : NS_IMETHODIMP
826 2 : LoadInfo::GetUpgradeInsecureRequests(bool* aResult)
827 : {
828 0 : *aResult = mUpgradeInsecureRequests;
829 2 : return NS_OK;
830 : }
831 :
832 : NS_IMETHODIMP
833 2 : LoadInfo::GetBrowserUpgradeInsecureRequests(bool* aResult)
834 : {
835 0 : *aResult = mBrowserUpgradeInsecureRequests;
836 2 : return NS_OK;
837 : }
838 :
839 : NS_IMETHODIMP
840 1 : LoadInfo::GetBrowserWouldUpgradeInsecureRequests(bool* aResult)
841 : {
842 0 : *aResult = mBrowserWouldUpgradeInsecureRequests;
843 1 : return NS_OK;
844 : }
845 :
846 : NS_IMETHODIMP
847 0 : LoadInfo::SetVerifySignedContent(bool aVerifySignedContent)
848 : {
849 0 : MOZ_ASSERT(mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT,
850 : "can only verify content for TYPE_DOCUMENT");
851 0 : mVerifySignedContent = aVerifySignedContent;
852 0 : return NS_OK;
853 : }
854 :
855 : NS_IMETHODIMP
856 113 : LoadInfo::GetVerifySignedContent(bool* aResult)
857 : {
858 0 : *aResult = mVerifySignedContent;
859 113 : return NS_OK;
860 : }
861 :
862 : NS_IMETHODIMP
863 0 : LoadInfo::SetEnforceSRI(bool aEnforceSRI)
864 : {
865 0 : mEnforceSRI = aEnforceSRI;
866 0 : return NS_OK;
867 : }
868 :
869 : NS_IMETHODIMP
870 71 : LoadInfo::GetEnforceSRI(bool* aResult)
871 : {
872 0 : *aResult = mEnforceSRI;
873 71 : return NS_OK;
874 : }
875 :
876 : NS_IMETHODIMP
877 10 : LoadInfo::SetForceAllowDataURI(bool aForceAllowDataURI)
878 : {
879 10 : MOZ_ASSERT(!mForceAllowDataURI ||
880 : mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT,
881 : "can only allow data URI navigation for TYPE_DOCUMENT");
882 0 : mForceAllowDataURI = aForceAllowDataURI;
883 10 : return NS_OK;
884 : }
885 :
886 : NS_IMETHODIMP
887 6 : LoadInfo::GetForceAllowDataURI(bool* aForceAllowDataURI)
888 : {
889 0 : *aForceAllowDataURI = mForceAllowDataURI;
890 6 : return NS_OK;
891 : }
892 :
893 : NS_IMETHODIMP
894 0 : LoadInfo::SetAllowInsecureRedirectToDataURI(bool aAllowInsecureRedirectToDataURI)
895 : {
896 0 : mAllowInsecureRedirectToDataURI = aAllowInsecureRedirectToDataURI;
897 0 : return NS_OK;
898 : }
899 :
900 : NS_IMETHODIMP
901 0 : LoadInfo::GetAllowInsecureRedirectToDataURI(bool* aAllowInsecureRedirectToDataURI)
902 : {
903 0 : *aAllowInsecureRedirectToDataURI = mAllowInsecureRedirectToDataURI;
904 0 : return NS_OK;
905 : }
906 :
907 : NS_IMETHODIMP
908 0 : LoadInfo::SetSkipContentPolicyCheckForWebRequest(bool aSkip)
909 : {
910 0 : mSkipContentPolicyCheckForWebRequest = aSkip;
911 0 : return NS_OK;
912 : }
913 :
914 : NS_IMETHODIMP
915 0 : LoadInfo::GetSkipContentPolicyCheckForWebRequest(bool* aSkip)
916 : {
917 0 : *aSkip = mSkipContentPolicyCheckForWebRequest;
918 0 : return NS_OK;
919 : }
920 :
921 : NS_IMETHODIMP
922 10 : LoadInfo::SetOriginalFrameSrcLoad(bool aOriginalFrameSrcLoad)
923 : {
924 0 : mOriginalFrameSrcLoad = aOriginalFrameSrcLoad;
925 10 : return NS_OK;
926 : }
927 :
928 : NS_IMETHODIMP
929 0 : LoadInfo::GetOriginalFrameSrcLoad(bool* aOriginalFrameSrcLoad)
930 : {
931 0 : *aOriginalFrameSrcLoad = mOriginalFrameSrcLoad;
932 0 : return NS_OK;
933 : }
934 :
935 : NS_IMETHODIMP
936 0 : LoadInfo::GetForceInheritPrincipalDropped(bool* aResult)
937 : {
938 0 : *aResult = mForceInheritPrincipalDropped;
939 0 : return NS_OK;
940 : }
941 :
942 : NS_IMETHODIMP
943 0 : LoadInfo::GetInnerWindowID(uint64_t* aResult)
944 : {
945 0 : *aResult = mInnerWindowID;
946 0 : return NS_OK;
947 : }
948 :
949 : NS_IMETHODIMP
950 60 : LoadInfo::GetOuterWindowID(uint64_t* aResult)
951 : {
952 0 : *aResult = mOuterWindowID;
953 60 : return NS_OK;
954 : }
955 :
956 : NS_IMETHODIMP
957 0 : LoadInfo::GetParentOuterWindowID(uint64_t* aResult)
958 : {
959 0 : *aResult = mParentOuterWindowID;
960 0 : return NS_OK;
961 : }
962 :
963 : NS_IMETHODIMP
964 0 : LoadInfo::GetTopOuterWindowID(uint64_t* aResult)
965 : {
966 0 : *aResult = mTopOuterWindowID;
967 0 : return NS_OK;
968 : }
969 :
970 : NS_IMETHODIMP
971 0 : LoadInfo::GetFrameOuterWindowID(uint64_t* aResult)
972 : {
973 0 : *aResult = mFrameOuterWindowID;
974 0 : return NS_OK;
975 : }
976 :
977 : NS_IMETHODIMP
978 0 : LoadInfo::GetScriptableOriginAttributes(JSContext* aCx,
979 : JS::MutableHandle<JS::Value> aOriginAttributes)
980 : {
981 0 : if (NS_WARN_IF(!ToJSValue(aCx, mOriginAttributes, aOriginAttributes))) {
982 : return NS_ERROR_FAILURE;
983 : }
984 0 : return NS_OK;
985 : }
986 :
987 : NS_IMETHODIMP
988 0 : LoadInfo::ResetPrincipalToInheritToNullPrincipal()
989 : {
990 : // take the originAttributes from the LoadInfo and create
991 : // a new NullPrincipal using those origin attributes.
992 : nsCOMPtr<nsIPrincipal> newNullPrincipal =
993 0 : NullPrincipal::Create(mOriginAttributes);
994 :
995 0 : mPrincipalToInherit = newNullPrincipal;
996 :
997 : // setting SEC_FORCE_INHERIT_PRINCIPAL_OVERRULE_OWNER will overrule
998 : // any non null owner set on the channel and will return the principal
999 : // form the loadinfo instead.
1000 0 : mSecurityFlags |= SEC_FORCE_INHERIT_PRINCIPAL_OVERRULE_OWNER;
1001 :
1002 0 : return NS_OK;
1003 : }
1004 :
1005 : NS_IMETHODIMP
1006 0 : LoadInfo::SetScriptableOriginAttributes(JSContext* aCx,
1007 : JS::Handle<JS::Value> aOriginAttributes)
1008 : {
1009 0 : OriginAttributes attrs;
1010 0 : if (!aOriginAttributes.isObject() || !attrs.Init(aCx, aOriginAttributes)) {
1011 : return NS_ERROR_INVALID_ARG;
1012 : }
1013 :
1014 0 : mOriginAttributes = attrs;
1015 0 : return NS_OK;
1016 : }
1017 :
1018 : nsresult
1019 151 : LoadInfo::GetOriginAttributes(mozilla::OriginAttributes* aOriginAttributes)
1020 : {
1021 0 : NS_ENSURE_ARG(aOriginAttributes);
1022 0 : *aOriginAttributes = mOriginAttributes;
1023 151 : return NS_OK;
1024 : }
1025 :
1026 : nsresult
1027 10 : LoadInfo::SetOriginAttributes(const mozilla::OriginAttributes& aOriginAttributes)
1028 : {
1029 0 : mOriginAttributes = aOriginAttributes;
1030 10 : return NS_OK;
1031 : }
1032 :
1033 : NS_IMETHODIMP
1034 532 : LoadInfo::SetEnforceSecurity(bool aEnforceSecurity)
1035 : {
1036 : // Indicates whether the channel was openend using AsyncOpen2. Once set
1037 : // to true, it must remain true throughout the lifetime of the channel.
1038 : // Setting it to anything else than true will be discarded.
1039 0 : MOZ_ASSERT(aEnforceSecurity, "aEnforceSecurity must be true");
1040 0 : mEnforceSecurity = mEnforceSecurity || aEnforceSecurity;
1041 532 : return NS_OK;
1042 : }
1043 :
1044 : NS_IMETHODIMP
1045 0 : LoadInfo::GetEnforceSecurity(bool* aResult)
1046 : {
1047 0 : *aResult = mEnforceSecurity;
1048 0 : return NS_OK;
1049 : }
1050 :
1051 : NS_IMETHODIMP
1052 532 : LoadInfo::SetInitialSecurityCheckDone(bool aInitialSecurityCheckDone)
1053 : {
1054 : // Indicates whether the channel was ever evaluated by the
1055 : // ContentSecurityManager. Once set to true, this flag must
1056 : // remain true throughout the lifetime of the channel.
1057 : // Setting it to anything else than true will be discarded.
1058 0 : MOZ_ASSERT(aInitialSecurityCheckDone, "aInitialSecurityCheckDone must be true");
1059 0 : mInitialSecurityCheckDone = mInitialSecurityCheckDone || aInitialSecurityCheckDone;
1060 532 : return NS_OK;
1061 : }
1062 :
1063 : NS_IMETHODIMP
1064 706 : LoadInfo::GetInitialSecurityCheckDone(bool* aResult)
1065 : {
1066 0 : *aResult = mInitialSecurityCheckDone;
1067 706 : return NS_OK;
1068 : }
1069 :
1070 : NS_IMETHODIMP
1071 0 : LoadInfo::AppendRedirectHistoryEntry(nsIRedirectHistoryEntry* aEntry,
1072 : bool aIsInternalRedirect)
1073 : {
1074 0 : NS_ENSURE_ARG(aEntry);
1075 0 : MOZ_ASSERT(NS_IsMainThread());
1076 :
1077 0 : mRedirectChainIncludingInternalRedirects.AppendElement(aEntry);
1078 0 : if (!aIsInternalRedirect) {
1079 0 : mRedirectChain.AppendElement(aEntry);
1080 : }
1081 : return NS_OK;
1082 : }
1083 :
1084 : NS_IMETHODIMP
1085 0 : LoadInfo::GetRedirects(JSContext* aCx, JS::MutableHandle<JS::Value> aRedirects,
1086 : const RedirectHistoryArray& aArray)
1087 : {
1088 0 : JS::Rooted<JSObject*> redirects(aCx, JS_NewArrayObject(aCx, aArray.Length()));
1089 0 : NS_ENSURE_TRUE(redirects, NS_ERROR_OUT_OF_MEMORY);
1090 :
1091 0 : JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
1092 0 : NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
1093 :
1094 0 : nsCOMPtr<nsIXPConnect> xpc = mozilla::services::GetXPConnect();
1095 :
1096 0 : for (size_t idx = 0; idx < aArray.Length(); idx++) {
1097 0 : JS::RootedObject jsobj(aCx);
1098 0 : nsresult rv = xpc->WrapNative(aCx, global, aArray[idx],
1099 : NS_GET_IID(nsIRedirectHistoryEntry),
1100 0 : jsobj.address());
1101 0 : NS_ENSURE_SUCCESS(rv, rv);
1102 0 : NS_ENSURE_STATE(jsobj);
1103 :
1104 0 : bool rc = JS_DefineElement(aCx, redirects, idx, jsobj, JSPROP_ENUMERATE);
1105 0 : NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
1106 : }
1107 :
1108 0 : aRedirects.setObject(*redirects);
1109 0 : return NS_OK;
1110 : }
1111 :
1112 : NS_IMETHODIMP
1113 0 : LoadInfo::GetRedirectChainIncludingInternalRedirects(JSContext* aCx, JS::MutableHandle<JS::Value> aChain)
1114 : {
1115 0 : return GetRedirects(aCx, aChain, mRedirectChainIncludingInternalRedirects);
1116 : }
1117 :
1118 : const RedirectHistoryArray&
1119 0 : LoadInfo::RedirectChainIncludingInternalRedirects()
1120 : {
1121 0 : return mRedirectChainIncludingInternalRedirects;
1122 : }
1123 :
1124 : NS_IMETHODIMP
1125 0 : LoadInfo::GetRedirectChain(JSContext* aCx, JS::MutableHandle<JS::Value> aChain)
1126 : {
1127 0 : return GetRedirects(aCx, aChain, mRedirectChain);
1128 : }
1129 :
1130 : const RedirectHistoryArray&
1131 139 : LoadInfo::RedirectChain()
1132 : {
1133 139 : return mRedirectChain;
1134 : }
1135 :
1136 : const nsTArray<nsCOMPtr<nsIPrincipal>>&
1137 0 : LoadInfo::AncestorPrincipals()
1138 : {
1139 0 : return mAncestorPrincipals;
1140 : }
1141 :
1142 : const nsTArray<uint64_t>&
1143 0 : LoadInfo::AncestorOuterWindowIDs()
1144 : {
1145 0 : return mAncestorOuterWindowIDs;
1146 : }
1147 :
1148 : void
1149 19 : LoadInfo::SetCorsPreflightInfo(const nsTArray<nsCString>& aHeaders,
1150 : bool aForcePreflight)
1151 : {
1152 0 : MOZ_ASSERT(GetSecurityMode() == nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS);
1153 0 : MOZ_ASSERT(!mInitialSecurityCheckDone);
1154 0 : mCorsUnsafeHeaders = aHeaders;
1155 0 : mForcePreflight = aForcePreflight;
1156 19 : }
1157 :
1158 : const nsTArray<nsCString>&
1159 0 : LoadInfo::CorsUnsafeHeaders()
1160 : {
1161 0 : return mCorsUnsafeHeaders;
1162 : }
1163 :
1164 : NS_IMETHODIMP
1165 0 : LoadInfo::GetForcePreflight(bool* aForcePreflight)
1166 : {
1167 0 : *aForcePreflight = mForcePreflight;
1168 0 : return NS_OK;
1169 : }
1170 :
1171 : void
1172 0 : LoadInfo::SetIsPreflight()
1173 : {
1174 0 : MOZ_ASSERT(GetSecurityMode() == nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS);
1175 0 : MOZ_ASSERT(!mInitialSecurityCheckDone);
1176 0 : mIsPreflight = true;
1177 0 : }
1178 :
1179 : void
1180 0 : LoadInfo::SetUpgradeInsecureRequests()
1181 : {
1182 0 : mUpgradeInsecureRequests = true;
1183 0 : }
1184 :
1185 : void
1186 0 : LoadInfo::SetBrowserUpgradeInsecureRequests()
1187 : {
1188 0 : mBrowserUpgradeInsecureRequests = true;
1189 0 : }
1190 :
1191 : void
1192 0 : LoadInfo::SetBrowserWouldUpgradeInsecureRequests()
1193 : {
1194 0 : mBrowserWouldUpgradeInsecureRequests = true;
1195 0 : }
1196 :
1197 : NS_IMETHODIMP
1198 0 : LoadInfo::GetIsPreflight(bool* aIsPreflight)
1199 : {
1200 0 : *aIsPreflight = mIsPreflight;
1201 0 : return NS_OK;
1202 : }
1203 :
1204 : NS_IMETHODIMP
1205 10 : LoadInfo::SetLoadTriggeredFromExternal(bool aLoadTriggeredFromExternal)
1206 : {
1207 10 : MOZ_ASSERT(!aLoadTriggeredFromExternal ||
1208 : mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT,
1209 : "can only set load triggered from external for TYPE_DOCUMENT");
1210 0 : mLoadTriggeredFromExternal = aLoadTriggeredFromExternal;
1211 10 : return NS_OK;
1212 : }
1213 :
1214 : NS_IMETHODIMP
1215 0 : LoadInfo::GetLoadTriggeredFromExternal(bool* aLoadTriggeredFromExternal)
1216 : {
1217 0 : *aLoadTriggeredFromExternal = mLoadTriggeredFromExternal;
1218 0 : return NS_OK;
1219 : }
1220 :
1221 : NS_IMETHODIMP
1222 0 : LoadInfo::GetServiceWorkerTaintingSynthesized(bool* aServiceWorkerTaintingSynthesized)
1223 : {
1224 0 : MOZ_ASSERT(aServiceWorkerTaintingSynthesized);
1225 0 : *aServiceWorkerTaintingSynthesized = mServiceWorkerTaintingSynthesized;
1226 0 : return NS_OK;
1227 : }
1228 :
1229 : NS_IMETHODIMP
1230 621 : LoadInfo::GetTainting(uint32_t* aTaintingOut)
1231 : {
1232 0 : MOZ_ASSERT(aTaintingOut);
1233 0 : *aTaintingOut = static_cast<uint32_t>(mTainting);
1234 621 : return NS_OK;
1235 : }
1236 :
1237 : NS_IMETHODIMP
1238 0 : LoadInfo::MaybeIncreaseTainting(uint32_t aTainting)
1239 : {
1240 0 : NS_ENSURE_ARG(aTainting <= TAINTING_OPAQUE);
1241 :
1242 : // Skip if the tainting has been set by the service worker.
1243 0 : if (mServiceWorkerTaintingSynthesized) {
1244 : return NS_OK;
1245 : }
1246 :
1247 0 : LoadTainting tainting = static_cast<LoadTainting>(aTainting);
1248 0 : if (tainting > mTainting) {
1249 0 : mTainting = tainting;
1250 : }
1251 : return NS_OK;
1252 : }
1253 :
1254 : void
1255 0 : LoadInfo::SynthesizeServiceWorkerTainting(LoadTainting aTainting)
1256 : {
1257 0 : MOZ_DIAGNOSTIC_ASSERT(aTainting <= LoadTainting::Opaque);
1258 0 : mTainting = aTainting;
1259 :
1260 : // Flag to prevent the tainting from being increased.
1261 0 : mServiceWorkerTaintingSynthesized = true;
1262 0 : }
1263 :
1264 : NS_IMETHODIMP
1265 1 : LoadInfo::GetIsTopLevelLoad(bool *aResult)
1266 : {
1267 0 : *aResult = mFrameOuterWindowID ? mFrameOuterWindowID == mOuterWindowID
1268 0 : : mParentOuterWindowID == mOuterWindowID;
1269 1 : return NS_OK;
1270 : }
1271 :
1272 : NS_IMETHODIMP
1273 2367 : LoadInfo::GetResultPrincipalURI(nsIURI **aURI)
1274 : {
1275 0 : NS_IF_ADDREF(*aURI = mResultPrincipalURI);
1276 2367 : return NS_OK;
1277 : }
1278 :
1279 : NS_IMETHODIMP
1280 430 : LoadInfo::SetResultPrincipalURI(nsIURI *aURI)
1281 : {
1282 0 : mResultPrincipalURI = aURI;
1283 430 : return NS_OK;
1284 : }
1285 :
1286 : void
1287 0 : LoadInfo::SetClientInfo(const ClientInfo& aClientInfo)
1288 : {
1289 0 : mClientInfo.emplace(aClientInfo);
1290 0 : }
1291 :
1292 : const Maybe<ClientInfo>&
1293 0 : LoadInfo::GetClientInfo()
1294 : {
1295 0 : return mClientInfo;
1296 : }
1297 :
1298 : void
1299 11 : LoadInfo::GiveReservedClientSource(UniquePtr<ClientSource>&& aClientSource)
1300 : {
1301 0 : MOZ_DIAGNOSTIC_ASSERT(aClientSource);
1302 0 : mReservedClientSource = std::move(aClientSource);
1303 0 : SetReservedClientInfo(mReservedClientSource->Info());
1304 11 : }
1305 :
1306 : UniquePtr<ClientSource>
1307 4 : LoadInfo::TakeReservedClientSource()
1308 : {
1309 8 : if (mReservedClientSource) {
1310 : // If the reserved ClientInfo was set due to a ClientSource being present,
1311 : // then clear that info object when the ClientSource is taken.
1312 3 : mReservedClientInfo.reset();
1313 : }
1314 8 : return std::move(mReservedClientSource);
1315 : }
1316 :
1317 : void
1318 11 : LoadInfo::SetReservedClientInfo(const ClientInfo& aClientInfo)
1319 : {
1320 0 : MOZ_DIAGNOSTIC_ASSERT(mInitialClientInfo.isNothing());
1321 : // Treat assignments of the same value as a no-op. The emplace below
1322 : // will normally assert when overwriting an existing value.
1323 11 : if (mReservedClientInfo.isSome() && mReservedClientInfo.ref() == aClientInfo) {
1324 : return;
1325 : }
1326 0 : mReservedClientInfo.emplace(aClientInfo);
1327 : }
1328 :
1329 : const Maybe<ClientInfo>&
1330 0 : LoadInfo::GetReservedClientInfo()
1331 : {
1332 0 : return mReservedClientInfo;
1333 : }
1334 :
1335 : void
1336 2 : LoadInfo::SetInitialClientInfo(const ClientInfo& aClientInfo)
1337 : {
1338 0 : MOZ_DIAGNOSTIC_ASSERT(!mReservedClientSource);
1339 2 : MOZ_DIAGNOSTIC_ASSERT(mReservedClientInfo.isNothing());
1340 : // Treat assignments of the same value as a no-op. The emplace below
1341 : // will normally assert when overwriting an existing value.
1342 2 : if (mInitialClientInfo.isSome() && mInitialClientInfo.ref() == aClientInfo) {
1343 : return;
1344 : }
1345 2 : mInitialClientInfo.emplace(aClientInfo);
1346 : }
1347 :
1348 : const Maybe<ClientInfo>&
1349 0 : LoadInfo::GetInitialClientInfo()
1350 : {
1351 0 : return mInitialClientInfo;
1352 : }
1353 :
1354 : void
1355 0 : LoadInfo::SetController(const ServiceWorkerDescriptor& aServiceWorker)
1356 : {
1357 0 : mController.emplace(aServiceWorker);
1358 0 : }
1359 :
1360 : void
1361 0 : LoadInfo::ClearController()
1362 : {
1363 0 : mController.reset();
1364 0 : }
1365 :
1366 : const Maybe<ServiceWorkerDescriptor>&
1367 7 : LoadInfo::GetController()
1368 : {
1369 7 : return mController;
1370 : }
1371 :
1372 : void
1373 : LoadInfo::SetPerformanceStorage(PerformanceStorage* aPerformanceStorage)
1374 : {
1375 : mPerformanceStorage = aPerformanceStorage;
1376 : }
1377 :
1378 : PerformanceStorage*
1379 : LoadInfo::GetPerformanceStorage()
1380 : {
1381 : return mPerformanceStorage;
1382 : }
1383 :
1384 : } // namespace net
1385 : } // namespace mozilla
|