Bug 1301123 - Add assertions ensuring that documents and inner windows cannot end up with an expanded principal; r=bholley
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 22 Sep 2016 18:35:48 -0400
changeset 315895 93a20b9fe4f9716bf5a76e89e65cdb15d79585b4
parent 315894 810a4f6dff0407c622e89cea3a6bb9a532c01cd0
child 315896 24a382443a0f871e38f4cb98ffd566c478308cd2
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1301123
milestone52.0a1
Bug 1301123 - Add assertions ensuring that documents and inner windows cannot end up with an expanded principal; r=bholley
dom/base/nsNodeInfoManager.cpp
toolkit/components/telemetry/Histograms.json
--- a/dom/base/nsNodeInfoManager.cpp
+++ b/dom/base/nsNodeInfoManager.cpp
@@ -6,16 +6,17 @@
 
 /*
  * A class for handing out nodeinfos and ensuring sharing of them as needed.
  */
 
 #include "nsNodeInfoManager.h"
 
 #include "mozilla/DebugOnly.h"
+#include "mozilla/Telemetry.h"
 #include "mozilla/dom/NodeInfo.h"
 #include "mozilla/dom/NodeInfoInlines.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsIAtom.h"
 #include "nsIDocument.h"
 #include "nsIPrincipal.h"
 #include "nsIURI.h"
@@ -384,16 +385,21 @@ void
 nsNodeInfoManager::SetDocumentPrincipal(nsIPrincipal *aPrincipal)
 {
   mPrincipal = nullptr;
   if (!aPrincipal) {
     aPrincipal = mDefaultPrincipal;
   }
 
   NS_ASSERTION(aPrincipal, "Must have principal by this point!");
+  MOZ_DIAGNOSTIC_ASSERT(!nsContentUtils::IsExpandedPrincipal(aPrincipal),
+                        "Documents shouldn't have an expanded principal");
+  if (nsContentUtils::IsExpandedPrincipal(aPrincipal)) {
+    Telemetry::Accumulate(Telemetry::DOCUMENT_WITH_EXPANDED_PRINCIPAL, 1);
+  }
 
   mPrincipal = aPrincipal;
 }
 
 void
 nsNodeInfoManager::RemoveNodeInfo(NodeInfo *aNodeInfo)
 {
   NS_PRECONDITION(aNodeInfo, "Trying to remove null nodeinfo from manager!");
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -10485,10 +10485,17 @@
   },
   "JS_AOT_USAGE": {
     "alert_emails": ["luke@mozilla.com", "bbouvier@mozilla.com"],
     "bug_numbers": [1288778],
     "expires_in_version": "56",
     "kind": "enumerated",
     "n_values": 4,
     "description": "Counts the number of asm.js vs WebAssembly modules instanciations, at the time modules are getting instanciated."
+  },
+  "DOCUMENT_WITH_EXPANDED_PRINCIPAL": {
+    "alert_emails": ["dev-platform@lists.mozilla.org"],
+    "bug_numbers": [1301123],
+    "expires_in_version": "58",
+    "kind": "count",
+    "description": "Number of documents encountered using an expanded principal."
   }
 }