Bug 1329186 - (1) Use asyncOpen2() and (2) change nsILoadInfo.SEC_NORMAL to SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL when using a SystemPrincipal r=IanN a=IanN
authorPhilip Chee <philip.chee@gmail.com>
Sun, 22 Jan 2017 23:47:02 +0800
changeset 24096 c0d44cd135763ae69491ccb887051e347050e15c
parent 24095 d1e921152a8fd1c4d87580a5f6e7682f96058d6f
child 24097 13d07cf86fa66c3068c84d056c9e5bc3bc0f6ce4
push id1973
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:55:50 +0000
treeherdercomm-aurora@9b85bcae26a8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN, IanN
bugs1329186
Bug 1329186 - (1) Use asyncOpen2() and (2) change nsILoadInfo.SEC_NORMAL to SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL when using a SystemPrincipal r=IanN a=IanN
suite/browser/test/browser/browser_pluginplaypreview.js
suite/common/nsContextMenu.js
suite/common/sidebar/sidebarOverlay.js
suite/common/src/nsAbout.js
suite/common/src/nsGopherProtocolStubHandler.js
suite/feeds/src/FeedConverter.js
suite/feeds/src/FeedWriter.js
suite/mailnews/addrbook/abCommon.js
--- a/suite/browser/test/browser/browser_pluginplaypreview.js
+++ b/suite/browser/test/browser/browser_pluginplaypreview.js
@@ -98,19 +98,19 @@ function registerPlayPreview(mimeType, t
       // Cancel the request so the viewer can handle it.
       aRequest.cancel(Components.results.NS_BINDING_ABORTED);
 
       // Create a new channel that is viewer loaded as a resource.
       var ioService = Services.io;
       var channel = ios.newChannel2(targetUrl, null, null, null,
                                     Services.scriptSecurityManager.getSystemPrincipal(),
                                     null,
-                                    Components.interfaces.nsILoadInfo.SEC_NORMAL,
+                                    Components.interfaces.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                     Components.interfaces.nsIContentPolicy.TYPE_OTHER);
-      channel.asyncOpen(this.listener, aContext);
+      channel.asyncOpen2(this.listener);
     },
 
     // nsIRequestObserver::onStopRequest
     onStopRequest: function(aRequest, aContext, aStatusCode) {
       // Do nothing.
     }
   };
 
--- a/suite/common/nsContextMenu.js
+++ b/suite/common/nsContextMenu.js
@@ -1086,17 +1086,17 @@ nsContextMenu.prototype = {
       channel.cancel(NS_ERROR_SAVE_LINK_AS_TIMEOUT);
     }
 
     // set up a channel to do the saving
     var ios = Services.io;
     var channel = ios.newChannel2(linkURL, null, null, null,
                                   Services.scriptSecurityManager.getSystemPrincipal(),
                                   null,
-                                  Components.interfaces.nsILoadInfo.SEC_NORMAL,
+                                  Components.interfaces.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                   Components.interfaces.nsIContentPolicy.TYPE_OTHER);
     channel.notificationCallbacks = new Callbacks();
 
     var flags = Components.interfaces.nsIChannel.LOAD_CALL_CONTENT_SNIFFERS;
 
     if (bypassCache)
       flags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
 
@@ -1114,17 +1114,17 @@ nsContextMenu.prototype = {
         channel.forceAllowThirdPartyCookie = true;
     }
 
     // fallback to the old way if we don't see the headers quickly
     var timeToWait = Services.prefs.getIntPref("browser.download.saveLinkAsFilenameTimeout");
     var timer = setTimeout(timerCallback, timeToWait);
 
     // kick off the channel with our proxy object as the listener
