Bug 1517466 - Clear-Site-Data header should be processed only for 2xx response status, r=farre
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 10 Jan 2019 10:54:47 +0100
changeset 510345 2b1a30512b0dd5721d6fcca0686658f31d066b7a
parent 510344 50f5048d3b938dc22b2f065de9329fd4b9b5cdc6
child 510346 5c1a8f06c28b16f7e151ed7f678194a9bda0f5d6
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfarre
bugs1517466
milestone66.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 1517466 - Clear-Site-Data header should be processed only for 2xx response status, r=farre
toolkit/components/clearsitedata/ClearSiteData.cpp
--- a/toolkit/components/clearsitedata/ClearSiteData.cpp
+++ b/toolkit/components/clearsitedata/ClearSiteData.cpp
@@ -169,19 +169,32 @@ ClearSiteData::Observe(nsISupports* aSub
     return NS_OK;
   }
 
   ClearDataFromChannel(channel);
   return NS_OK;
 }
 
 void ClearSiteData::ClearDataFromChannel(nsIHttpChannel* aChannel) {
+  MOZ_ASSERT(aChannel);
+
   nsresult rv;
   nsCOMPtr<nsIURI> uri;
 
+  uint32_t status;
+  rv = aChannel->GetResponseStatus(&status);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
+
+  // We just care about 2xx response status.
+  if (status < 200 || status >= 300) {
+    return;
+  }
+
   nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
   if (NS_WARN_IF(!ssm)) {
     return;
   }
 
   nsCOMPtr<nsIPrincipal> principal;
   rv = ssm->GetChannelResultPrincipal(aChannel, getter_AddRefs(principal));
   if (NS_WARN_IF(NS_FAILED(rv))) {