Bug 1505887 - Make CanCallerAccess(nsINode*) know about chromeonly content. r=bz
☠☠ backed out by dc298299ebad ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 26 Nov 2018 21:11:12 +0100
changeset 507494 7b9afff4ff11f683d9a5e46ae92d80d6e9e7add3
parent 507493 15da6e919d804d770219f720fb93b7c2d42e5f10
child 507495 490a99122a7fc04ad0ec6bf9e32036c36b92d631
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1505887
milestone65.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 1505887 - Make CanCallerAccess(nsINode*) know about chromeonly content. r=bz Differential Revision: https://phabricator.services.mozilla.com/D11409
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -2088,19 +2088,28 @@ nsContentUtils::CanCallerAccess(nsIPrinc
 
   // The subject doesn't subsume aPrincipal. Allow access only if the subject
   // is chrome.
   return IsCallerChrome();
 }
 
 // static
 bool
-nsContentUtils::CanCallerAccess(nsINode* aNode)
-{
-  return CanCallerAccess(SubjectPrincipal(), aNode->NodePrincipal());
+nsContentUtils::CanCallerAccess(const nsINode* aNode)
+{
+  nsIPrincipal* subject = SubjectPrincipal();
+  if (IsSystemPrincipal(subject)) {
+    return true;
+  }
+
+  if (aNode->ChromeOnlyAccess()) {
+    return false;
+  }
+
+  return CanCallerAccess(subject, aNode->NodePrincipal());
 }
 
 // static
 bool
 nsContentUtils::CanCallerAccess(nsPIDOMWindowInner* aWindow)
 {
   nsCOMPtr<nsIScriptObjectPrincipal> scriptObject = do_QueryInterface(aWindow);
   NS_ENSURE_TRUE(scriptObject, false);
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -629,17 +629,17 @@ public:
 
   /**
    * Checks whether two nodes come from the same origin.
    */
   static nsresult CheckSameOrigin(const nsINode* aTrustedNode,
                                   const nsINode* unTrustedNode);
 
   // Check if the (JS) caller can access aNode.
-  static bool CanCallerAccess(nsINode* aNode);
+  static bool CanCallerAccess(const nsINode* aNode);
 
   // Check if the (JS) caller can access aWindow.
   // aWindow can be either outer or inner window.
   static bool CanCallerAccess(nsPIDOMWindowInner* aWindow);
 
   // Check if the principal is chrome or an addon with the permission.
   static bool PrincipalHasPermission(nsIPrincipal* aPrincipal, const nsAtom* aPerm);