Bug 1286798 - Part 33: Restrict localStorage from being available on some pages; r=asuth
authorJan Varga <jan.varga@gmail.com>
Thu, 29 Nov 2018 21:49:01 +0100
changeset 508031 eba8447d393532c4f429c84a14c9a3a3acb5c447
parent 508030 1309fe77cfaa7237aeb193db5b3544f7c2a0f6f0
child 508032 3adfef6668aae569ca9086120be540308c005a70
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1286798
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1286798 - Part 33: Restrict localStorage from being available on some pages; r=asuth This matches the old implementation. localStorage shouldn't be available on some pages, for example about:home.
dom/localstorage/LSObject.cpp
--- a/dom/localstorage/LSObject.cpp
+++ b/dom/localstorage/LSObject.cpp
@@ -160,18 +160,30 @@ LSObject::CreateForWindow(nsPIDOMWindowI
   if (NS_WARN_IF(!principal)) {
     return NS_ERROR_FAILURE;
   }
 
   if (nsContentUtils::IsSystemPrincipal(principal)) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
+  // localStorage is not available on some pages on purpose, for example
+  // about:home. Match the old implementation by using GenerateOriginKey
+  // for the check.
+  nsCString dummyOriginAttrSuffix;
+  nsCString dummyOriginKey;
+  nsresult rv = GenerateOriginKey(principal,
+                                  dummyOriginAttrSuffix,
+                                  dummyOriginKey);
+  if (NS_FAILED(rv)) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+
   nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo());
-  nsresult rv = PrincipalToPrincipalInfo(principal, principalInfo);
+  rv = PrincipalToPrincipalInfo(principal, principalInfo);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   MOZ_ASSERT(principalInfo->type() == PrincipalInfo::TContentPrincipalInfo);
 
   nsCString origin;
   rv = QuotaManager::GetInfoFromPrincipal(principal, nullptr, nullptr, &origin);
@@ -210,18 +222,27 @@ LSObject::CreateForPrincipal(nsPIDOMWind
                              const nsAString& aDocumentURI,
                              bool aPrivate,
                              LSObject** aObject)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aPrincipal);
   MOZ_ASSERT(aObject);
 
+  nsCString dummyOriginAttrSuffix;
+  nsCString dummyOriginKey;
+  nsresult rv = GenerateOriginKey(aPrincipal,
+                                  dummyOriginAttrSuffix,
+                                  dummyOriginKey);
+  if (NS_FAILED(rv)) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+
   nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo());
-  nsresult rv = PrincipalToPrincipalInfo(aPrincipal, principalInfo);
+  rv = PrincipalToPrincipalInfo(aPrincipal, principalInfo);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   MOZ_ASSERT(principalInfo->type() == PrincipalInfo::TContentPrincipalInfo ||
              principalInfo->type() == PrincipalInfo::TSystemPrincipalInfo);
 
   nsCString origin;