From 115cf1e322bdabaee001781e1d5a8ee4928992af Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 22 Apr 2018 22:17:09 +0200 Subject: Revert "Bug 1182569: Update ContentSecurityManager to handle docshell loads" This reverts commit 2e33335820b2816bee111e78588ac82e401c86ae. --- dom/security/nsContentSecurityManager.cpp | 81 +++++++------------------------ 1 file changed, 17 insertions(+), 64 deletions(-) (limited to 'dom/security') diff --git a/dom/security/nsContentSecurityManager.cpp b/dom/security/nsContentSecurityManager.cpp index 458f41144..9329c558a 100644 --- a/dom/security/nsContentSecurityManager.cpp +++ b/dom/security/nsContentSecurityManager.cpp @@ -10,9 +10,6 @@ #include "nsIStreamListener.h" #include "nsIDocument.h" #include "nsMixedContentBlocker.h" -#include "nsCDefaultURIFixup.h" -#include "nsIURIFixup.h" -#include "nsINestedURI.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/TabChild.h" @@ -247,6 +244,10 @@ DoCORSChecks(nsIChannel* aChannel, nsILoadInfo* aLoadInfo, static nsresult DoContentSecurityChecks(nsIChannel* aChannel, nsILoadInfo* aLoadInfo) { + nsCOMPtr uri; + nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri)); + NS_ENSURE_SUCCESS(rv, rv); + nsContentPolicyType contentPolicyType = aLoadInfo->GetExternalContentPolicyType(); nsContentPolicyType internalContentPolicyType = @@ -254,24 +255,12 @@ DoContentSecurityChecks(nsIChannel* aChannel, nsILoadInfo* aLoadInfo) nsCString mimeTypeGuess; nsCOMPtr requestingContext = nullptr; - nsCOMPtr uri; - nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri)); - NS_ENSURE_SUCCESS(rv, rv); - - if (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT || - contentPolicyType == nsIContentPolicy::TYPE_SUBDOCUMENT) { - // TYPE_DOCUMENT and TYPE_SUBDOCUMENT loads might potentially - // be wyciwyg:// channels. Let's fix up the URI so we can - // perform proper security checks. - nsCOMPtr urifixup(do_GetService(NS_URIFIXUP_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && urifixup) { - nsCOMPtr fixedURI; - rv = urifixup->CreateExposableURI(uri, getter_AddRefs(fixedURI)); - if (NS_SUCCEEDED(rv)) { - uri = fixedURI; - } - } - } +#ifdef DEBUG + // Don't enforce TYPE_DOCUMENT assertions for loads + // initiated by javascript tests. + bool skipContentTypeCheck = false; + skipContentTypeCheck = Preferences::GetBool("network.loadinfo.skip_type_assertion"); +#endif switch(contentPolicyType) { case nsIContentPolicy::TYPE_OTHER: { @@ -305,14 +294,16 @@ DoContentSecurityChecks(nsIChannel* aChannel, nsILoadInfo* aLoadInfo) } case nsIContentPolicy::TYPE_DOCUMENT: { - mimeTypeGuess = EmptyCString(); - requestingContext = aLoadInfo->LoadingNode(); + MOZ_ASSERT(skipContentTypeCheck || false, "contentPolicyType not supported yet"); break; } case nsIContentPolicy::TYPE_SUBDOCUMENT: { mimeTypeGuess = NS_LITERAL_CSTRING("text/html"); requestingContext = aLoadInfo->LoadingNode(); + MOZ_ASSERT(!requestingContext || + requestingContext->NodeType() == nsIDOMNode::DOCUMENT_NODE, + "type_subdocument requires requestingContext of type Document"); break; } @@ -456,32 +447,18 @@ DoContentSecurityChecks(nsIChannel* aChannel, nsILoadInfo* aLoadInfo) MOZ_ASSERT(false, "can not perform security check without a valid contentType"); } - // For document loads we use the triggeringPrincipal as the originPrincipal. - // Note the the loadingPrincipal for loads of TYPE_DOCUMENT is a nullptr. - nsCOMPtr principal = - (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT || - contentPolicyType == nsIContentPolicy::TYPE_SUBDOCUMENT) - ? aLoadInfo->TriggeringPrincipal() - : aLoadInfo->LoadingPrincipal(); - int16_t shouldLoad = nsIContentPolicy::ACCEPT; rv = NS_CheckContentLoadPolicy(internalContentPolicyType, uri, - principal, + aLoadInfo->LoadingPrincipal(), requestingContext, mimeTypeGuess, nullptr, //extra, &shouldLoad, nsContentUtils::GetContentPolicy(), nsContentUtils::GetSecurityManager()); - - if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) { - if ((NS_SUCCEEDED(rv) && shouldLoad == nsIContentPolicy::REJECT_TYPE) && - (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT || - contentPolicyType == nsIContentPolicy::TYPE_SUBDOCUMENT)) { - // for docshell loads we might have to return SHOW_ALT. - return NS_ERROR_CONTENT_BLOCKED_SHOW_ALT; - } + NS_ENSURE_SUCCESS(rv, rv); + if (NS_CP_REJECTED(shouldLoad)) { return NS_ERROR_CONTENT_BLOCKED; } @@ -629,30 +606,6 @@ nsContentSecurityManager::CheckChannel(nsIChannel* aChannel) nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri)); NS_ENSURE_SUCCESS(rv, rv); - nsContentPolicyType contentPolicyType = - loadInfo->GetExternalContentPolicyType(); - - if (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT || - contentPolicyType == nsIContentPolicy::TYPE_SUBDOCUMENT) { - // query the nested URI for security checks like in the case of view-source - nsCOMPtr nestedURI = do_QueryInterface(uri); - if (nestedURI) { - nestedURI->GetInnerURI(getter_AddRefs(uri)); - } - - // TYPE_DOCUMENT and TYPE_SUBDOCUMENT loads might potentially - // be wyciwyg:// channels. Let's fix up the URI so we can - // perform proper security checks. - nsCOMPtr urifixup(do_GetService(NS_URIFIXUP_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && urifixup) { - nsCOMPtr fixedURI; - rv = urifixup->CreateExposableURI(uri, getter_AddRefs(fixedURI)); - if (NS_SUCCEEDED(rv)) { - uri = fixedURI; - } - } - } - // Handle cookie policies uint32_t cookiePolicy = loadInfo->GetCookiePolicy(); if (cookiePolicy == nsILoadInfo::SEC_COOKIES_SAME_ORIGIN) { -- cgit v1.2.3