diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index 470f26ca3917..e1ff31a4ba5d 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -1589,7 +1589,7 @@ nsCSSStyleSheet::DidDirty() } nsresult -nsCSSStyleSheet::SubjectSubsumesInnerPrincipal() const +nsCSSStyleSheet::SubjectSubsumesInnerPrincipal() { // Get the security manager and do the subsumes check nsIScriptSecurityManager *securityManager = @@ -1612,7 +1612,26 @@ nsCSSStyleSheet::SubjectSubsumesInnerPrincipal() const } if (!nsContentUtils::IsCallerTrustedForWrite()) { - return NS_ERROR_DOM_SECURITY_ERR; + // Allow access only if CORS mode is not NONE + if (GetCORSMode() == CORS_NONE) { + return NS_ERROR_DOM_SECURITY_ERR; + } + + // Now make sure we set the principal of our inner to the + // subjectPrincipal. That means we need a unique inner, of + // course. But we don't want to do that if we're not complete + // yet. Luckily, all the callers of this method throw anyway if + // not complete, so we can just do that here too. + if (!mInner->mComplete) { + return NS_ERROR_DOM_INVALID_ACCESS_ERR; + } + + rv = WillDirty(); + NS_ENSURE_SUCCESS(rv, rv); + + mInner->mPrincipal = subjectPrincipal; + + DidDirty(); } return NS_OK; diff --git a/layout/style/nsCSSStyleSheet.h b/layout/style/nsCSSStyleSheet.h index 262433a5f872..0aaf808e6415 100644 --- a/layout/style/nsCSSStyleSheet.h +++ b/layout/style/nsCSSStyleSheet.h @@ -265,8 +265,9 @@ protected: // Return success if the subject principal subsumes the principal of our // inner, error otherwise. This will also succeed if the subject has - // UniversalXPConnect. - nsresult SubjectSubsumesInnerPrincipal() const; + // UniversalXPConnect or if access is allowed by CORS. In the latter case, + // it will set the principal of the inner to the subject principal. + nsresult SubjectSubsumesInnerPrincipal(); // Add the namespace mapping from this @namespace rule to our namespace map nsresult RegisterNamespaceRule(mozilla::css::Rule* aRule); diff --git a/layout/style/test/test_bug732209.html b/layout/style/test/test_bug732209.html index 59ef6876316a..44e9227763db 100644 --- a/layout/style/test/test_bug732209.html +++ b/layout/style/test/test_bug732209.html @@ -27,7 +27,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=732209 crossorigin="use-credentials"> -