Bug 1201740 - Prevent interception if the request is a System XHR. r=bkelly
authorsajitk <sajitk@rocketmail.com>
Sun, 11 Oct 2015 18:13:09 +0200
changeset 267224 7c5db9a3a4b1ab8d809c8e5943f911870b8639b5
parent 267223 2e9ee2819de4a8b12372cd249419120bc4cfb668
child 267225 d6d3fcb7c0bc0e331a38c49cd0d541ccf9b83501
push idunknown
push userunknown
push dateunknown
reviewersbkelly
bugs1201740
milestone44.0a1
Bug 1201740 - Prevent interception if the request is a System XHR. r=bkelly
dom/base/nsXMLHttpRequest.cpp
--- a/dom/base/nsXMLHttpRequest.cpp
+++ b/dom/base/nsXMLHttpRequest.cpp
@@ -1713,47 +1713,51 @@ nsXMLHttpRequest::Open(const nsACString&
   mAlreadySetHeaders.Clear();
 
   // When we are called from JS we can find the load group for the page,
   // and add ourselves to it. This way any pending requests
   // will be automatically aborted if the user leaves the page.
   nsCOMPtr<nsILoadGroup> loadGroup = GetLoadGroup();
 
   nsSecurityFlags secFlags = nsILoadInfo::SEC_NORMAL;
+  nsLoadFlags loadFlags = nsIRequest::LOAD_BACKGROUND;
   if (IsSystemXHR()) {
     // Don't give this document the system principal.  We need to keep track of
     // mPrincipal being system because we use it for various security checks
     // that should be passing, but the document data shouldn't get a system
     // principal.  Hence we set the sandbox flag in loadinfo, so that 
     // GetChannelResultPrincipal will give us the nullprincipal.
     secFlags |= nsILoadInfo::SEC_SANDBOXED;
+
+    //For a XHR, disable interception
+    loadFlags |= nsIChannel::LOAD_BYPASS_SERVICE_WORKER;
   } else {
     secFlags |= nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
   }
 
   // If we have the document, use it
   if (doc) {
     rv = NS_NewChannel(getter_AddRefs(mChannel),
                        uri,
                        doc,
                        secFlags,
                        nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST,
                        loadGroup,
                        nullptr,   // aCallbacks
-                       nsIRequest::LOAD_BACKGROUND);
+                       loadFlags);
   } else {
     //otherwise use the principal
     rv = NS_NewChannel(getter_AddRefs(mChannel),
                        uri,
                        mPrincipal,
                        secFlags,
                        nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST,
                        loadGroup,
                        nullptr,   // aCallbacks
-                       nsIRequest::LOAD_BACKGROUND);
+                       loadFlags);
   }
 
   if (NS_FAILED(rv)) return rv;
 
   mState &= ~(XML_HTTP_REQUEST_USE_XSITE_AC |
               XML_HTTP_REQUEST_NEED_AC_PREFLIGHT);
 
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));