[tor-commits] [tor-browser/tor-browser-17.0.9esr-1] fixup! Isolate DOM storage to first party URI

mikeperry at torproject.org mikeperry at torproject.org
Thu Oct 3 02:40:30 UTC 2013


commit 6627ae06096197c94a5ad1a9d45d17a9ec144828
Author: Mike Perry <mikeperry-git at torproject.org>
Date:   Wed Oct 2 19:29:23 2013 -0700

    fixup! Isolate DOM storage to first party URI
    
    Make DOM Storage isolation use the simpler GetFirstPartyURI call.
---
 docshell/base/nsDocShell.cpp              |   21 +++++++-------
 dom/src/storage/nsDOMStorageDBWrapper.cpp |   45 ++++++++++++++++-------------
 2 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
index 6e9c6aa..1cef3f9 100644
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -12459,15 +12459,15 @@ nsDocShell::GetSessionStorageKey(nsIURI *aFirstPartyURI,
     if (!aOrigin)
         return NS_ERROR_FAILURE;
 
+    nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
+                            do_GetService(THIRDPARTYUTIL_CONTRACTID);
+    if (!thirdPartyUtil)
+      return NS_ERROR_FAILURE;
+
     aResult.Append(aOrigin);
 
     nsCOMPtr<nsIURI> firstPartyURI = aFirstPartyURI;
     if (!firstPartyURI) {
-        nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
-                                do_GetService(THIRDPARTYUTIL_CONTRACTID);
-        if (!thirdPartyUtil)
-          return NS_ERROR_FAILURE;
-
         nsCOMPtr<nsIDocument> doc(do_GetInterface(GetAsSupports(this)));
         nsresult rv = thirdPartyUtil->GetFirstPartyURI(nullptr, doc,
                                                getter_AddRefs(firstPartyURI));
@@ -12475,11 +12475,12 @@ nsDocShell::GetSessionStorageKey(nsIURI *aFirstPartyURI,
     }
 
     nsCAutoString host;
-    nsresult rv = firstPartyURI->GetHost(host);
-    if (NS_SUCCEEDED(rv) && (host.Length() > 0)) {
-        aResult.AppendLiteral("&");
-        aResult.Append(host);
-    }
+    nsresult rv = thirdPartyUtil->GetFirstPartyHostForIsolation(firstPartyURI,
+                                                                host);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    aResult.AppendLiteral("&");
+    aResult.Append(host);
 
     return NS_OK;
 }
diff --git a/dom/src/storage/nsDOMStorageDBWrapper.cpp b/dom/src/storage/nsDOMStorageDBWrapper.cpp
index 048738a..04942fd 100644
--- a/dom/src/storage/nsDOMStorageDBWrapper.cpp
+++ b/dom/src/storage/nsDOMStorageDBWrapper.cpp
@@ -17,6 +17,7 @@
 #include "mozIStorageService.h"
 #include "mozIStorageValueArray.h"
 #include "mozIStorageFunction.h"
+#include "mozIThirdPartyUtil.h"
 #include "nsPrintfCString.h"
 #include "nsNetUtil.h"
 
@@ -243,6 +244,9 @@ nsresult
 nsDOMStorageDBWrapper::CreateOriginScopeDBKey(nsIURI *aFirstPartyURI,
                                               nsIURI* aUri, nsACString& aKey)
 {
+  if (!aFirstPartyURI)
+    return NS_ERROR_FAILURE;
+
   nsresult rv;
 
   rv = CreateDomainScopeDBKey(aUri, aKey);
@@ -262,16 +266,15 @@ nsDOMStorageDBWrapper::CreateOriginScopeDBKey(nsIURI *aFirstPartyURI,
     aKey.Append(nsPrintfCString("%d", port));
   }
 
-  // Isolate scope keys to the URL bar domain by appending &firstPartyHost
-  // if available.
-  if (aFirstPartyURI) {
-    nsCAutoString host;
-    rv = aFirstPartyURI->GetHost(host);
-    if (NS_SUCCEEDED(rv) && (host.Length() > 0)) {
-      aKey.AppendLiteral("&");
-      aKey.Append(host);
-    }
-  }
+  // Isolate scope keys to the URL bar domain by appending &firstPartyHost.
+  nsCAutoString host;
+  nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
+                                     do_GetService(THIRDPARTYUTIL_CONTRACTID);
+  rv = thirdPartyUtil->GetFirstPartyHostForIsolation(aFirstPartyURI, host);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  aKey.AppendLiteral("&");
+  aKey.Append(host);
 
   return NS_OK;
 }
@@ -332,6 +335,9 @@ nsDOMStorageDBWrapper::CreateQuotaDomainDBKey(nsIURI *aFirstPartyURI,
                                               bool aEffectiveTLDplus1Only,
                                               nsACString& aKey)
 {
+  if (!aFirstPartyURI)
+    return NS_ERROR_FAILURE;
+
   nsresult rv;
 
   nsCAutoString subdomainsDBKey;
@@ -361,16 +367,15 @@ nsDOMStorageDBWrapper::CreateQuotaDomainDBKey(nsIURI *aFirstPartyURI,
   if (!aIncludeSubDomains)
     subdomainsDBKey.AppendLiteral(":");
 
-  // Isolate quota keys to the URL bar domain by appending &firstPartyHost
-  // if available.
-  if (aFirstPartyURI) {
-    nsCAutoString host;
-    rv = aFirstPartyURI->GetHost(host);
-    if (NS_SUCCEEDED(rv) && (host.Length() > 0)) {
-      subdomainsDBKey.AppendLiteral("&");
-      subdomainsDBKey.Append(host);
-    }
-  }
+  // Isolate scope keys to the URL bar domain by appending &firstPartyHost.
+  nsCAutoString host;
+  nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
+                                     do_GetService(THIRDPARTYUTIL_CONTRACTID);
+  rv = thirdPartyUtil->GetFirstPartyHostForIsolation(aFirstPartyURI, host);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  subdomainsDBKey.AppendLiteral("&");
+  subdomainsDBKey.Append(host);
 
   aKey.Assign(subdomainsDBKey);
   return NS_OK;





More information about the tor-commits mailing list