Bug 1349517 - Don't set CSP on NullPrincipal if it already has one. r=ckerschb
authorFrederik Braun <fbraun+gh@mozilla.com>
Thu, 23 Mar 2017 13:21:13 +0100
changeset 352316 5080c78d2515b840f3dc476e5147ea7c34debf1e
parent 352315 a813601f912ceb40ff643f9f12d406eca6a74e8a
child 352317 e3b2db0bf09032a3e8838fcaa66cfaac4993fa1d
push id31635
push usercbook@mozilla.com
push dateTue, 11 Apr 2017 08:17:41 +0000
treeherdermozilla-central@7031c811659d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1349517
milestone55.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 1349517 - Don't set CSP on NullPrincipal if it already has one. r=ckerschb MozReview-Commit-ID: EKqDr7RxjWE
caps/nsScriptSecurityManager.cpp
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -302,23 +302,33 @@ nsScriptSecurityManager::GetChannelResul
               nsAutoCString URISpec;
               uri->GetSpec(URISpec);
               bool isData = (NS_SUCCEEDED(uri->SchemeIs("data", &isData)) && isData);
               if (URISpec.EqualsLiteral("about:srcdoc") || isData) {
                 nsCOMPtr<nsIPrincipal> principalToInherit = loadInfo->PrincipalToInherit();
                 if (!principalToInherit) {
                   principalToInherit = loadInfo->TriggeringPrincipal();
                 }
-                nsCOMPtr<nsIContentSecurityPolicy> originalCsp;
-                principalToInherit->GetCsp(getter_AddRefs(originalCsp));
-                // if the principalToInherit had a CSP,
-                // add it to the newly created NullPrincipal.
-                if (originalCsp) {
-                  nsresult rv = (*aPrincipal)->SetCsp(originalCsp);
-                  NS_ENSURE_SUCCESS(rv, rv);
+                nsCOMPtr<nsIContentSecurityPolicy> originalCSP;
+                principalToInherit->GetCsp(getter_AddRefs(originalCSP));
+                if (originalCSP) {
+                  // if the principalToInherit had a CSP,
+                  // add it to the newly created NullPrincipal
+                  // (unless it already has one)
+                  nsCOMPtr<nsIContentSecurityPolicy> nullPrincipalCSP;
+                  (*aPrincipal)->GetCsp(getter_AddRefs(nullPrincipalCSP));
+                  if (nullPrincipalCSP) {
+                    MOZ_ASSERT(nullPrincipalCSP == originalCSP,
+                              "There should be no other CSP here.");
+                    // CSPs are equal, no need to set it again.
+                    return NS_OK;
+                  } else {
+                    nsresult rv = (*aPrincipal)->SetCsp(originalCSP);
+                    NS_ENSURE_SUCCESS(rv, rv);
+                  }
                 }
               }
             }
           return NS_OK;
         }
 
     bool forceInherit = loadInfo->GetForceInheritPrincipal();
     if (aIgnoreSandboxing && !forceInherit) {