Fix for bug 90728. Replace mailto parameter force-plain-text by html-body. Also, when a mailto url contains an html body, we run the body into the HTML sanitizer to prevent security breach. R=varada, SR=sspitzer
git-svn-id: svn://10.0.0.236/trunk@127797 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -101,6 +101,6 @@ interface nsIMailtoUrl : nsISupports {
|
||||
out string aFromPart, out string aFollowUpToPart, out string aOrganizationPart,
|
||||
out string aReplyToPart, out string aSubjectPart, out string aBodyPart, out string aHtmlPart,
|
||||
out string aReferencePart, out string aAttachmentPart, out string aPriorityPart,
|
||||
out string aNewsgroupPart, out string aNewsHostPart, out boolean aforcePlainText);
|
||||
out string aNewsgroupPart, out string aNewsHostPart, out boolean aHTMLBody);
|
||||
|
||||
};
|
||||
|
||||
@@ -85,8 +85,18 @@
|
||||
#include "nsMsgUtils.h"
|
||||
#endif
|
||||
|
||||
// <for functions="HTMLSantinize">
|
||||
#include "nsIParser.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsIContentSink.h"
|
||||
#include "mozISanitizingSerializer.h"
|
||||
|
||||
static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
|
||||
static NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
|
||||
// </for>
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool _just_to_be_sure_we_create_only_on_compose_service_ = PR_FALSE;
|
||||
static PRBool _just_to_be_sure_we_create_only_one_compose_service_ = PR_FALSE;
|
||||
#endif
|
||||
|
||||
#define DEFAULT_CHROME "chrome://messenger/content/messengercompose/messengercompose.xul"
|
||||
@@ -122,8 +132,8 @@ static PRUint32 GetMessageSizeFromURI(const char * originalMsgURI)
|
||||
nsMsgComposeService::nsMsgComposeService()
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
NS_ASSERTION(!_just_to_be_sure_we_create_only_on_compose_service_, "You cannot create several message compose service!");
|
||||
_just_to_be_sure_we_create_only_on_compose_service_ = PR_TRUE;
|
||||
NS_ASSERTION(!_just_to_be_sure_we_create_only_one_compose_service_, "You cannot create several message compose service!");
|
||||
_just_to_be_sure_we_create_only_one_compose_service_ = PR_TRUE;
|
||||
#endif
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
@@ -156,8 +166,8 @@ nsMsgComposeService::~nsMsgComposeService()
|
||||
nsresult nsMsgComposeService::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (!prefs)
|
||||
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (!prefService)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Register observers
|
||||
@@ -171,11 +181,11 @@ nsresult nsMsgComposeService::Init()
|
||||
}
|
||||
|
||||
// Register some pref observer
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
||||
nsCOMPtr<nsIPrefBranch> prefs;
|
||||
rv = prefService->GetBranch(nsnull, getter_AddRefs(prefs));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranchInternal> pbi = do_QueryInterface(prefBranch, &rv);
|
||||
nsCOMPtr<nsIPrefBranchInternal> pbi = do_QueryInterface(prefs, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = pbi->AddObserver(PREF_MAIL_COMPOSE_MAXRECYCLEDWINDOWS, this, PR_TRUE);
|
||||
}
|
||||
@@ -199,8 +209,12 @@ void nsMsgComposeService::Reset()
|
||||
mMaxRecycledWindows = 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (!prefs)
|
||||
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (!prefService)
|
||||
return;
|
||||
nsCOMPtr<nsIPrefBranch> prefs;
|
||||
rv = prefService->GetBranch(nsnull, getter_AddRefs(prefs));
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
|
||||
rv = prefs->GetIntPref(PREF_MAIL_COMPOSE_MAXRECYCLEDWINDOWS, &mMaxRecycledWindows);
|
||||
@@ -482,7 +496,7 @@ NS_IMETHODIMP nsMsgComposeService::OpenComposeWindowWithURI(const char * aMsgCom
|
||||
rv = aURI->QueryInterface(NS_GET_IID(nsIMailtoUrl), getter_AddRefs(aMailtoUrl));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRBool aPlainText = PR_FALSE;
|
||||
PRBool aHTMLBody = PR_FALSE;
|
||||
nsXPIDLCString aToPart;
|
||||
nsXPIDLCString aCcPart;
|
||||
nsXPIDLCString aBccPart;
|
||||
@@ -497,11 +511,52 @@ NS_IMETHODIMP nsMsgComposeService::OpenComposeWindowWithURI(const char * aMsgCom
|
||||
getter_Copies(aBodyPart), nsnull /* html part */,
|
||||
nsnull /* a ref part */, nsnull /* attachment part */,
|
||||
nsnull /* priority */, getter_Copies(aNewsgroup), nsnull /* host */,
|
||||
&aPlainText);
|
||||
&aHTMLBody);
|
||||
|
||||
MSG_ComposeFormat format = nsIMsgCompFormat::Default;
|
||||
if (aPlainText)
|
||||
format = nsIMsgCompFormat::PlainText;
|
||||
nsString rawBody = NS_ConvertUTF8toUCS2(aBodyPart);
|
||||
nsString sanitizedBody;
|
||||
|
||||
MSG_ComposeFormat format = nsIMsgCompFormat::PlainText;
|
||||
if (aHTMLBody)
|
||||
{
|
||||
//For security reason, we must sanitize the message body before accepting any html...
|
||||
|
||||
// Create a parser
|
||||
nsCOMPtr<nsIParser> parser = do_CreateInstance(kParserCID);
|
||||
|
||||
// Create the appropriate output sink
|
||||
nsCOMPtr<nsIContentSink> sink = do_CreateInstance(MOZ_SANITIZINGHTMLSERIALIZER_CONTRACTID);
|
||||
|
||||
nsXPIDLCString allowedTags;
|
||||
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefService)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefs;
|
||||
rv = prefService->GetBranch(MAILNEWS_ROOT_PREF, getter_AddRefs(prefs));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
prefs->GetCharPref("display.html_sanitizer.allowed_tags", getter_Copies(allowedTags));
|
||||
}
|
||||
|
||||
if (parser && sink)
|
||||
{
|
||||
nsCOMPtr<mozISanitizingHTMLSerializer> sanSink(do_QueryInterface(sink));
|
||||
if (sanSink)
|
||||
{
|
||||
sanSink->Initialize(&sanitizedBody, 0, NS_ConvertASCIItoUCS2(allowedTags.get()));
|
||||
|
||||
parser->SetContentSink(sink);
|
||||
nsCOMPtr<nsIDTD> dtd = do_CreateInstance(kNavDTDCID);
|
||||
if (dtd)
|
||||
{
|
||||
parser->RegisterDTD(dtd);
|
||||
|
||||
rv = parser->Parse(rawBody, 0, NS_LITERAL_CSTRING("text/html"), PR_FALSE, PR_TRUE);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
format = nsIMsgCompFormat::HTML;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMsgComposeParams> pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv) && pMsgComposeParams)
|
||||
@@ -519,7 +574,7 @@ NS_IMETHODIMP nsMsgComposeService::OpenComposeWindowWithURI(const char * aMsgCom
|
||||
pMsgCompFields->SetBcc(NS_ConvertUTF8toUCS2(aBccPart).get());
|
||||
pMsgCompFields->SetNewsgroups(aNewsgroup);
|
||||
pMsgCompFields->SetSubject(NS_ConvertUTF8toUCS2(aSubjectPart).get());
|
||||
pMsgCompFields->SetBody(NS_ConvertUTF8toUCS2(aBodyPart).get());
|
||||
pMsgCompFields->SetBody(format == nsIMsgCompFormat::HTML ? sanitizedBody.get() : rawBody.get());
|
||||
|
||||
pMsgComposeParams->SetComposeFields(pMsgCompFields);
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ static NS_DEFINE_CID(kCMimeConverterCID, NS_MIME_CONVERTER_CID);
|
||||
nsMailtoUrl::nsMailtoUrl()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
m_forcePlainText = PR_FALSE;
|
||||
m_htmlBody = PR_FALSE;
|
||||
nsComponentManager::CreateInstance(kSimpleURICID, nsnull,
|
||||
NS_GET_IID(nsIURI),
|
||||
(void **) getter_AddRefs(m_baseURL));
|
||||
@@ -140,12 +140,12 @@ nsresult nsMailtoUrl::ParseMailtoUrl(char * searchPart)
|
||||
m_followUpToPart = value;
|
||||
else if (!nsCRT::strcasecmp (token, "from"))
|
||||
m_fromPart = value;
|
||||
else if (!nsCRT::strcasecmp (token, "force-plain-text"))
|
||||
m_forcePlainText = PR_TRUE;
|
||||
break;
|
||||
case 'H':
|
||||
if (!nsCRT::strcasecmp(token, "html-part"))
|
||||
m_htmlPart = value;
|
||||
else if (!nsCRT::strcasecmp (token, "html-body"))
|
||||
m_htmlBody = PR_TRUE;
|
||||
break;
|
||||
case 'N':
|
||||
if (!nsCRT::strcasecmp (token, "newsgroups"))
|
||||
@@ -318,7 +318,7 @@ NS_IMETHODIMP nsMailtoUrl::GetMessageContents(char ** aToPart, char ** aCcPart,
|
||||
char ** aFromPart, char ** aFollowUpToPart, char ** aOrganizationPart,
|
||||
char ** aReplyToPart, char ** aSubjectPart, char ** aBodyPart, char ** aHtmlPart,
|
||||
char ** aReferencePart, char ** aAttachmentPart, char ** aPriorityPart,
|
||||
char ** aNewsgroupPart, char ** aNewsHostPart, PRBool * aForcePlainText)
|
||||
char ** aNewsgroupPart, char ** aNewsHostPart, PRBool * aHTMLBody)
|
||||
{
|
||||
if (aToPart)
|
||||
*aToPart = ToNewCString(m_toPart);
|
||||
@@ -350,8 +350,8 @@ NS_IMETHODIMP nsMailtoUrl::GetMessageContents(char ** aToPart, char ** aCcPart,
|
||||
*aNewsgroupPart = ToNewCString(m_newsgroupPart);
|
||||
if (aNewsHostPart)
|
||||
*aNewsHostPart = ToNewCString(m_newsHostPart);
|
||||
if (aForcePlainText)
|
||||
*aForcePlainText = m_forcePlainText;
|
||||
if (aHTMLBody)
|
||||
*aHTMLBody = m_htmlBody;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ protected:
|
||||
nsCString m_replyToPart;
|
||||
nsCString m_priorityPart;
|
||||
|
||||
PRBool m_forcePlainText;
|
||||
PRBool m_htmlBody;
|
||||
};
|
||||
|
||||
class nsSmtpUrl : public nsISmtpUrl, public nsMsgMailNewsUrl
|
||||
|
||||
Reference in New Issue
Block a user