Attachment #8984570: Align LoadInfo::mServiceWorkerTaintingSynthesized handling with other service worker fields. r=valentin for bug #1467852

View | Details | Raw Unified | Return to bug 1467852
Collapse All | Expand All

(-)a/netwerk/base/LoadInfo.cpp (-1 / +2 lines)
Line     Link Here 
 Lines 391-407   LoadInfo::LoadInfo(const LoadInfo& rhs) Link Here 
391
      rhs.mRedirectChainIncludingInternalRedirects)
391
      rhs.mRedirectChainIncludingInternalRedirects)
392
  , mRedirectChain(rhs.mRedirectChain)
392
  , mRedirectChain(rhs.mRedirectChain)
393
  , mAncestorPrincipals(rhs.mAncestorPrincipals)
393
  , mAncestorPrincipals(rhs.mAncestorPrincipals)
394
  , mAncestorOuterWindowIDs(rhs.mAncestorOuterWindowIDs)
394
  , mAncestorOuterWindowIDs(rhs.mAncestorOuterWindowIDs)
395
  , mCorsUnsafeHeaders(rhs.mCorsUnsafeHeaders)
395
  , mCorsUnsafeHeaders(rhs.mCorsUnsafeHeaders)
396
  , mForcePreflight(rhs.mForcePreflight)
396
  , mForcePreflight(rhs.mForcePreflight)
397
  , mIsPreflight(rhs.mIsPreflight)
397
  , mIsPreflight(rhs.mIsPreflight)
398
  , mLoadTriggeredFromExternal(rhs.mLoadTriggeredFromExternal)
398
  , mLoadTriggeredFromExternal(rhs.mLoadTriggeredFromExternal)
399
  , mServiceWorkerTaintingSynthesized(rhs.mServiceWorkerTaintingSynthesized)
399
  // mServiceWorkerTaintingSynthesized must be handled specially during redirect
400
  , mServiceWorkerTaintingSynthesized(false)
400
{
401
{
401
}
402
}
402
403
403
LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
404
LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
404
                   nsIPrincipal* aTriggeringPrincipal,
405
                   nsIPrincipal* aTriggeringPrincipal,
405
                   nsIPrincipal* aPrincipalToInherit,
406
                   nsIPrincipal* aPrincipalToInherit,
406
                   nsIPrincipal* aSandboxedLoadingPrincipal,
407
                   nsIPrincipal* aSandboxedLoadingPrincipal,
407
                   nsIURI* aResultPrincipalURI,
408
                   nsIURI* aResultPrincipalURI,
(-)a/netwerk/base/LoadInfo.h (-8 lines)
Line     Link Here 
 Lines 78-101   public: Link Here 
78
  // nsBaseChannel::Redirect()
78
  // nsBaseChannel::Redirect()
79
  already_AddRefed<nsILoadInfo>
79
  already_AddRefed<nsILoadInfo>
80
  CloneWithNewSecFlags(nsSecurityFlags aSecurityFlags) const;
80
  CloneWithNewSecFlags(nsSecurityFlags aSecurityFlags) const;
81
  // creates a copy of the loadinfo which is appropriate to use for a
81
  // creates a copy of the loadinfo which is appropriate to use for a
82
  // separate request. I.e. not for a redirect or an inner channel, but
82
  // separate request. I.e. not for a redirect or an inner channel, but
83
  // when a separate request is made with the same security properties.
83
  // when a separate request is made with the same security properties.
84
  already_AddRefed<nsILoadInfo> CloneForNewRequest() const;
84
  already_AddRefed<nsILoadInfo> CloneForNewRequest() const;
85
85
86
  // The service worker and fetch specifications require returning the
87
  // exact tainting level of the Response passed to FetchEvent.respondWith().
88
  // This method allows us to override the tainting level in that case.
89
  //
90
  // NOTE: This should not be used outside of service worker code! Use
91
  //       nsILoadInfo::MaybeIncreaseTainting() instead.
92
  void SynthesizeServiceWorkerTainting(LoadTainting aTainting);