-    channel.asyncOpen(new SaveAsListener(), null);
+    channel.asyncOpen2(new SaveAsListener());
   },
 
   // Save URL of clicked-on image, video, or audio.
   saveMedia: function() {
     var doc = this.target.ownerDocument;
     if (this.onCanvas)
       // Bypass cache, since it's a data: URL.
       saveImageURL(this.target.toDataURL(), "canvas.png", "SaveImageTitle",
--- a/suite/common/sidebar/sidebarOverlay.js
+++ b/suite/common/sidebar/sidebarOverlay.js
@@ -833,17 +833,17 @@ function check_for_missing_panels() {
     currTab = new sbPanel(currHeader.getAttribute("id"), currHeader, i);
     if (!currTab.is_excluded()) {
       if (currHeader.hasAttribute("prereq") && currHeader.getAttribute("prereq") != "") {
         var prereq_file = currHeader.getAttribute("prereq");
         var ios = Services.io;
         var channel = ios.newChannel2(prereq_file, null, null, null,
                                       Services.scriptSecurityManager.getSystemPrincipal(),
                                       null,
-                                      Components.interfaces.nsILoadInfo.SEC_NORMAL,
+                                      Components.interfaces.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                       Components.interfaces.nsIContentPolicy.TYPE_OTHER);
         try {
           channel.open();
         }
         catch(ex if (ex.result == Components.results.NS_ERROR_FILE_NOT_FOUND)) {
           sidebarObj.datasource.Assert(RDF.GetResource(currHeader.getAttribute("id")),
                                        RDF.GetResource(NC + "exclude"),
                                        RDF.GetLiteral(sidebarObj.component),
--- a/suite/common/src/nsAbout.js
+++ b/suite/common/src/nsAbout.js
@@ -47,17 +47,17 @@ About.prototype = {
   newChannel: function(aURI, aLoadInfo) {
     var module = this.getModule(aURI);
     var newURI = Services.io.newURI(this[module + "URI"]);
     var channel = aLoadInfo ?
                   Services.io.newChannelFromURIWithLoadInfo(newURI, aLoadInfo) :
                   Services.io.newChannelFromURI2(newURI, null,
                                                  Services.scriptSecurityManager.getSystemPrincipal(),
                                                  null,
-                                                 Components.interfaces.nsILoadInfo.SEC_NORMAL,
+                                                 Components.interfaces.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                                  Components.interfaces.nsIContentPolicy.TYPE_OTHER);
     channel.originalURI = aURI;
     if (this[module + "Flags"] & UNTRUSTED)
       channel.owner = null;
     return channel;
   },
 
   getIndexedDBOriginPostfix: function(aURI) {
--- a/suite/common/src/nsGopherProtocolStubHandler.js
+++ b/suite/common/src/nsGopherProtocolStubHandler.js
@@ -49,17 +49,17 @@ GopherProtocol.prototype = {
   newChannel2: function GP_newChannel2(inputURI, loadinfo) {
     var ios = Services.io;
     var newURI = ios.newURI("chrome://communicator/content/gopherAddon.xhtml");
     // Create a chrome channel, and de-chrome it, to our information page.
     var chan = loadinfo ? ios.newChannelFromURIWithLoadInfo(newURI, loadinfo) :
                           ios.newChannelFromURI2(newURI, null,
                                                  Services.scriptSecurityManager.getSystemPrincipal(),
                                                  null,
-                                                 Components.interfaces.nsILoadInfo.SEC_NORMAL,
+                                                 Components.interfaces.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                                  Components.interfaces.nsIContentPolicy.TYPE_OTHER);
     chan.originalURI = inputURI;
     chan.owner = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
                            .getService(Components.interfaces.nsIScriptSecurityManager)
                            .getCodebasePrincipal(inputURI);
     return chan;
   }
 };
--- a/suite/feeds/src/FeedConverter.js
+++ b/suite/feeds/src/FeedConverter.js
@@ -259,17 +259,17 @@ FeedConverter.prototype = {
                                       .createCodebasePrincipal(chromeURI,
                                                                loadInfo.originAttributes);
         chromeChannel.originalURI = result.uri;
       }
       else
         chromeChannel = Services.io.newChannelFromURIWithLoadInfo(result.uri, loadInfo);
 
       chromeChannel.loadGroup = this._request.loadGroup;
-      chromeChannel.asyncOpen(this._listener, null);
+      chromeChannel.asyncOpen2(this._listener);
     }
     finally {
       this._releaseHandles();
     }
   },
 
   /**
    * See nsIStreamListener.idl
@@ -529,17 +529,17 @@ GenericProtocolHandler.prototype = {
   newChannel2: function newChannel(aUri, aLoadinfo) {
     var uri = aUri.QueryInterface(Components.interfaces.nsINestedURI).innerURI;
     var ios = Services.io;
     var channel = aLoadinfo ?
                   ios.newChannelFromURIWithLoadInfo(uri, aLoadinfo) :
                   ios.newChannelFromURI2(uri, null,
                                          Services.scriptSecurityManager.getSystemPrincipal(),
                                          null,
-                                         Components.interfaces.nsILoadInfo.SEC_NORMAL,
+                                         Components.interfaces.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                          Components.interfaces.nsIContentPolicy.TYPE_OTHER);
     if (channel instanceof Components.interfaces.nsIHttpChannel)
       // Set this so we know this is supposed to be a feed
       channel.setRequestHeader("X-Moz-Is-Feed", "1", false);
     channel.originalURI = aUri;
     return channel;
   },
 
--- a/suite/feeds/src/FeedWriter.js
+++ b/suite/feeds/src/FeedWriter.js
@@ -507,18 +507,18 @@ FeedWriter.prototype = {
         } catch (ex) {
         }
 
       }
 
       if (enc.hasKey("length") && /^[0-9]+$/.test(enc.get("length"))) {
         let enc_size = convertByteUnits(parseInt(enc.get("length")));
 
-        let size_text = this._getFormattedString("enclosureSizeText",
-                             [enc_size[0], this._getString(enc_size[1])]);
+        size_text = this._getFormattedString("enclosureSizeText",
+                         [enc_size[0], this._getString(enc_size[1])]);
       }
 
       let iconimg = this._document.createElementNS(HTML_NS, "img");
       iconimg.setAttribute("src", mozicon);
       iconimg.setAttribute("class", "type-icon");
       enclosureDiv.appendChild(iconimg);
 
       enclosureDiv.appendChild(this._document.createTextNode( " " ));
@@ -969,21 +969,23 @@ FeedWriter.prototype = {
    * @param aWindow
    *        The window of the document invoking the BrowserFeedWriter
    */
   _getOriginalURI: function getOriginalURI(aWindow) {
     var chan = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                       .getInterface(Components.interfaces.nsIWebNavigation)
                       .QueryInterface(Components.interfaces.nsIDocShell)
                       .currentDocumentChannel;
+    // The following channel is never openend, so it does not matter what
+    // securityFlags we pass; let's follow the principle of least privilege.
     var ios = Services.io;
     var channel = ios.newChannel2(FEEDHANDLER_URI, null, null, null,
                                   this._feedprincipal,
                                   null,
-                                  Components.interfaces.nsILoadInfo.SEC_NORMAL,
+                                  Components.interfaces.nsILoadInfo.SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED,
                                   Components.interfaces.nsIContentPolicy.TYPE_OTHER);
     var resolvedURI = channel.URI;
 
     if (resolvedURI.equals(chan.URI))
       return chan.originalURI;
 
     return null;
   },
--- a/suite/mailnews/addrbook/abCommon.js
+++ b/suite/mailnews/addrbook/abCommon.js
@@ -704,17 +704,17 @@ function storePhoto(aUri) {
   // Get the photos directory and check that it exists
   var file = getPhotosDir();
 
   // Create a channel from the URI and open it as an input stream
   var channel = Services.io.newChannelFromURI2(Services.io.newURI(aUri),
                                          null,
                                          Services.scriptSecurityManager.getSystemPrincipal(),
                                          null,
-                                         Components.interfaces.nsILoadInfo.SEC_NORMAL,
+                                         Components.interfaces.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                          Components.interfaces.nsIContentPolicy.TYPE_INTERNAL_IMAGE);
 
   var istream = channel.open();
 
   // Get the photo file
   file = makePhotoFile(file, findPhotoExt(channel));
 
   return IOUtils.saveStreamToFile(istream, file);