This commit is contained in:
Jonas Sicking 2010-03-02 11:40:14 -08:00
Родитель 95ddb6d412
Коммит d06a79e62c
4 изменённых файлов: 34 добавлений и 6 удалений

Просмотреть файл

@ -1256,6 +1256,11 @@ public:
const nsACString& aMimeGuess = EmptyCString(), const nsACString& aMimeGuess = EmptyCString(),
nsISupports* aExtra = nsnull); nsISupports* aExtra = nsnull);
/**
* Returns true if aPrincipal is the system principal.
*/
static PRBool IsSystemPrincipal(nsIPrincipal* aPrincipal);
/** /**
* Trigger a link with uri aLinkURI. If aClick is false, this triggers a * Trigger a link with uri aLinkURI. If aClick is false, this triggers a
* mouseover on the link, otherwise it triggers a load after doing a * mouseover on the link, otherwise it triggers a load after doing a

Просмотреть файл

@ -112,7 +112,7 @@ interface nsIContentPolicy : nsISupports
const unsigned long TYPE_PING = 10; const unsigned long TYPE_PING = 10;
/** /**
* Indicates an XMLHttpRequest. * Indicates an XMLHttpRequest. Also used for document.load.
*/ */
const unsigned long TYPE_XMLHTTPREQUEST = 11; const unsigned long TYPE_XMLHTTPREQUEST = 11;

Просмотреть файл

@ -4251,6 +4251,14 @@ nsContentUtils::CheckSecurityBeforeLoad(nsIURI* aURIToLoad,
return aLoadingPrincipal->CheckMayLoad(aURIToLoad, PR_TRUE); return aLoadingPrincipal->CheckMayLoad(aURIToLoad, PR_TRUE);
} }
PRBool
nsContentUtils::IsSystemPrincipal(nsIPrincipal* aPrincipal)
{
PRBool isSystem;
nsresult rv = sSecurityManager->IsSystemPrincipal(aPrincipal, &isSystem);
return NS_SUCCEEDED(rv) && isSystem;
}
/* static */ /* static */
void void
nsContentUtils::TriggerLink(nsIContent *aContent, nsPresContext *aPresContext, nsContentUtils::TriggerLink(nsIContent *aContent, nsPresContext *aPresContext,

Просмотреть файл

@ -85,6 +85,8 @@
#include "nsIScriptGlobalObjectOwner.h" #include "nsIScriptGlobalObjectOwner.h"
#include "nsIJSContextStack.h" #include "nsIJSContextStack.h"
#include "nsContentCreatorFunctions.h" #include "nsContentCreatorFunctions.h"
#include "nsContentPolicyUtils.h"
#include "nsContentErrors.h"
#include "nsIDOMUserDataHandler.h" #include "nsIDOMUserDataHandler.h"
#include "nsEventDispatcher.h" #include "nsEventDispatcher.h"
#include "nsNodeUtils.h" #include "nsNodeUtils.h"
@ -335,10 +337,6 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn)
return rv; return rv;
} }
nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
nsCOMPtr<nsIURI> codebase;
principal->GetURI(getter_AddRefs(codebase));
// Check to see whether the current document is allowed to load this URI. // Check to see whether the current document is allowed to load this URI.
// It's important to use the current document's principal for this check so // It's important to use the current document's principal for this check so
// that we don't end up in a case where code with elevated privileges is // that we don't end up in a case where code with elevated privileges is
@ -347,9 +345,26 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn)
// Enforce same-origin even for chrome loaders to avoid someone accidentally // Enforce same-origin even for chrome loaders to avoid someone accidentally
// using a document that content has a reference to and turn that into a // using a document that content has a reference to and turn that into a
// chrome document. // chrome document.
if (codebase) { nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
if (!nsContentUtils::IsSystemPrincipal(principal)) {
rv = principal->CheckMayLoad(uri, PR_FALSE); rv = principal->CheckMayLoad(uri, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XMLHTTPREQUEST,
uri,
principal,
callingDoc ? callingDoc.get() :
static_cast<nsIDocument*>(this),
NS_LITERAL_CSTRING("application/xml"),
nsnull,
&shouldLoad,
nsContentUtils::GetContentPolicy(),
nsContentUtils::GetSecurityManager());
NS_ENSURE_SUCCESS(rv, rv);
if (NS_CP_REJECTED(shouldLoad)) {
return NS_ERROR_CONTENT_BLOCKED;
}
} else { } else {
// We're called from chrome, check to make sure the URI we're // We're called from chrome, check to make sure the URI we're
// about to load is also chrome. // about to load is also chrome.