93
94
  void SetIsPreflight();
86
  void SetIsPreflight();
95
  void SetUpgradeInsecureRequests();
87
  void SetUpgradeInsecureRequests();
96
  void SetBrowserUpgradeInsecureRequests();
88
  void SetBrowserUpgradeInsecureRequests();
97
  void SetBrowserWouldUpgradeInsecureRequests();
89
  void SetBrowserWouldUpgradeInsecureRequests();
98
90
99
private:
91
private:
100
  // private constructor that is only allowed to be called from within
92
  // private constructor that is only allowed to be called from within
101
  // HttpChannelParent and FTPChannelParent declared as friends undeneath.
93
  // HttpChannelParent and FTPChannelParent declared as friends undeneath.
(-)a/netwerk/base/nsILoadInfo.idl (+11 lines)
Line     Link Here 
 Lines 39-54   native OriginAttributes(mozilla::OriginA Link Here 
39
[ref] native PrincipalArrayRef(const nsTArray<nsCOMPtr<nsIPrincipal>>);
39
[ref] native PrincipalArrayRef(const nsTArray<nsCOMPtr<nsIPrincipal>>);
40
[ref] native const_ClientInfoRef(const mozilla::dom::ClientInfo);
40
[ref] native const_ClientInfoRef(const mozilla::dom::ClientInfo);
41
      native UniqueClientSource(mozilla::UniquePtr<mozilla::dom::ClientSource>);
41
      native UniqueClientSource(mozilla::UniquePtr<mozilla::dom::ClientSource>);
42
      native UniqueClientSourceMove(mozilla::UniquePtr<mozilla::dom::ClientSource>&&);
42
      native UniqueClientSourceMove(mozilla::UniquePtr<mozilla::dom::ClientSource>&&);
43
[ref] native const_MaybeClientInfoRef(const mozilla::Maybe<mozilla::dom::ClientInfo>);
43
[ref] native const_MaybeClientInfoRef(const mozilla::Maybe<mozilla::dom::ClientInfo>);
44
[ref] native const_ServiceWorkerDescriptorRef(const mozilla::dom::ServiceWorkerDescriptor);
44
[ref] native const_ServiceWorkerDescriptorRef(const mozilla::dom::ServiceWorkerDescriptor);
45
[ref] native const_MaybeServiceWorkerDescriptorRef(const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor>);
45
[ref] native const_MaybeServiceWorkerDescriptorRef(const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor>);
46
[ptr] native PerformanceStoragePtr(mozilla::dom::PerformanceStorage);
46
[ptr] native PerformanceStoragePtr(mozilla::dom::PerformanceStorage);
47
      native LoadTainting(mozilla::LoadTainting);
47
48
48
typedef unsigned long nsSecurityFlags;
49
typedef unsigned long nsSecurityFlags;
49
50
50
/**
51
/**
51
 * The LoadInfo object contains information about a network load, why it
52
 * The LoadInfo object contains information about a network load, why it
52
 * was started, and how we plan on using the resulting response.
53
 * was started, and how we plan on using the resulting response.
53
 * If a network request is redirected, the new channel will receive a new
54
 * If a network request is redirected, the new channel will receive a new
54
 * LoadInfo object. The new object will contain mostly the same
55
 * LoadInfo object. The new object will contain mostly the same
 Lines 986-994   interface nsILoadInfo : nsISupports Link Here 
986
  [noscript, nostdcall, notxpcom]
987
  [noscript, nostdcall, notxpcom]
987
  void SetPerformanceStorage(in PerformanceStoragePtr aPerformanceStorage);
988
  void SetPerformanceStorage(in PerformanceStoragePtr aPerformanceStorage);
988
989
989
  /**
990
  /**
990
   * Get the PerformanceStorage.
991
   * Get the PerformanceStorage.
991
   */
992
   */
992
  [noscript, nostdcall, notxpcom]
993
  [noscript, nostdcall, notxpcom]
993
  PerformanceStoragePtr GetPerformanceStorage();
994
  PerformanceStoragePtr GetPerformanceStorage();
995
996
  /* The service worker and fetch specifications require returning the
997
   * exact tainting level of the Response passed to FetchEvent.respondWith().
998
   * This method allows us to override the tainting level in that case.
999
   *
1000
   * NOTE: This should not be used outside of service worker code! Use
1001
   *       nsILoadInfo::MaybeIncreaseTainting() instead.
1002
   */
1003
  [noscript, nostdcall, notxpcom]
1004
  void SynthesizeServiceWorkerTainting(in LoadTainting aTainting);
994
};
1005
};
(-)a/netwerk/protocol/http/HttpChannelChild.cpp (+18 lines)
Line     Link Here 
 Lines 1803-1818   HttpChannelChild::Redirect1Begin(const u Link Here 
1803
1803
1804
void
1804
void
1805
HttpChannelChild::BeginNonIPCRedirect(nsIURI* responseURI,
1805
HttpChannelChild::BeginNonIPCRedirect(nsIURI* responseURI,
1806
                                      const nsHttpResponseHead* responseHead,
1806
                                      const nsHttpResponseHead* responseHead,
1807
                                      bool aResponseRedirected)
1807
                                      bool aResponseRedirected)
1808
{
1808
{
1809
  LOG(("HttpChannelChild::BeginNonIPCRedirect [this=%p]\n", this));
1809
  LOG(("HttpChannelChild::BeginNonIPCRedirect [this=%p]\n", this));
1810
1810
1811
  // This method is only used by child-side service workers.  It should not be
1812
  // used by new code.  We want to remove it in the future.
1813
  MOZ_DIAGNOSTIC_ASSERT(mSynthesizedResponse);
1814
1811
  // If the response has been redirected, propagate all the URLs to content.
1815
  // If the response has been redirected, propagate all the URLs to content.
1812
  // Thus, the exact value of the redirect flag does not matter as long as it's
1816
  // Thus, the exact value of the redirect flag does not matter as long as it's
1813
  // not REDIRECT_INTERNAL.
1817
  // not REDIRECT_INTERNAL.
1814
  const uint32_t redirectFlag =
1818
  const uint32_t redirectFlag =
1815
    aResponseRedirected ? nsIChannelEventSink::REDIRECT_TEMPORARY
1819
    aResponseRedirected ? nsIChannelEventSink::REDIRECT_TEMPORARY
1816
                        : nsIChannelEventSink::REDIRECT_INTERNAL;
1820
                        : nsIChannelEventSink::REDIRECT_INTERNAL;
1817
1821
1818
1822
 Lines 1828-1843   HttpChannelChild::BeginNonIPCRedirect(ns Link Here 
1828
    // is a synthesized response that has its own security info, the pre-redirect channel
1832
    // is a synthesized response that has its own security info, the pre-redirect channel
1829
    // has already received it and it must be propagated to the post-redirect channel.
1833
    // has already received it and it must be propagated to the post-redirect channel.
1830
    nsCOMPtr<nsIHttpChannelChild> channelChild = do_QueryInterface(newChannel);
1834
    nsCOMPtr<nsIHttpChannelChild> channelChild = do_QueryInterface(newChannel);
1831
    if (mSecurityInfo && channelChild) {
1835
    if (mSecurityInfo && channelChild) {
1832
      HttpChannelChild* httpChannelChild = static_cast<HttpChannelChild*>(channelChild.get());
1836
      HttpChannelChild* httpChannelChild = static_cast<HttpChannelChild*>(channelChild.get());
1833
      httpChannelChild->OverrideSecurityInfoForNonIPCRedirect(mSecurityInfo);
1837
      httpChannelChild->OverrideSecurityInfoForNonIPCRedirect(mSecurityInfo);
1834
    }
1838
    }
1835
1839
1840
    // Normally we don't propagate the LoadInfo's service worker tainting
1841
    // synthesis flag on redirect.  A real redirect normally will want to allow
1842
    // normal tainting to proceed from its starting taint.  For this particular
1843
    // redirect, though, we are performing a redirect to communicate the URL of
1844
    // the service worker synthetic response itself.  This redirect still represents
1845
    // the synthetic response, so we must preserve the flag.
1846
    if (mLoadInfo && mLoadInfo->GetServiceWorkerTaintingSynthesized()) {
1847
      nsCOMPtr<nsILoadInfo> newChannelLoadInfo;
1848
      Unused << newChannel->GetLoadInfo(getter_AddRefs(newChannelLoadInfo));
1849
      if (newChannelLoadInfo) {
1850
        newChannelLoadInfo->SynthesizeServiceWorkerTainting(mLoadInfo->GetTainting());
1851
      }
1852
    }
1853
1836
    nsCOMPtr<nsIEventTarget> target = GetNeckoTarget();
1854
    nsCOMPtr<nsIEventTarget> target = GetNeckoTarget();
1837
    MOZ_ASSERT(target);
1855
    MOZ_ASSERT(target);
1838
1856
1839
    rv = gHttpHandler->AsyncOnChannelRedirect(this,
1857
    rv = gHttpHandler->AsyncOnChannelRedirect(this,
1840
                                              newChannel,
1858
                                              newChannel,
1841
                                              redirectFlag,
1859
                                              redirectFlag,
1842
                                              target);
1860
                                              target);
1843
  }
1861
  }
(-)a/netwerk/protocol/http/InterceptedHttpChannel.cpp (+11 lines)
Line     Link Here 
 Lines 267-282   InterceptedHttpChannel::RedirectForRespo Link Here 
267
  uint32_t flags = aResponseRedirected ? nsIChannelEventSink::REDIRECT_TEMPORARY
267
  uint32_t flags = aResponseRedirected ? nsIChannelEventSink::REDIRECT_TEMPORARY
268
                                       : nsIChannelEventSink::REDIRECT_INTERNAL;
268
                                       : nsIChannelEventSink::REDIRECT_INTERNAL;
269
269
270
  nsCOMPtr<nsILoadInfo> redirectLoadInfo =
270
  nsCOMPtr<nsILoadInfo> redirectLoadInfo =
271
    CloneLoadInfoForRedirect(aResponseURI, flags);
271
    CloneLoadInfoForRedirect(aResponseURI, flags);
272
  newChannel->SetLoadInfo(redirectLoadInfo);
272
  newChannel->SetLoadInfo(redirectLoadInfo);
273
  NS_ENSURE_SUCCESS(rv, rv);
273
  NS_ENSURE_SUCCESS(rv, rv);
274
274
275
  // Normally we don't propagate the LoadInfo's service worker tainting
276
  // synthesis flag on redirect.  A real redirect normally will want to allow
277
  // normal tainting to proceed from its starting taint.  For this particular
278
  // redirect, though, we are performing a redirect to communicate the URL of
279
  // the service worker synthetic response itself.  This redirect still represents
280
  // the synthetic response, so we must preserve the flag.
281
  if (redirectLoadInfo && mLoadInfo &&
282
      mLoadInfo->GetServiceWorkerTaintingSynthesized()) {
283
    redirectLoadInfo->SynthesizeServiceWorkerTainting(mLoadInfo->GetTainting());
284
  }
285
275
  rv = SetupReplacementChannel(aResponseURI, newChannel, true, flags);
286
  rv = SetupReplacementChannel(aResponseURI, newChannel, true, flags);
276
  NS_ENSURE_SUCCESS(rv, rv);
287
  NS_ENSURE_SUCCESS(rv, rv);
277
288
278
  mRedirectChannel = newChannel;
289
  mRedirectChannel = newChannel;
279
290
280
  rv = gHttpHandler->AsyncOnChannelRedirect(this, mRedirectChannel, flags);
291
  rv = gHttpHandler->AsyncOnChannelRedirect(this, mRedirectChannel, flags);
281
292
282
  if (NS_FAILED(rv)) {
293
  if (NS_FAILED(rv)) {

Return to bug 1467852