Bug 1505887 - Make CanCallerAccess(nsINode*) know about chromeonly content. r=bz
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 26 Nov 2018 21:11:12 +0100
changeset 507506 ad4ea72ce4d4f7c9150575f6173fa0fbb05e967c
parent 507505 8221df0f4e50bbdebe7cd65c1b3adf799a1aa6a6
child 507507 07789ba4c3d73b0318cbd9fa10c8e7f110565801
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);