Bug 1276419 - Don't manipulate URLs in compositions which are not under our control. r=rkent a=jorgk
authorJorg K <mozilla@jorgk.com>
Fri, 12 Aug 2016 08:07:17 +0200
changeset 27340 0d45c9451a463a9eaac0712b1ec819435b22a8da
parent 27339 d6bb01ec036b4b05b73e4c72b62c91a913f463fc
child 27341 334d53412a4c33c3230e685a7fa56eedba11379b
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrkent, jorgk
bugs1276419
Bug 1276419 - Don't manipulate URLs in compositions which are not under our control. r=rkent a=jorgk
mailnews/compose/src/nsMsgCompose.cpp
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -76,16 +76,17 @@
 #include "nsIAbManager.h"
 #include "nsCRT.h"
 #include "mozilla/Services.h"
 #include "mozilla/mailnews/MimeHeaderParser.h"
 #include "nsStreamConverter.h"
 #include "nsISelection.h"
 #include "nsJSEnvironment.h"
 #include "nsIObserverService.h"
+#include "nsIProtocolHandler.h"
 
 using namespace mozilla::mailnews;
 
 static nsresult GetReplyHeaderInfo(int32_t* reply_header_type,
                                    nsString& reply_header_locale,
                                    nsString& reply_header_authorwrote,
                                    nsString& reply_header_ondateauthorwrote,
                                    nsString& reply_header_authorwroteondate,
@@ -377,16 +378,34 @@ nsresult nsMsgCompose::ResetUrisForEmbed
         nsCOMPtr<nsIDOMHTMLImageElement> image = do_QueryInterface(domElement);
         if (!image)
           continue;
         nsCString partNum;
         mMsgSend->GetPartForDomIndex(i, partNum);
         // do we care about anything besides images?
         nsAutoString objURL;
         image->GetSrc(objURL);
+
+        // First we need to make sure that the URL is associated with a message
+        // protocol so we don't accidentally manipulate a URL like:
+        // http://www.site.com/retrieve.html?C=image.jpg.
+        nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
+        NS_ENSURE_SUCCESS(rv, rv);
+        nsAutoCString scheme;
+        ioService->ExtractScheme(NS_ConvertUTF16toUTF8(objURL), scheme);
+
+        // Detect message protocols where attachments can occur.
+        nsCOMPtr<nsIProtocolHandler> handler;
+        ioService->GetProtocolHandler(scheme.get(), getter_AddRefs(handler));
+        if (!handler)
+          continue;
+        nsCOMPtr<nsIMsgMessageFetchPartService> mailHandler = do_QueryInterface(handler);
+        if (!mailHandler)
+          continue;
+
         // the objURL is the full path to the embedded content. We need
         // to update it with uri for the folder we just saved to, and the new
         // msg key.
         int32_t restOfUrlIndex = objURL.Find("?number=");
         if (restOfUrlIndex == kNotFound)
           restOfUrlIndex = objURL.FindChar('?');
         else
           restOfUrlIndex = objURL.FindChar('&', restOfUrlIndex);