diff --git a/mozilla/caps/idl/nsIScriptSecurityManager.idl b/mozilla/caps/idl/nsIScriptSecurityManager.idl index 89d4f82df39..a2e76106a72 100644 --- a/mozilla/caps/idl/nsIScriptSecurityManager.idl +++ b/mozilla/caps/idl/nsIScriptSecurityManager.idl @@ -218,6 +218,13 @@ interface nsIScriptSecurityManager : nsIXPCSecurityManager [noscript] void checkSameOriginURI(in nsIURI aSourceURI, in nsIURI aTargetURI); + /** + * Returns OK if aSourcePrincipal and aTargetPrincipal + * have the same "origin" (scheme, host, and port). + */ + [noscript] void checkSameOriginPrincipal(in nsIPrincipal aSourcePrincipal, + in nsIPrincipal aTargetPrincipal); + }; %{C++ diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index dc8ea6ded02..107ffc74cc1 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -556,6 +556,15 @@ nsScriptSecurityManager::CheckSameOriginURI(nsIURI* aSourceURI, return NS_OK; } +NS_IMETHODIMP +nsScriptSecurityManager::CheckSameOriginPrincipal(nsIPrincipal* aSourcePrincipal, + nsIPrincipal* aTargetPrincipal) +{ + return CheckSameOriginDOMProp(aSourcePrincipal, aTargetPrincipal, + nsIXPCSecurityManager::ACCESS_SET_PROPERTY); +} + + nsresult nsScriptSecurityManager::CheckPropertyAccessImpl(PRUint32 aAction, nsIXPCNativeCallContext* aCallContext, diff --git a/mozilla/content/base/public/nsINodeInfo.h b/mozilla/content/base/public/nsINodeInfo.h index cbe2d41326d..10c8e5ad8f9 100644 --- a/mozilla/content/base/public/nsINodeInfo.h +++ b/mozilla/content/base/public/nsINodeInfo.h @@ -67,6 +67,7 @@ class nsINodeInfoManager; class nsINameSpaceManager; class nsIDocument; class nsIURI; +class nsIPrincipal; // IID for the nsINodeInfo interface @@ -287,6 +288,11 @@ public: */ NS_IMETHOD GetDocument(nsIDocument*& aDocument) const = 0; + /* + * Retrieve a pointer to the principal for the document of this node info. + */ + NS_IMETHOD GetDocumentPrincipal(nsIPrincipal** aPrincipal) const = 0; + protected: /* * nsNodeInfoInner is used for two things: @@ -368,15 +374,15 @@ public: NS_IMETHOD GetDocument(nsIDocument*& aDocument) = 0; /** - * Gets the url of the document associated with this. + * Gets the principal of the document associated with this. */ - NS_IMETHOD GetDocumentURL(nsIURI** aURL) = 0; + NS_IMETHOD GetDocumentPrincipal(nsIPrincipal** aPrincipal) = 0; /** - * Sets the url of the nodeinfo manager. This should only be called when - * this nodeinfo manager isn't connected to an nsIDocument. + * Sets the principal of the nodeinfo manager. This should only be called + * when this nodeinfo manager isn't connected to an nsIDocument. */ - NS_IMETHOD SetDocumentURL(nsIURI* aURL) = 0; + NS_IMETHOD SetDocumentPrincipal(nsIPrincipal* aPrincipal) = 0; }; diff --git a/mozilla/content/base/src/nsContentUtils.cpp b/mozilla/content/base/src/nsContentUtils.cpp index f2d0dda2a65..3e43484a21e 100644 --- a/mozilla/content/base/src/nsContentUtils.cpp +++ b/mozilla/content/base/src/nsContentUtils.cpp @@ -379,12 +379,12 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode, NS_PRECONDITION(aTrustedNode, "There must be a trusted node"); /* - * Get hold of each node's document or uri + * Get hold of each node's document or principal */ // In most cases this is a document, so lets try that first nsCOMPtr trustedDoc = do_QueryInterface(aTrustedNode); - nsCOMPtr trustedUri; + nsCOMPtr trustedPrincipal; if (!trustedDoc) { #ifdef DEBUG @@ -396,7 +396,7 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode, aTrustedNode->GetOwnerDocument(getter_AddRefs(domDoc)); if (!domDoc) { // In theory this should never happen. But since theory and reality are - // different for XUL elements we'll try to get the URI from the + // different for XUL elements we'll try to get the principal from the // nsINodeInfoManager. nsCOMPtr cont = do_QueryInterface(aTrustedNode); @@ -406,12 +406,11 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode, cont->GetNodeInfo(*getter_AddRefs(ni)); NS_ENSURE_TRUE(ni, NS_ERROR_UNEXPECTED); - nsCOMPtr nimgr; - ni->GetNodeInfoManager(*getter_AddRefs(nimgr)); - nimgr->GetDocumentURL(getter_AddRefs(trustedUri)); + ni->GetDocumentPrincipal(getter_AddRefs(trustedPrincipal)); - if (!trustedUri) { - // Can't get uri of aTrustedNode so we can't check security against it + if (!trustedPrincipal) { + // Can't get principal of aTrustedNode so we can't check security + // against it return NS_ERROR_UNEXPECTED; } @@ -429,7 +428,7 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode, nsCOMPtr content = do_QueryInterface(aUnTrustedNode); nsCOMPtr unTrustedDoc; - nsCOMPtr unTrustedUri; + nsCOMPtr unTrustedPrincipal; if (!content) { unTrustedDoc = do_QueryInterface(aUnTrustedNode); @@ -447,21 +446,21 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode, nsCOMPtr domDoc; aUnTrustedNode->GetOwnerDocument(getter_AddRefs(domDoc)); if (!domDoc) { - // if we can't get a doc then lets try to get uri through nodeinfo + // if we can't get a doc then lets try to get principal through nodeinfo // manager nsCOMPtr ni; content->GetNodeInfo(*getter_AddRefs(ni)); if (!ni) { - // we can't get to the uri so we'll give up and give the caller access + // we can't get to the principal so we'll give up and give the caller + // access return NS_OK; } - nsCOMPtr nimgr; - ni->GetNodeInfoManager(*getter_AddRefs(nimgr)); - nimgr->GetDocumentURL(getter_AddRefs(unTrustedUri)); - if (!unTrustedUri) { - // we can't get to the uri so we'll give up and give the caller access + ni->GetDocumentPrincipal(getter_AddRefs(unTrustedPrincipal)); + + if (!unTrustedPrincipal) { + // we can't get to the principal so we'll give up and give the caller access return NS_OK; } @@ -473,31 +472,31 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode, } /* - * Compare the uris + * Compare the principals */ // If they are in the same document then everything is just fine if (trustedDoc == unTrustedDoc && trustedDoc) return NS_OK; - if (!trustedUri) { - trustedDoc->GetDocumentURL(getter_AddRefs(trustedUri)); - // If the trusted node doesn't have a uri we can't check security against it - if (!trustedUri) { + if (!trustedPrincipal) { + trustedDoc->GetPrincipal(getter_AddRefs(trustedPrincipal)); + if (!trustedPrincipal) { + // If the trusted node doesn't have a principal we can't check security against it + return NS_ERROR_DOM_SECURITY_ERR; } } - // Chrome can do anything - PRBool isChrome; - nsresult rv = trustedUri->SchemeIs("chrome", &isChrome); - if (NS_SUCCEEDED(rv) && isChrome) { - return NS_OK; - } - if (!unTrustedUri) { - unTrustedDoc->GetDocumentURL(getter_AddRefs(unTrustedUri)); - // If the untrusted node doesn't have a uri we'll allow it to be accessed. - if (!unTrustedUri) { + if (!unTrustedPrincipal) { + unTrustedDoc->GetPrincipal(getter_AddRefs(unTrustedPrincipal)); + if (!unTrustedDoc) { + // We can't get hold of the principal for this node. This should happen + // very rarely, like for textnodes out of the tree and