Bug 1415352: Part 5a - Allow extension codebase principals to override CSP. r?bz draft
authorKris Maglione <maglione.k@gmail.com>
Tue, 07 Nov 2017 14:25:59 -0800
changeset 694623 793e2157fd27473489b35a92c58bdead7d89e1d5
parent 694622 15ab92e6689555a3b1b84bf11104b7f31e904279
child 694624 075e525f61637c0a13278590fee96213fb7b6b49
push id88175
push usermaglione.k@gmail.com
push dateTue, 07 Nov 2017 23:59:46 +0000
reviewersbz
bugs1415352
milestone58.0a1
Bug 1415352: Part 5a - Allow extension codebase principals to override CSP. r?bz We currently use plain extension codebase principals for most of the extension stylesheets that we inject into content pages. Since we want the content loaded by those stylesheets to be exempt from CSP, and can't safely use expanded principals for their loads, we need to make plain extension codebase principals exempt from CSP. MozReview-Commit-ID: IIAUWU68nor
caps/BasePrincipal.h
--- a/caps/BasePrincipal.h
+++ b/caps/BasePrincipal.h
@@ -135,21 +135,30 @@ public:
   // The aAllowIfInheritsPrincipal argument is passed through to CheckMayLoad()
   // to determine which consistituent principals may load the requested URI.
   nsIPrincipal* PrincipalToInherit(nsIURI* aRequestedURI = nullptr,
                                    bool aAllowIfInheritsPrincipal = true);
 
   /**
    * Returns true if this principal's CSP should override a document's CSP for
    * loads that it triggers. Currently true only for expanded principals which
-   * subsume the document principal.
+   * subsume the document principal, and add-on codebase principals regardless
+   * of whether they subsume the document principal.
    */
   bool OverridesCSP(nsIPrincipal* aDocumentPrincipal)
   {
-    return mKind == eExpandedPrincipal && FastSubsumes(aDocumentPrincipal);
+    // Expanded principals override CSP if and only if they subsume the document
+    // principal.
+    if (mKind == eExpandedPrincipal) {
+      return FastSubsumes(aDocumentPrincipal);
+    }
+    // Extension principals always override CSP. This is primarily for the sake
+    // of their stylesheets, which are usually loaded from channels and cannot
+    // have expanded principals.
+    return AddonPolicy();
   }
 
 protected:
   virtual ~BasePrincipal();
 
   // Note that this does not check OriginAttributes. Callers that depend on
   // those must call Subsumes instead.
   virtual bool SubsumesInternal(nsIPrincipal* aOther, DocumentDomainConsideration aConsider) = 0;