Bug 1315905 - Cleanup Necko http security check - part 1, r=valentin a=ghang
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 21 Dec 2016 10:37:42 +0100
changeset 452606 83da1807aafab6fe395af4a71085ec70eb009b96
parent 452605 1230317c6b19002205544dbefe4dddd884a4d8d1
child 452607 c05b211ecbdcbacd8860750186e20cd9d430eca5
push id39418
push userbmo:twointofive@gmail.com
push dateWed, 21 Dec 2016 20:59:30 +0000
reviewersvalentin, ghang
bugs1315905
milestone51.0
Bug 1315905 - Cleanup Necko http security check - part 1, r=valentin a=ghang
netwerk/ipc/NeckoParent.cpp
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -168,26 +168,30 @@ void CrashWithReason(const char * reason
 }
 
 const char*
 NeckoParent::GetValidatedOriginAttributes(const SerializedLoadContext& aSerialized,
                                           PContentParent* aContent,
                                           nsIPrincipal* aRequestingPrincipal,
                                           DocShellOriginAttributes& aAttrs)
 {
-  if (!aSerialized.IsNotNull()) {
-    if (UsingNeckoIPCSecurity()) {
-      CrashWithReason("GetValidatedOriginAttributes | SerializedLoadContext from child is null");
-      return "SerializedLoadContext from child is null";
+  if (!UsingNeckoIPCSecurity()) {
+    if (!aSerialized.IsNotNull()) {
+      // If serialized is null, we cannot validate anything. We have to assume
+      // that this requests comes from a SystemPrincipal.
+      aAttrs = DocShellOriginAttributes(NECKO_NO_APP_ID, false);
+    } else {
+      aAttrs = aSerialized.mOriginAttributes;
     }
+    return nullptr;
+  }
 
-    // If serialized is null, we cannot validate anything. We have to assume
-    // that this requests comes from a SystemPrincipal.
-    aAttrs = DocShellOriginAttributes(NECKO_NO_APP_ID, false);
-    return nullptr;
+  if (!aSerialized.IsNotNull()) {
+    CrashWithReason("GetValidatedOriginAttributes | SerializedLoadContext from child is null");
+    return "SerializedLoadContext from child is null";
   }
 
   nsTArray<TabContext> contextArray =
     static_cast<ContentParent*>(aContent)->GetManagedTabContext();
 
   nsAutoCString serializedSuffix;
   aSerialized.mOriginAttributes.CreateAnonymizedSuffix(serializedSuffix);
 
@@ -222,22 +226,16 @@ NeckoParent::GetValidatedOriginAttribute
     if (swm &&
         swm->MayHaveActiveServiceWorkerInstance(static_cast<ContentParent*>(aContent),
                                                 aRequestingPrincipal)) {
       aAttrs = aSerialized.mOriginAttributes;
       return nullptr;
     }
   }
 
-  if (!UsingNeckoIPCSecurity()) {
-    // We are running some tests
-    aAttrs = aSerialized.mOriginAttributes;
-    return nullptr;
-  }
-
   nsAutoCString errorString;
   errorString.Append("GetValidatedOriginAttributes | App does not have permission -");
   errorString.Append(debugString);
 
   // Leak the buffer on the heap to make sure that it lives long enough, as
   // MOZ_CRASH_ANNOTATE expects the pointer passed to it to live to the end of
   // the program.
   char * error = strdup(errorString.BeginReading());