Bug 1461407 - make about:home unlinkable again and improve behavior of serialized principals across changes to URLs, r?bz,Mardak draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 14 May 2018 22:04:49 +0100
changeset 796075 257e47ec684d839fcc5f5a8a55242969fd83f20b
parent 794690 45ec8fd380dd2c308e79dbb396ca87f2ce9b3f9c
push id110158
push usergijskruitbosch@gmail.com
push dateThu, 17 May 2018 00:05:01 +0000
reviewersbz, Mardak
bugs1461407
milestone62.0a1
Bug 1461407 - make about:home unlinkable again and improve behavior of serialized principals across changes to URLs, r?bz,Mardak Making about:home unlinkable changes its URL structure. Prior to this change, it is a nested URL. After this change, it no longer is. We store serialized versions of principals in some cases. These include details about whether the URI is nested etc. This is problematic for the about:home change because the change in nesting changes the origin of the page, so the origin would mismatch between the principal and its URL. To avoid this, we always re-create URIs for about: URIs when deserializing them from strings, ensuring we don't create bogus principals. MozReview-Commit-ID: 87zVUFgbusn
browser/components/about/AboutRedirector.cpp
caps/ContentPrincipal.cpp
--- a/browser/components/about/AboutRedirector.cpp
+++ b/browser/components/about/AboutRedirector.cpp
@@ -79,17 +79,17 @@ static const RedirEntry kRedirMap[] = {
     nsIAboutModule::HIDE_FROM_ABOUTABOUT },
   { "sessionrestore", "chrome://browser/content/aboutSessionRestore.xhtml",
     nsIAboutModule::ALLOW_SCRIPT |
     nsIAboutModule::HIDE_FROM_ABOUTABOUT },
   { "welcomeback", "chrome://browser/content/aboutWelcomeBack.xhtml",
     nsIAboutModule::ALLOW_SCRIPT |
     nsIAboutModule::HIDE_FROM_ABOUTABOUT },
   // Actual activity stream URL for home and newtab are set in channel creation
-  { "home", "about:blank", ACTIVITY_STREAM_FLAGS | nsIAboutModule::MAKE_LINKABLE }, // Bug 1438367 to try removing MAKE_LINKABLE again
+  { "home", "about:blank", ACTIVITY_STREAM_FLAGS },
   { "newtab", "about:blank", ACTIVITY_STREAM_FLAGS },
   { "welcome", "about:blank",
     nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
     nsIAboutModule::ALLOW_SCRIPT },
   { "library", "chrome://browser/content/aboutLibrary.xhtml",
     nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
--- a/caps/ContentPrincipal.cpp
+++ b/caps/ContentPrincipal.cpp
@@ -415,16 +415,24 @@ ContentPrincipal::Read(nsIObjectInputStr
   nsCOMPtr<nsISupports> supports;
   nsCOMPtr<nsIURI> codebase;
   nsresult rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   codebase = do_QueryInterface(supports);
+  // Enforce re-parsing about: URIs so that if they change, we continue to use
+  // their new principals correctly.
+  bool isAbout = false;
+  if (NS_SUCCEEDED(codebase->SchemeIs("about", &isAbout)) && isAbout) {
+    nsAutoCString spec;
+    codebase->GetSpec(spec);
+    NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(codebase), spec), NS_ERROR_FAILURE);
+  }
 
   nsCOMPtr<nsIURI> domain;
   rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   domain = do_QueryInterface(supports);