aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/EphyBrowser.cpp
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-11-15 00:04:44 +0800
committerChristian Persch <chpe@src.gnome.org>2004-11-15 00:04:44 +0800
commit2c88315e6e2546470485400058ad20b7e115d93c (patch)
tree696e510bdf3a9f4df0500fa85ece53b14668069c /embed/mozilla/EphyBrowser.cpp
parent8d62a2a659d2c31b28b1ae7df7d3185a3e11d4bc (diff)
downloadgsoc2013-epiphany-2c88315e6e2546470485400058ad20b7e115d93c.tar
gsoc2013-epiphany-2c88315e6e2546470485400058ad20b7e115d93c.tar.gz
gsoc2013-epiphany-2c88315e6e2546470485400058ad20b7e115d93c.tar.bz2
gsoc2013-epiphany-2c88315e6e2546470485400058ad20b7e115d93c.tar.lz
gsoc2013-epiphany-2c88315e6e2546470485400058ad20b7e115d93c.tar.xz
gsoc2013-epiphany-2c88315e6e2546470485400058ad20b7e115d93c.tar.zst
gsoc2013-epiphany-2c88315e6e2546470485400058ad20b7e115d93c.zip
Check favicon urls with script sec manager and content policy.
2004-11-14 Christian Persch <chpe@cvs.gnome.org> * embed/mozilla/EphyBrowser.cpp: * embed/mozilla/EphyBrowser.h: * embed/mozilla/Makefile.am: Check favicon urls with script sec manager and content policy.
Diffstat (limited to 'embed/mozilla/EphyBrowser.cpp')
-rw-r--r--embed/mozilla/EphyBrowser.cpp97
1 files changed, 72 insertions, 25 deletions
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp
index 6e87868f5..153e16c4d 100644
--- a/embed/mozilla/EphyBrowser.cpp
+++ b/embed/mozilla/EphyBrowser.cpp
@@ -68,8 +68,13 @@
#undef MOZILLA_STRICT_API
#include "nsMemory.h"
#include "nsIChannel.h"
+#include "nsIScriptSecurityManager.h"
+#include "nsIServiceManager.h"
#ifdef ALLOW_PRIVATE_API
+/* not frozen yet */
+#include "nsIContentPolicy.h"
+/* will never be frozen */
#include "nsIDocShell.h"
#include "nsIMarkupDocumentViewer.h"
#ifdef HAVE_MOZILLA_PSM
@@ -111,9 +116,15 @@ EphyEventListener::Init(EphyEmbed *aOwner)
return NS_OK;
}
-nsresult
-EphyFaviconEventListener::HandleFaviconLink (nsIDOMNode *node)
+NS_IMETHODIMP
+EphyFaviconEventListener::HandleEvent(nsIDOMEvent* aDOMEvent)
{
+ nsCOMPtr<nsIDOMEventTarget> eventTarget;
+ aDOMEvent->GetTarget(getter_AddRefs(eventTarget));
+
+ nsCOMPtr<nsIDOMNode> node = do_QueryInterface(eventTarget);
+ NS_ENSURE_TRUE (node, NS_ERROR_FAILURE);
+
nsCOMPtr<nsIDOMElement> linkElement;
linkElement = do_QueryInterface (node);
if (!linkElement) return NS_ERROR_FAILURE;
@@ -147,36 +158,72 @@ EphyFaviconEventListener::HandleFaviconLink (nsIDOMNode *node)
nsEmbedString spec;
rv = doc->GetDocumentURI (spec);
- NS_ENSURE_SUCCESS (rv, rv);
+ NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
- nsCOMPtr<nsIURI> uri;
- rv = EphyUtils::NewURI (getter_AddRefs(uri), spec);
- NS_ENSURE_SUCCESS (rv, rv);
+ nsCOMPtr<nsIURI> docUri;
+ EphyUtils::NewURI (getter_AddRefs(docUri), spec);
+ NS_ENSURE_TRUE (docUri, NS_ERROR_FAILURE);
+
+ nsEmbedCString faviconUrl;
+ rv = docUri->Resolve (link, faviconUrl);
+ NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
- nsEmbedCString favicon_url;
- rv = uri->Resolve (link, favicon_url);
- if (NS_FAILED (rv)) return NS_ERROR_FAILURE;
-
- char *url = g_strdup (favicon_url.get());
+ nsCOMPtr<nsIURI> favUri;
+ EphyUtils::NewURI (getter_AddRefs (favUri), faviconUrl);
+ NS_ENSURE_TRUE (favUri, NS_ERROR_FAILURE);
+
+ /* check if load is allowed */
+ nsCOMPtr<nsIScriptSecurityManager> secMan
+ (do_GetService("@mozilla.org/scriptsecuritymanager;1"));
+ /* refuse if we can't check */
+ NS_ENSURE_TRUE (secMan, NS_OK);
+
+ rv = secMan->CheckLoadURI(docUri, favUri,
+ nsIScriptSecurityManager::STANDARD);
+ /* failure means it didn't pass the security check */
+ if (NS_FAILED (rv)) return NS_OK;
+
+ /* security check passed, now check with content policy */
+ nsCOMPtr<nsIContentPolicy> policy =
+ do_GetService("@mozilla.org/layout/content-policy;1");
+ /* refuse if we can't check */
+ NS_ENSURE_TRUE (policy, NS_OK);
+
+#if MOZ_NSICONTENTPOLICY_VARIANT == 2
+ /* FIXME: mozilla tabbrowser.xml passes
+ * safeGetProperty(event.target, "type") as mimetype guess:
+ */
+ PRUnichar typeAttr[] = { 't', 'y', 'p', 'e', '\0' };
+ nsEmbedString typeVal;
+ linkElement->GetAttribute (nsEmbedString (typeAttr), typeVal);
+
+ nsEmbedCString cTypeVal;
+ NS_UTF16ToCString (typeVal, NS_CSTRING_ENCODING_UTF8, cTypeVal);
+
+ PRInt16 decision = 0;
+ rv = policy->ShouldLoad (nsIContentPolicy::TYPE_IMAGE,
+ favUri, docUri, eventTarget,
+ cTypeVal, nsnull,
+ &decision);
+ NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
+ if (decision != nsIContentPolicy::ACCEPT) return NS_OK;
+#else
+ PRBool shouldLoad = PR_FALSE;
+ rv = policy->ShouldLoad (nsIContentPolicy::IMAGE,
+ favUri, eventTarget,
+ nsnull /* FIXME: DOM window*/,
+ &shouldLoad);
+ NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
+ if (!shouldLoad) return NS_OK;
+#endif
+
+ /* ok, we accept this as a valid favicon for this site */
+ char *url = g_strdup (faviconUrl.get());
g_signal_emit_by_name (mOwner, "ge_favicon", url);
g_free (url);
}
return NS_OK;
-}
-
-NS_IMETHODIMP
-EphyFaviconEventListener::HandleEvent(nsIDOMEvent* aDOMEvent)
-{
- nsCOMPtr<nsIDOMEventTarget> eventTarget;
- aDOMEvent->GetTarget(getter_AddRefs(eventTarget));
-
- nsCOMPtr<nsIDOMNode> node = do_QueryInterface(eventTarget);
- NS_ENSURE_TRUE (node, NS_ERROR_FAILURE);
-
- HandleFaviconLink (node);
-
- return NS_OK;
}
NS_IMETHODIMP