Closed Bug 1151366 Opened 10 years ago Closed 8 years ago

File disclosure via covertly imposed attachments in HTML emails

Categories

(MailNews Core :: Composition, defect)

defect
Not set
normal

Tracking

(thunderbird_esr45 wontfix, thunderbird52+ fixed, thunderbird53 fixed)

RESOLVED FIXED
Thunderbird 53.0
Tracking Status
thunderbird_esr45 --- wontfix
thunderbird52 + fixed
thunderbird53 --- fixed

People

(Reporter: arminius, Assigned: mkmelin)

References

Details

(5 keywords, Whiteboard: stealing local files at known paths)

Attachments

(5 files, 54 obsolete files)

(deleted), text/html
Details
(deleted), patch
ehsan.akhgari
: review+
Details | Diff | Splinter Review
(deleted), text/html
Details
(deleted), patch
jorgk-bmo
: review+
Details | Diff | Splinter Review
(deleted), patch
mkmelin
: review+
Details | Diff | Splinter Review
Users can be deceived into sending involuntary attachments via email, thus disclosing private information / local files. Thunderbird allows to embed images inline in HTML emails, including local resources (specified with a file:// scheme). All embedded objects that are not tagged as moz-do-not-send="true" will automatically be attached to the message before dispatching. So, if this tag is contained in a mail body, the local file will be sent as well: <img src="file:///etc/hosts" moz-do-not-send="false"> For security, cited emails have to pass TagEmbeddedObjects(), which sanitizes all untrusted HTML elements (sets moz-do-not-send to true) before including the quoted text as part of a reply or forwarded message: https://dxr.mozilla.org/comm-central/source/mailnews/compose/src/nsMsgCompose.cpp#444 Otherwise, an attacker could hide a prepared HTML tag in an email and wait for a victim to reply. The victim would quote the attacker's message including the directive to attach a specific file, making him unwittingly transmit a local resource. The measure leaves some attack vectors open, though. - Emails in the inbox can be re-sent as original messages via "Context Menu > Edit As New Message" (or CTRL+E). - HTML text can be copy-pasted into an email. In both cases, the content would not be sanitized and attachment directives are preserved. If I was to reply to someone with a last name as odd as mine, I would likely copy-paste it out of the mail, rather than risking to misspell the name. Any HTML elements hidden in between the letters would therefore end up in my own email and potentially lead to a local file disclosure. Proof of concept via the HTML attachment: - Open the page and copy the specified string. - Compose a new mail in Thunderbird and paste the string into the body. - Send it to someone. - View the raw source of the transmitted mail (CTRL+U). The /etc/hosts file should have been attached silently.
Confirming. Note: requires the use of HTML mail composition. This is not a mitigation because that's the default, but may trip up devs and testers who are more likely to prefer plain text than the general public. Going with sec-moderate as a first guess because the user interaction required will limit the spread of any attack, but it's a completely plausible attack and results in stealing local data so the impact is similar to a sec-high. It's a muddy line depending on how gullible you think the average Thunderbird user is, but there's no question that this attack can send back sensitive data.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Whiteboard: stealing local files at known paths
I'd like to add that instead of specific files you could just target emails, which might be a more realistic use case and pretty reliable, although it's brute-force. Per https://tools.ietf.org/html/rfc5092 you can construct something like this: <img src="imap://imap.example.com:993/fetch>UID>/INBOX>23" moz-do-not-send="false"> The folder structure should be easy to guess for most mail providers. If you cascade multiple tags with consecutive IDs, chances are that you get an entire mailbox back.
(In reply to Armin Razmdjou from comment #3) > I'd like to add that instead of specific files you could just target emails, > which might be a more realistic use case and pretty reliable, although it's > brute-force. Per https://tools.ietf.org/html/rfc5092 you can construct > something like this: > <img src="imap://imap.example.com:993/fetch>UID>/INBOX>23" > moz-do-not-send="false"> > > The folder structure should be easy to guess for most mail providers. If you > cascade multiple tags with consecutive IDs, chances are that you get an > entire mailbox back. You'd need the username, SSL or STARTTLS, and the start UID to be included in URLs to guess. SMTP servers also reject mailing messages larger than a few dozen megabytes, which corresponds to only a few hundred messages. I don't know our copy-paste code, but probably the easiest way to block this is to sanitize URLs on copy-paste. If that doesn't work, preventing uploads of non-image data is probably the best bet, and dropping support for <link href="" rel="stylesheet"> (or perhaps filtering that out for valid CSS as well, but that's harder). Can someone who understands editor and/or copy-paste better evaluate the first option for feasibility? I'm only good at the backend side of this.
Flags: needinfo?(neil)
(In reply to Joshua Cranmer [:jcranmer] from comment #4) > You'd need the username, SSL or STARTTLS, and the start UID to be included > in URLs to guess. SMTP servers also reject mailing messages larger than a > few dozen megabytes, which corresponds to only a few hundred messages. I don't - my Thunderbird implies these details by default. So this is the exact payload I just successfully used on my Gmail account: imap://imap.googlemail.com:993/fetch>UID>/[Gmail]/All%20Mail>7 Also, a few hundred mails might be enough to pick up something interesting.
(In reply to Joshua Cranmer from comment #4) > I don't know our copy-paste code, but probably the easiest way to block this > is to sanitize URLs on copy-paste. > > Can someone who understands editor and/or copy-paste better evaluate the > first option for feasibility? I thought we already sanitised URLs on copy-paste, but Ehsan would know more.
Flags: needinfo?(neil) → needinfo?(ehsan)
(In reply to neil@parkwaycc.co.uk from comment #6) > (In reply to Joshua Cranmer from comment #4) > > I don't know our copy-paste code, but probably the easiest way to block this > > is to sanitize URLs on copy-paste. > > > > Can someone who understands editor and/or copy-paste better evaluate the > > first option for feasibility? > > I thought we already sanitised URLs on copy-paste, but Ehsan would know more. We do. But I'm not sure I understand what this bug report has to do with copy and paste? Isn't this about replying to an email without pasting anything?
Flags: needinfo?(ehsan) → needinfo?(Pidgeot18)
(In reply to :Ehsan Akhgari (not reading bugmail, needinfo? me!) from comment #7) > We do. But I'm not sure I understand what this bug report has to do with > copy and paste? Isn't this about replying to an email without pasting > anything? (In reply to Armin Razmdjou from comment #0) > Proof of concept via the HTML attachment: > - Open the page and copy the specified string. > - Compose a new mail in Thunderbird and paste the string into the body. > - Send it to someone. > - View the raw source of the transmitted mail (CTRL+U). The /etc/hosts file > should have been attached silently. ^ That's what I was basing the copy-paste issue off of.
Flags: needinfo?(Pidgeot18)
Oh, OK, sorry I missed that. The sanitization upon paste happens inside nsHTMLEditor::ParseFragment. You may want to see why that doesn't work. For example, make sure the caller doesn't set aTrustedInput to true.
Flags: sec-bounty?
Flags: sec-bounty? → sec-bounty+
Joshua or Neil, would either of you be able to try to make progress with this bug?
Group: core-security → mail-core-security
Did some investigation - we set nsIDocShell::APP_TYPE_EDITOR for the compose window => nsPlaintextEditor::IsSafeToInsertData will say it's safe -> no sanitation on paste - even with sanitation, a moz-do-not-send="false" is NOT sanitized - moz-do-not-send doesn't really matter (the test case img without it works too) - fwd/reply seem not affected Possible solution - on paste (even for app=mail), set moz-do-not-send=true for file: urls Comments?
Attached patch bug1151366_sec_file_attach.m-c.patch (obsolete) (deleted) — Splinter Review
Something like this? Don't make the paste trusted just because app=editor. Drop src="file://....." on paste
Assignee: nobody → mkmelin+mozilla
Status: NEW → ASSIGNED
Attachment #8725410 - Flags: feedback?(ehsan)
Comment on attachment 8725410 [details] [diff] [review] bug1151366_sec_file_attach.m-c.patch Review of attachment 8725410 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/base/nsTreeSanitizer.cpp @@ +1151,5 @@ > bool aAllowXLink, > bool aAllowStyle, > bool aAllowDangerousSrc) > { > +printf("xxxmagnus nsTreeSanitizer::SanitizeAttributes aAllowDangerousSrc=%d\n", aAllowDangerousSrc); Debugging left-overs? (several more below.) @@ +1446,5 @@ > sAttributesHTML, > (nsIAtom***)kURLAttributesHTML, > false, mAllowStyles, > (nsGkAtoms::img == localName) && > + !mCidEmbedsOnly && !mDropLocalLinks); I don't understand why this only disallows local links. Plus, I don't think that's a good solution in the first place, since it seems like Armin pointed out that the same issue exists with imap links. Furthermore, isn't http://myintranet/secret-file going to have the same issue? ::: editor/libeditor/nsHTMLDataTransfer.cpp @@ +2126,5 @@ > DocumentFragment** aFragment, > bool aTrustedInput) > { > +printf("xxxmagnus nsHTMLEditor::ParseFragment aFragStr=%s, aTrustedInput=%d\n", NS_ConvertUTF16toUTF8(aFragStr).get(), aTrustedInput); > + Looks like debugging left-overs? @@ +2142,5 @@ > if (!aTrustedInput) { > + uint32_t flags = aContextLocalName ? nsIParserUtils::SanitizerAllowStyle : > + nsIParserUtils::SanitizerAllowComments; > + flags |= nsIParserUtils::SanitizerDropLocalLinks; > + nsTreeSanitizer sanitizer(flags); You're changing the behavior for Firefox here, which is not OK. ::: editor/libeditor/nsPlaintextDataTransfer.cpp @@ -440,5 @@ > dsti->GetRootTreeItem(getter_AddRefs(root)); > nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(root); > - uint32_t appType; > - if (docShell && NS_SUCCEEDED(docShell->GetAppType(&appType))) > - isSafe = appType == nsIDocShell::APP_TYPE_EDITOR; This will probably break BlueGriffon and the SeaMonkey composer. I'm not 100% sure how they would rely on this.
Attachment #8725410 - Flags: feedback?(ehsan) → feedback-
Attached patch bug1151366_sec_file_attach.m-c.patch (obsolete) (deleted) — Splinter Review
Went back to the drawing board a bit with this. 1. don't make app==editor automatically safe --> sanitize will be run 2. no longer add the moz-do-not-send attribute to the list of allowed attributes --> on paste that attribute will be nuked Next up: comm-central part of this.
Attachment #8725410 - Attachment is obsolete: true
Attachment #8730367 - Flags: review?(ehsan)
Reverse the logic for attaching. Require that we have moz-do-not-send="false" to send. The main problem was that we check for the moz-do-not-send attribute but in case there was NO such attribute we'd still accept to send. Also handle for the case of empty src properly. (On trunk you get an error dialog, and after clicking ok you still get to send...) I realize this will probably break someone's current usege, but I think the logic of just attaching without anyone explicitly asked for it is just so dangerous.
Attachment #8730374 - Flags: review?(Pidgeot18)
Comment on attachment 8730367 [details] [diff] [review] bug1151366_sec_file_attach.m-c.patch Review of attachment 8730367 [details] [diff] [review]: ----------------------------------------------------------------- ::: editor/libeditor/nsPlaintextDataTransfer.cpp @@ -440,5 @@ > dsti->GetRootTreeItem(getter_AddRefs(root)); > nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(root); > - uint32_t appType; > - if (docShell && NS_SUCCEEDED(docShell->GetAppType(&appType))) > - isSafe = appType == nsIDocShell::APP_TYPE_EDITOR; Can you please explain what this part of the patch is trying to achieve? Isn't isSafe just set to false here for Thunderbird?
No, we set the appType to editor for composition here: http://mxr.mozilla.org/comm-central/source/mailnews/compose/src/nsMsgCompose.cpp#1005 This is so that file:// url images would be able to load during composition (and possibly something else). Obviously we don't want file urls to be able to load in *received* mails.
Comment on attachment 8730367 [details] [diff] [review] bug1151366_sec_file_attach.m-c.patch Review of attachment 8730367 [details] [diff] [review]: ----------------------------------------------------------------- I see, makes sense. I'm till slightly worried that this may affect BlueGriffon, not sure how active Daniel is these days. I'll flag him, but I think you should be good to land this in a few days if he doesn't respond.
Attachment #8730367 - Flags: review?(ehsan)
Attachment #8730367 - Flags: review?(daniel)
Attachment #8730367 - Flags: review+
(In reply to :Ehsan Akhgari from comment #18) > Comment on attachment 8730367 [details] [diff] [review] > bug1151366_sec_file_attach.m-c.patch > > Review of attachment 8730367 [details] [diff] [review]: > ----------------------------------------------------------------- > > I see, makes sense. I'm till slightly worried that this may affect > BlueGriffon, not sure how active Daniel is these days. I'll flag him, but I > think you should be good to land this in a few days if he doesn't respond. Discovering this only now. Looking.
Comment on attachment 8730367 [details] [diff] [review] bug1151366_sec_file_attach.m-c.patch I am not fundamentally against this patch (I can nuke it in BlueGriffon's tree) but I still find a few things a bit strange, sorry. First, nsIDocShell has a special constant for email clients, why is msgcompose using APP_TYPE_EDITOR and not APP_TYPE_MAIL that would allow a clean switch in nsPlaintextEditor::IsSafeToInsertData instead of that deletion that could have side-effects on pure editors having no restrictions on local files? Second, with the three lines deleted, isSafe is always false before the test |if (!isSafe && aSourceDoc)| so you can clean that up. Purely cosmetic but still. Third, I am not sure I like having pasting in a pure editor like BG based on Subsumes(). This feels wrong. I think I would try to use APP_TYPE_MAIL in msgcompose and fix the limited number of places where APP_TYPE_EDITOR is expected for TB instead. In the case of nsPlaintextDataTransfer.cpp, I would then keep the deleted lines but add a case for APP_TYPE_MAIL.
Attachment #8730367 - Flags: review?(daniel) → review-
Or maybe a fourth constant in nsIDocShell meaning an editor inside an email client. We're unable to make the difference between that and a pure editor for the time being.
Ok, so only remove the moz-do-not-send attr from whitelist, so it gets sanitized away on paste.
Attachment #8736919 - Flags: review?(ehsan)
Attachment #8730367 - Attachment is obsolete: true
For thunderbird, don't pretend we're an editor anymore. To be able to view file:// images during composition instead convert them to data uris directly. In addition to the earlier plan (comment 15). Joshua, are you able to review this anytime soon? If not, maybe rkent?
Attachment #8730374 - Attachment is obsolete: true
Attachment #8730374 - Flags: review?(Pidgeot18)
Attachment #8736921 - Flags: review?(rkent)
Attachment #8736921 - Flags: review?(Pidgeot18)
I'd be willing to try to review it if you cannot get anyone else, but I would need to do a develop of background understanding before I could. How about jorgk? He's much closer to the editor and composer than I am these days.
Comment on attachment 8736921 [details] [diff] [review] bug1151366_sec_file_attach.patch (comm-central part) Review of attachment 8736921 [details] [diff] [review]: ----------------------------------------------------------------- I've looked at it since I was threatened to review this. I see a lot of comment changes and minor tweaks and a couple of new functions. Let me ask some questions and then the review will be easier. Kent sometimes reviews his own patches to give further explanation. ::: mailnews/compose/content/mailComposeEditorOverlay.xul @@ +51,2 @@ > > + function OnAcceptOverlay() As far as I can see this is the only "real" change. Can you explain what's happening here. @@ +123,3 @@ > } > > + function GenerateDataURI(url) { Straight forward new function used above. ::: mailnews/compose/src/nsMsgCompose.cpp @@ -989,5 @@ > if (NS_FAILED(rv)) return rv; > > m_baseWindow = do_QueryInterface(treeOwner); > - > - window->GetDocShell()->SetAppType(nsIDocShell::APP_TYPE_EDITOR); Mentioned in comment #11. Editor app type has its consequences. ::: mailnews/compose/src/nsMsgSend.cpp @@ +1457,5 @@ > if (anchor && !forceToBeAttached) > return NS_OK; > } > > + *acceptObject = forceToBeAttached; Here we have the policy change mentioned in comment #15, right? Require that we have moz-do-not-send="false" to send.
(In reply to Jorg K (GMT+2) from comment #25) > ::: mailnews/compose/content/mailComposeEditorOverlay.xul > @@ +51,2 @@ > > > > + function OnAcceptOverlay() > > As far as I can see this is the only "real" change. Can you explain what's > happening here. Sure. When the user clicks ok in the image insert dialog, if a file was selected we convert that to a data: uri instead. Later on send, that data uri is resolved and sent as a cid (like before) if "attach the source of this" is checked. > > + *acceptObject = forceToBeAttached; > > Here we have the policy change mentioned in comment #15, right? Require that > we have moz-do-not-send="false" to send. Yes. I think the policy should be to include only when explicitly asked. Otherwise it's quite a chase to be able to catch all cases e.g. a simple paste where the source is file:// something (and moz-do-not-send is not set at all). And to handle that in a good way if encountered. Some people are likely to use pics in their html signature, they will have to add the moz-do-not-send="false" orstart using a data uri instead.
Attachment #8736919 - Flags: review?(ehsan) → review+
Keywords: leave-open
OS: Linux → All
Hardware: x86_64 → All
Attachment #8736921 - Flags: review?(rkent)
Attachment #8736921 - Flags: review?(mozilla)
Attachment #8736921 - Flags: review?(Pidgeot18)
I think I can't do a qualified review since I don't have enough background knowledge. For example, I don't understand why the nsGkAtoms::mozdonotsend was removed from kAttributesHTML[] and what the sanitise is about. I also don't understand how the image was inserted before, that it, before this bit if (/^file:/i.test(gMsgCompInputElement.value.trim())) { var dataURI = GenerateDataURI(gMsgCompInputElement.value.trim()); gMsgCompInputElement.value = dataURI; gMsgCompAttachSourceElement.checked = true; was added. I did apply the patch to play around with. I noticed two problems: For I brief moment I see the base64 encoded data flash up on the screen in the compose window. That may be due to a slower debug build, but it's noticeable and will confuse the user. The second problem is more severe. I've added a signature that contains an image: <img moz-do-not-send="false" src="file:///D:/Desktop/Bugzilla%20down.png"> That image doesn't show in a new message. It shows when I look at the image and go "OK" on the dialog.
(In reply to Jorg K (GMT+2) from comment #28) > For example, I don't understand why the nsGkAtoms::mozdonotsend was removed > from kAttributesHTML[] and what the sanitise is about. When pasting html don't want someone to be able to hide moz-do-not-send="true" in the source, since that would lead to that file getting sent. Sanitation will now make sure the moz-do-not-send attribute is removed if someone tried to do that. > I also don't understand how the image was inserted before, that it, before > this bit > if (/^file:/i.test(gMsgCompInputElement.value.trim())) { > var dataURI = GenerateDataURI(gMsgCompInputElement.value.trim()); > gMsgCompInputElement.value = dataURI; > gMsgCompAttachSourceElement.checked = true; > was added. It just used to set the img src="file://something" and since editors allow linking to file the image was shown. On send we included anything that *did not* have the moz-do-not-send="false" set. > I did apply the patch to play around with. I noticed two problems: > > For I brief moment I see the base64 encoded data flash up on the screen in > the compose window. That may be due to a slower debug build, but it's > noticeable and will confuse the user. Haven't seen it. > The second problem is more severe. I've added a signature that contains an > image: > <img moz-do-not-send="false" src="file:///D:/Desktop/Bugzilla%20down.png"> > That image doesn't show in a new message. It shows when I look at the image > and go "OK" on the dialog. Hmm, yes (though it will get sent). Our options are not to support it, or have some migration/conversion occur.
Thanks for the clarifications. So the M-C change assures that the moz-do-not-send is stripped upon paste. BTW, you meant to say «hide moz-do-not-send="false"», right, since that's the dangerous case? As for the base64 flashing over the screen, you can believe me, or I can attach a video. Maybe not an issue on a optimised compile. As for the image in the signature, I don't understand your answer. I tried all combinations of <img src="file:///D:/Desktop/Bugzilla%20down.png"> <img moz-do-not-send="true" src="file:///D:/Desktop/Bugzilla%20down.png"> <img moz-do-not-send="false" src="file:///D:/Desktop/Bugzilla%20down.png"> in the HTML box and the picture never shows in the new message. I also tried D:\Desktop\Bugzilla down.png in the file box and that also doesn't work. Both options work on Daily. Surely hell will break lose if suddenly showing pictures in signatures stops working. If I understand the solution correctly, the compose window stops being an editor: - window->GetDocShell()->SetAppType(nsIDocShell::APP_TYPE_EDITOR); so the pictures are not pulled in automatically (quote: editors allow linking to file). They only get attached when added manually now when going "OK" on the properties dialogue. I undid that changed and now the images in the signature show as before. I wonder which other ramifications not being an editor will have. Note that David suggested using APP_TYPE_MAIL in comment #20. I'll clear the r? since I don't think it's ready.
Attachment #8736921 - Flags: review?(mozilla)
(In reply to Jorg K (GMT+2) from comment #30) > I wonder which other ramifications not being an editor will have. Note that > David suggested using APP_TYPE_MAIL in comment #20. Should be safe, it's only special cased for this purpose. >http://mxr.mozilla.org/comm-central/search?string=APP_TYPE_EDITOR&find=&findi=&filter=^[^\0]*%24&hitlimit=&tree=comm-central> I didn't want to add another type as whole concept of linking to local files will be troublesome. E.g. likely not possible with any other editor if that ever changes.
Attached patch bug1151366_sec_file_attach.patch (obsolete) (deleted) — Splinter Review
Now images are showing in signatures. We replace them too with data uris (until send).
Attachment #8736921 - Attachment is obsolete: true
Attachment #8740543 - Flags: review?(mozilla)
Attachment #8736919 - Attachment description: bug1151366_sec_file_attach.m-c.patch → [checked in] bug1151366_sec_file_attach.m-c.patch
Comment on attachment 8740543 [details] [diff] [review] bug1151366_sec_file_attach.patch Review of attachment 8740543 [details] [diff] [review]: ----------------------------------------------------------------- I'll look at it in more detail tomorrow. Just one question for now. ::: mailnews/compose/src/nsMsgCompose.cpp @@ +4170,5 @@ > > nsAutoCString readStr(readBuf, (int32_t) fileSize); > PR_FREEIF(readBuf); > > + // XXX: ^^^ could really use nsContentUtils::SlurpFileToString instead! What is this comment telling us?
Just that it looks to me we could use that function instead of using our reading the file ourselves, removing 20 or so lines of code. (Not really relevant to this bug, just noted it as it was close to code I was changing.)
Comment on attachment 8740543 [details] [diff] [review] bug1151366_sec_file_attach.patch Sorry, I have to give an r- here. Of the three "image in signature" cases, only one works. I'm also not convinced by the over-all concept. I'll explain that below. There are three ways to include an image in a signature: 1) Use HTML in the signature: My test case: <img moz-do-not-send='false' src="file://D:/Desktop/Bugzilla-down.png"> Not working: Picture is not visible when you first open a new composition. That's a consequence of not being an APP_TYPE_EDITOR any more. Image properties file://D:/Desktop/Bugzilla-down.png as expected. After sending it's fine. 2) Attach signature from file directly pointing to the image file: My test case: D:\Desktop\Bugzilla-down.png Not working: Picture is not visible when you first open a new composition. If you go to image properties you get the data URI: data:image/png;base64,iVBORw0KGgoAA ... ErkJggg== moz-do-not-send='false' Is the moz-do-not-send='false' correct in the data there? When sending this message I only see a broken image in the sent message. The sent message has: src="data:image/png;base64,iVBORw0KGgoAA ... ErkJggg==%20moz-do-not-send=%27false%27" That doesn't look right. 3) Attach signature from file pointing to a HTML file with a reference to the image. My test case: D:\Desktop\Bugzilla-down.html with this content: <img src="file://D:/Desktop/Bugzilla-down.png"> That works although you get the ugly data URI data:image/png;base64,iVBORw etc. in the image properties. The sent message has: <img moz-do-not-send="false" src="cid:part1.EDAB4045.F7CEF57B@jorgk.com"> I must say that I am not thrilled at all about the data URIs in the image properties. That certainly is a confusing change of the behaviour. I'm also not convinced that all this hassle is warranted and that withdrawing APP_TYPE_EDITOR from our e-mail composer is the right thing to do. What problem are we trying to solve here? I had to read comment #0 to get a better understanding. One problem is *pasting* content from an attacker's e-mail. If I understand it correctly, that is now covered by the M-C change, right? The exact effect of removing nsGkAtoms::mozdonotsend from kAttributesHTML[] is that the attribute is dropped, right? And then we have the "policy change", that no value means: Do not send. I'm fine with that. That leaves the problem of "Edit as new message". Now, this is already a mad thing to do. Why would I edit someone else's e-mail as new as my own message? Anyway, for this rare and crazy case, why don't we sanitize the message instead of jumping through all the hoops you're attempting here? Wouldn't it just be a case of calling TagEmbeddedObjects() on the "reused" message as we do for quotes? That should sanitise it the same way quotes are sanitised. What am I missing? Furthermore, I went through the trouble of looking at this: > > I wonder which other ramifications not being an editor will have. Note that > > David suggested using APP_TYPE_MAIL in comment #20. > Should be safe, it's only special cased for this purpose. > >http://mxr.mozilla.org/comm-central/ > search?string=APP_TYPE_EDITOR&find=&findi=&filter=^[^\0]*%24&hitlimit=&tree=c > omm-central> Easier here: https://dxr.mozilla.org/comm-central/search?q=APP_TYPE_EDITOR&redirect=false&case=false There are only two relevant cases: https://dxr.mozilla.org/comm-central/source/mozilla/dom/base/nsContentUtils.cpp#3011 That's where it says: // Editor apps get special treatment here, editors can load images from anywhere. So that's the behaviour you want to switch off. OK. But why don't we just allow the loading as long as the image is not sent? So in any part of the new message, that is obtained from the attacker's message via copy/paste or "edit as new", we simply strip or correct the moz-do-not-send attribute. What about the other one: https://dxr.mozilla.org/comm-central/source/mozilla/editor/libeditor/nsPlaintextDataTransfer.cpp#444 What are the consequences for not being an APP_TYPE_EDITOR any more? You mention some investigation in comment #11. Kent always mentions that he spends hours on reviews, so I'll just state that reviewing this is not easy and quite time consuming.
Attachment #8740543 - Flags: review?(mozilla) → review-
(In reply to Jorg K (GMT+2) from comment #36) > I must say that I am not thrilled at all about the data URIs in the image > properties. That certainly is a confusing change of the behaviour. Well mails are not really design documents, what matters is that the image is shown. > One problem is *pasting* content from an attacker's e-mail. If I understand > it correctly, that is now covered by the M-C change, right? The exact effect Partly. The checked in m-c change makes sanitation drop that element. But for sanitation to run we need to be APP_TYPE_MAIL. > What are the consequences for not being an APP_TYPE_EDITOR any more? Looks like none that really matter. > that reviewing this is not easy and quite time consuming. Welcome to the club ;)
Attached patch bug1151366_sec_file_attach.patch (obsolete) (deleted) — Splinter Review
The last patch had some bugs due to last minute reworks :( This works for all three cases. Also removing mail.compose.dont_attach_source_of_local_network_links since it doesn't make any sense anymore now that files are always data: instead.
Attachment #8740543 - Attachment is obsolete: true
Attachment #8741489 - Flags: review?(mozilla)
I'll repeat again that an important secondary goal for removing the file:// source handling is that it really locks down what we can use for editor. It will only be trouble for any future developments of the composition window.
Comment on attachment 8741489 [details] [diff] [review] bug1151366_sec_file_attach.patch I am really sorry, and I can see all the effort you put into converting file content into data URIs, but I am not convinced by this solution. I am opposed to stop being a APP_TYPE_EDITOR type application and do all the work ourselves. I appreciate that you want to become more independent of what the M-C editor does for us, and you know that I would be the first person to roll out the bug-ridden M-C editor and roll something else into its place. However, presently we do rely on the M-C editor and it makes no sense to do 80% of the work ourselves (jumping through hoops and making the user-interface worse by showing those lovely data URIs) and break the remaining 20%. Create yourself a webpage with this content: <html> <body> <img src="file://someimage.png"> </body> </html> Open that page in Firefox. Copy the image. Paste it into a Magnus-style composition window. It doesn't work. Just like the signatures didn't work. I suggest not to fix these last 20% I am currently aware of by attaching some listener to the document and converting any picture on the fly upon paste. Please tell me what is so wrong about this approach: 1) Continue being a APP_TYPE_EDITOR. 2) Make sure we sanitize quotes and any content from "edit as new" or forward. You said in comment #37: Sanitising only works for APP_TYPE_EDITOR. Why did you change M-C code if you want to stop using the feature (not that the M-C change hurts)? 3) Switch the default attachment action to "do not attach". I'm happy that people have to rework their signatures. We need to be careful in the paste case described above.
Attachment #8741489 - Flags: review?(mozilla)
(In reply to Jorg K (GMT+2) from comment #40) > Please tell me what is so wrong about this approach: > 1) Continue being a APP_TYPE_EDITOR. Not a big deal in it self. It's semantically wrong though and (as we see in this bug) gives you a big problem because it is special cased to say certain things are safe for editors, when in fact they are really not safe for mail. > 2) Make sure we sanitize quotes and any content from "edit as new" or > forward. > You said in comment #37: Sanitising only works for APP_TYPE_EDITOR. Why > did you change M-C code > if you want to stop using the feature (not that the M-C change hurts)? I don't expect us to stop using it anytime soon if ever. The change was only so people couldn't be tricked to paste <img moz-do-not-send="false" src="file:///" /> which would cause the file to be attached. That is, so that if we find a moz-do-not-send attribute on send, we can trust it. > 3) Switch the default attachment action to "do not attach". Yes that is what I've proposed too. The problem with what you propose above is this: yes, you'd get the image showing in the editor, but uselessly so since it wouldn't get *attached* so the recipient would still NOT see it. I've not tracked down how to fix your paste from file:// based web page (which would be very uncommon!) case but it's certainly possible to paste images as such from other software. I suppose it should just prefer the correct flavour if it finds a file url.
(In reply to Magnus Melin from comment #41) > Not a big deal in it self. It's semantically wrong though and (as we see in > this bug) gives you a big problem because it is special cased to say certain > things are safe for editors, when in fact they are really not safe for mail. Well, as we've seen, there are only two special cases for APP_TYPE_EDITOR in M-C: For loading images: https://dxr.mozilla.org/comm-central/source/mozilla/dom/base/nsContentUtils.cpp#3011 For other stuff, and I still don't understand what the ramifications are of switching this off. https://dxr.mozilla.org/comm-central/source/mozilla/editor/libeditor/nsPlaintextDataTransfer.cpp#444 nsPlaintextEditor::IsSafeToInsertData() is called a few times in "data transfer". It would be very handy to keep using the automatic image insertion. If the other stuff isn't desired, we'd have to be APP_TYPE_MAIL as previously suggested. > The change was only > so people couldn't be tricked to paste <img moz-do-not-send="false" > src="file:///" /> which would cause the file to be attached. That is, so > that if we find a moz-do-not-send attribute on send, we can trust it. Agreed. But we also need to sanitise "edit as new" and forwarded content. Also you said that the sanitise only works for APP_TYPE_MAIL (quote): "But for sanitation to run we need to be APP_TYPE_MAIL." I'm still confused: The main windows seems to be APP_TYPE_MAIL https://dxr.mozilla.org/comm-central/source/mail/base/content/mailWindow.js#108 but the compose window was APP_TYPE_EDITOR which your patch removes. > > 3) Switch the default attachment action to "do not attach". > Yes that is what I've proposed too. Of course. I didn't invent any of this ;-) > The problem with what you propose above is this: yes, you'd get the image > showing in the editor, but uselessly so since it wouldn't get *attached* so > the recipient would still NOT see it. Yes, I can see the dilemma, that's why I said above (quote): "We need to be careful in the paste case described above." We'd have to see how we would get image paste with "do not send" set to false, yet other paste actions should paste without that attribute, so it defaults to true. Maybe that's wishful thinking and not distinguishable.
OK, I've thought about it some more, here is my solution: 1) Continue being a APP_TYPE_EDITOR, or switch to APP_TYPE_MAIL, but let the M-C editor do the image handling. 2) Make sure we sanitize pasted content, quotes and any content from "edit as new" or forward. 3) Switch the default attachment action to "do not attach", so any content we see will not be attached unless the moz-do-not-send=false was explicitly set. 4) Signatures: I'm happy that people have to rework their signatures. Cases from comment #36: 1) Images via direct HTML: They need to add moz-do-not-send=false (or you can do it for them). 2) Images attached directly via "Attach signature from file": You add moz-do-not-send=false. 3) Images attached via HTML via "Attach signature from file": They need to add moz-do-not-send=false (or you can do it for them). In fact, you already visited all those spots to convert the image to data URI, so instead you can add the moz-do-not-send=false for file:// based pictures. 5) When pasting: Look at the content being pasted. If the content being pasted only contains one image and nothing else, set moz-do-not-send=false on that image. Advantage of this approach: We don't need to convert images to data URIs you introduced and the user sees the image name in the UI. Less code change. Yes, 5) is a little annoying to do, but in your approach you would have to do something similar to fix my "paste from file:// based web page". (I know it hurts to remove code you've already written, see bug 597369.)
Sorry, I don't like it. There are a lot of upsides in using my proposed approach, and no real upside with the other approach - besides less code change.
Attached patch bug1151366_paste_img.mc.patch (obsolete) (deleted) — Splinter Review
With this patch you can paste images from "Copy Image" even if they are file://. I'm just reordering the flavors so that if there's an image that would be preferred over the html transfer flavor.
Comment on attachment 8741489 [details] [diff] [review] bug1151366_sec_file_attach.patch Review of attachment 8741489 [details] [diff] [review]: ----------------------------------------------------------------- Could you have another look at this?
Attachment #8741489 - Flags: review?(mozilla)
Comment on attachment 8742488 [details] [diff] [review] bug1151366_paste_img.mc.patch I think this won't fly since you will also prefer bitmaps over http:// links. I don't think this will pass review in M-C (since it would change browser behaviour for no good reason). Let's see how your try turns out: https://treeherder.mozilla.org/#/jobs?repo=try&revision=b60f379a8533b339ce83b285616f3fe34befd2d4 One failure so far: bc7 424 INFO TEST-UNEXPECTED-FAIL | browser/base/content/test/general/browser_clipboard.js | Paste after copy image - "<i>Italic</i> <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAXZJREFUOE+1 == "<i>Italic</i> <img id=\"img\" tabindex=\"1\" src=\"http://example.org/browser/browser/base/content/test/general/moz.png\">Test - Looks like you managed to do what was intended, grab the data ;-)
Yes it's a slight change in behavior. Can't say if it will be accepted or not for sure, but drag'n'drop from desktop will also "paste" the image data like my patch, not the html with the src url. So it's consistent in that way, and the user did do "Copy Image" so it's not unreasonable imo. Then it's of course possible to just do the transfer flavor reordering for APP_TYPE_MAIL if needed.
(In reply to Magnus Melin from comment #46) > Could you have another look at this? I have looked at this for many hours, so I don't need to take another look. I don't like the approach and I will not approve it. These are my reasons: 1) I strongly dislike the insertion of data URIs since they destroy a useful user interface. Conversion to data URIs should happen as late as possible in the pipeline, usually at send time, not at composition time. 2) You cannot copy images from a file:// based web page. Your M-C change is not acceptable and won't find approval since it changes the behaviour of Firefox for no good reason. In reply to comment #48: You that there are lots of JS "editors" around that do a whole lot of listeting in the contenteditables they live it. We cannot change that behaviour. Hacking it for APP_TYPE_MAIL is, well, a hack. I will work on my approach: 1) Switch to APP_TYPE_MAIL and let the M-C editor do the image handling. This is necessary, as you pointed out, since APP_TYPE_EDITOR receives no sanitation of pasted content, but APP_TYPE_MAIL does. 2) Make sure we sanitize pasted content (done in 1)), quotes and any content from "edit as new" or forward. 3) Switch the default attachment action to "do not attach", so any content we see will not be attached unless the moz-do-not-send=false was explicitly set. 4) Signatures: I'm happy that people have to rework their signatures. Cases from comment #36: 1) Images via direct HTML: They need to add moz-do-not-send=false (or you can do it for them). 2) Images attached directly via "Attach signature from file": You add moz-do-not-send=false. 3) Images attached via HTML via "Attach signature from file": They need to add moz-do-not-send=false (or you can do it for them). In fact, you already visited all those spots to convert the image to data URI, so instead you can add the moz-do-not-send=false for file:// based pictures. 5) When pasting: Look at the content being pasted. If the content being pasted only contains one image and nothing else, set moz-do-not-send=false on that image. I will attach patches for 1) and 5) in the next comments. I believe that part of your patch can be used for parts 3) to 4). Let me know if you're prepared to accept a solution like the one I have proposed.
This also switches to APP_TYPE_MAIL.
Attachment #8741489 - Flags: review?(mozilla)
Comment on attachment 8742664 [details] [diff] [review] JK M-C part: Handling image insertion for APP_TYPE_MAIL Review of attachment 8742664 [details] [diff] [review]: ----------------------------------------------------------------- This is a major no-no. You can't allow mail content to access whatever they like on the system.
Attachment #8742664 - Flags: review-
I have to say I don't think your dislike of data uris (for whatever reason I don't know) is a valid reason not to go ahead with them. Please base it on technical facts. Maybe others can chip in with opinions here?
Flags: needinfo?(ehsan)
Flags: needinfo?(Pidgeot18)
(In reply to Magnus Melin from comment #52) > This is a major no-no. You can't allow mail content to access whatever they > like on the system. Huh? It allows insertion of images like we did before. Where's the problem? They are sanitised, so they won't be sent. What's wrong with the patch?
It also allows any mail you *receive* to link/access anything on your computer.
(In reply to Magnus Melin from comment #53) > dislike of data uris (for whatever reason I don't know) ... They are ugly, they can be huge for large images and they MUST not show in the user interface if avoidable. The user has <img src="file://...> in his signature or inserts an image from the file system and you show him the encoded binary representation of the file. Please don't! Let me know the technical advantages of your solution apart from being more independent of the M-C editor.
(In reply to Magnus Melin from comment #55) > It also allows any mail you *receive* to link/access anything on your > computer. Since the overall app is APP_TYPE_MAIL? OK, then the patch is wrong. Then we need to stay APP_TYPE_EDITOR and make sure we get sanitation on paste, or create APP_TYPE_MAIL_EDITOR. That's implementation detail. The main question to answer here: Immediate conversion of all images in the composition window to data URIs, yes or no. My answer is a clear "No".
Being *web compatible* is the huge deal. "In the user interface" is relative, because nobody really goes back to change the image source in the properties dialog. You delete the image and paste a new one. On the off chance you do want to change it, it doesn't matter what was there earlier.
Attached image Screenshot showing the data URI I'm opposing (obsolete) (deleted) —
Since you asked other people to chip in, let them have an image ;-) This is how the image properties dialogue will look like in Magnus' approach. All user-inserted imaged from a local file (including via a signature) are converted to data URIs. The original file location is lost. What do you think? Maybe Kent has an opinion, too, since he was meant to be a reviewer here.
Flags: needinfo?(rkent)
Attachment #8742696 - Flags: ui-review?
(In reply to Magnus Melin from comment #58) > Being *web compatible* is the huge deal. And that means, more independence from the M-C editor?
The inclusion of data URIs in the composition would also preclude having any HTML editor associated with the compose window in the future since those potentially large data blocks would just fill the screen. There already is an add-on which provides a HTML tab, so its users wouldn't be pleased.
(In reply to Magnus Melin from comment #53) > I have to say I don't think your dislike of data uris (for whatever reason I > don't know) is a valid reason not to go ahead with them. Please base it on > technical facts. > > Maybe others can chip in with opinions here? First things first, I'm _not_ trying to pile onto the ongoing argument here. This is just my opinion and you and/or Jorg are welcome to disagree. :-) On switching the editable region from APP_TYPE_EDITOR to APP_TYPE_MAIL, I think that's definitely the right thing to do. Note that this flag affects whether Gecko tries to sanitize attributes and elements that can run scripts (think of pasting <img src="invalid" onerror="doBackThings()"> for example.) On the question of whether it's fine to show a data URI in the UI, I personally don't care much either way. If it's just the string in the UI, perhaps upon pasting you could remember the original URI somewhere (preferably outside of the DOM being edited) and use it in the UI when needed? On doing hacks such as attachment 8742664 [details] [diff] [review], absolutely no. I'll r- any such patch which turns off tree sanitization for all APP_TYPE_MAIL editors. On breaking people's existing email signatures, I definitely think we should make sure that images in signatures still work (i.e., the image shows up and will get sent as a data: URI.) On the objection to data: URIs, years ago we switched Thunderbird to convert pasted image files in emails to data: URIs, and the sky didn't fall (and to the best of my knowledge we did not even receive a single complaint.) I hope I'm covering all of the in-flight discussion points. If you have any other questions, please let me know.
Flags: needinfo?(ehsan)
(In reply to :Ehsan Akhgari (busy, don't ask for review please) from comment #62) > On doing hacks such as attachment 8742664 [details] [diff] [review], > absolutely no. I'll r- any such patch which turns off tree sanitization for > all APP_TYPE_MAIL editors. Ehsan, I don't understand your comment. My aim is to allow image inclusion from files in TB compose windows. This currently works since the compose window is of APP_TYPE_EDITOR. The downside of being APP_TYPE_EDITOR is that pasted content is *not* sanitised. I tried pasting this form a page <img moz-do-not-send="true" klaus-attr="huhu" src="file://D:/Desktop/Bugzilla-down.png"> and the attributes got pasted. That's why I wanted to switch to APP_TYPE_MAIL to get the sanitation and I did - if (appType != nsIDocShell::APP_TYPE_EDITOR) { + if (appType != nsIDocShell::APP_TYPE_EDITOR && appType != nsIDocShell::APP_TYPE_MAIL) { in attachment 8742664 [details] [diff] [review] to still allow file images being pulled in. This is the wrong thing to do, since the overall TB window is of APP_TYPE_MAIL, so just viewing an e-mail would access the image on the local machine as Magnus pointed out in comment #52. Since APP_TYPE_EDITOR doesn't get sanitation and APP_TYPE_MAIL can't be used, I'm proposing a new type APP_TYPE_MAIL_EDITOR which will get sanitation but will still allow images from file://. You're saying: I'll r- any such patch which turns off tree sanitization for all APP_TYPE_MAIL editors. That was never the plan and that was also not what the patch in attachment 8742664 [details] [diff] [review] was about. Or do you count nsContentUtils::CanLoadImage() as part of the sanitation? I thought, and I'm new to this area, that sanitation has to do with cleaning up content before pasting it. Please explain and also please look at the patch with the f? In an attempt to copy single images as bitmaps, Magnus has proposed attachment 8742488 [details] [diff] [review] which simply changes the order of the flavours. Personally I don't think it's a good idea. Can you please comment on this, too.
Attachment #8742664 - Attachment is obsolete: true
Attachment #8742872 - Flags: feedback?(ehsan)
Comment on attachment 8742872 [details] [diff] [review] JK M-C part: Handling image insertion for APP_TYPE_MAIL_EDITOR Review of attachment 8742872 [details] [diff] [review]: ----------------------------------------------------------------- ::: docshell/base/nsIDocShell.idl @@ +320,5 @@ > */ > const unsigned long APP_TYPE_UNKNOWN = 0; > const unsigned long APP_TYPE_MAIL = 1; > const unsigned long APP_TYPE_EDITOR = 2; > + const unsigned long APP_TYPE_MAIL_EDITOR = 2; That should of course be = 3.
Comment on attachment 8742872 [details] [diff] [review] JK M-C part: Handling image insertion for APP_TYPE_MAIL_EDITOR I don't know exactly what APP_TYPE_MAIL_EDITOR is supposed to be. If you want to create another app type, we need to define exactly how it differs from the existing ones, after auditing the existing places where we do something based on the app type. But I also disagree with your overall approach as my comment suggested. My comment was about treating all APP_TYPE_MAIL as APP_TYPE_EDITOR, I used the wrong attachment name. Sorry about that! Last but not least, I'm very busy and don't have time for reviews these days, as my Bugzilla name clearly suggests. :-) Please find another reviewer once there is a final patch ready. Thanks.
Attachment #8742872 - Flags: feedback?(ehsan)
(In reply to :Ehsan Akhgari (busy, don't ask for review please) from comment #65) > I don't know exactly what APP_TYPE_MAIL_EDITOR is supposed to be. If you > want to create another app type, we need to define exactly how it differs > from the existing ones, after auditing the existing places where we do > something based on the app type. But I also disagree with your overall > approach as my comment suggested. I know you're very busy, but you've sadly caused some confusion here. If you want to avoid people having to clarify, please be clear to start with ;-) Which overall approach do you disagree with? You said that switching from from APP_TYPE_EDITOR to APP_TYPE_MAIL is definitely the right thing to do. If we do this, we lose the ability of showing images from file://. Either we need to do Magnus' trick to pull all the images in as data URIs or do my approach of creating a new app type, which, agreed, should be exactly defined. > My comment was about treating all APP_TYPE_MAIL as APP_TYPE_EDITOR, I used > the wrong attachment name. Sorry about that! I'm not aware that any patch suggested that, but then there's a history of obsolete patches, some carry your f- and others carry your r+. Can you please clarify and then I won't ask any more and we won't ask you for review.
Flags: needinfo?(ehsan)
(In reply to Jorg K (GMT+2) from comment #66) > (In reply to :Ehsan Akhgari (busy, don't ask for review please) from comment > #65) > > I don't know exactly what APP_TYPE_MAIL_EDITOR is supposed to be. If you > > want to create another app type, we need to define exactly how it differs > > from the existing ones, after auditing the existing places where we do > > something based on the app type. But I also disagree with your overall > > approach as my comment suggested. > I know you're very busy, but you've sadly caused some confusion here. If you > want to avoid people having to clarify, please be clear to start with ;-) > Which overall approach do you disagree with? > You said that switching from from APP_TYPE_EDITOR to APP_TYPE_MAIL is > definitely the right thing to do. Right. > If we do this, we lose the ability of showing images from file://. Either we > need to do Magnus' trick to pull all the images in as data URIs Yes, this is what I suggest we should do.
Flags: needinfo?(ehsan)
The functionality of the "Insert HTML" window would also be destroyed by Magnus' (and Ehsan's) solution. For me, it took 13 seconds to bring up the window and TB became unresponsive during this time. Please don't destroy the UI for the sake of fixing a security bug.
Huh? Insert HTML is empty to start with! In any case, you're probably running a very slow debug build. Though the uris can obviously be long, it shouldn't take much time for real. Regarding editing html src that's not a feature available today, and it's totally up to the editor to cap what it wants to display in that view. I know I've seen editors do exactly that for long attribute values until you go to edit the attribute.
(In reply to Magnus Melin from comment #69) > Huh? Insert HTML is empty to start with! In any case, you're probably > running a very slow debug build. Though the uris can obviously be long, it > shouldn't take much time for real. > > Regarding editing html src that's not a feature available today, and it's > totally up to the editor to cap what it wants to display in that view. I > know I've seen editors do exactly that for long attribute values until you > go to edit the attribute. It's available, but not obvious. Select whole text in message and then choose Insert HTML, voila the whole html content is in this window. Thats how I'm changing things in html mails. And this would make it hard with data URIs as it fills the window unneeded.
Insert HTML shows the HTML around the spot where you edit, so I inserted the image first, then tried to add more HTML around it. Also, "Insert HTML" is the poor man's solution to inspect the HTML of the body. I was using the official TB Daily as of yesterday. There are other ways to insert the ugly data URI today without your patch (via drag) but your approach would aggravate the issue greatly since every image from a file would cause it.
<somewhat off topic> I tried a data URI on TinyMCE (https://www.tinymce.com/). They upload the image and show: blob:https://www.tinymce.com/37a04812-b882-46bb-a2f6-bbb3c20371dd as info. I also tried https://textbox.io. They also upload and show: <p><img alt="" src="https://s3.amazonaws.com/tbio.demo.images/1wugguwjiatkm69xmt7w1den1mpvqkxi75mwfmb49lz89o4r/soQYkXSaRI.bmp" /></p> All measures to hide the data like we always have done with <img src="file:// ...> And we're not talking about web editing as such. We're talking about a user preparing a document on his local machine with data from his local machine for sending later. </somewhat off topic>
Investigation into the use of APP_TYPE_MAIL in M-C: http://mxr.mozilla.org/mozilla-central/source/dom/base/nsGlobalWindow.cpp#4482 nsGlobalWindow::GetOpenerWindowOuter() - opener not returned for APP_TYPE_MAIL http://mxr.mozilla.org/mozilla-central/source/dom/base/nsContentUtils.cpp#7072 nsContentUtils::PrefetchEnabled() false returned for APP_TYPE_MAIL These wouldn't change with the introduction of APP_TYPE_MAIL_EDITOR. Investigation into the use of APP_TYPE_EDITOR in M-C: http://mxr.mozilla.org/mozilla-central/source/dom/base/nsContentUtils.cpp#3011 nsContentUtils::CanLoadImage() - I suggest to add APP_TYPE_MAIL_EDITOR here, attachment 8742872 [details] [diff] [review]. http://mxr.mozilla.org/mozilla-central/source/editor/libeditor/nsPlaintextDataTransfer.cpp#444 nsPlaintextEditor::IsSafeToInsertData() - true returned for APP_TYPE_EDITOR. Investigation into the use of IsSafeToInsertData() in M-C: http://mxr.mozilla.org/mozilla-central/source/editor/libeditor/nsHTMLDataTransfer.cpp#1108 http://mxr.mozilla.org/mozilla-central/source/editor/libeditor/nsHTMLDataTransfer.cpp#1230 IsSafeToInsertData() is called and the result is passed into InsertObject(). Following the call-chain we get here: https://dxr.mozilla.org/mozilla-central/source/editor/libeditor/nsHTMLDataTransfer.cpp#2133 There the sanitiser gets called if it wasn't safe. http://mxr.mozilla.org/mozilla-central/source/editor/libeditor/nsPlaintextDataTransfer.cpp#190 I didn't look into that further. Summary: APP_TYPE_EDITOR inserts images and does NOT get sanitation. New APP_TYPE_MAIL_EDITOR would insert images and receive sanitation. My approach: 1) New APP_TYPE_MAIL_EDITOR (attachment 8742872 [details] [diff] [review]). 2) Make sure we sanitize pasted content (done in 1)), quotes and any content from forward or "edit as new". Note that quotes and inline forwarded content already pass through TagEmbeddedObjects(), so moz-do-not-send is set to true. Processing missing for "edit as new" content. 3) Switch the default attachment action to "do not attach", so any content we see will not be attached unless the moz-do-not-send=false was explicitly set. 4) Signatures as per comment #49 (not repeating it again). 5) When pasting: Look at the content being pasted. If the content being pasted only contains one image and nothing else, set moz-do-not-send=false on that image, attachment 8742665 [details] [diff] [review].
Please note that bug 1206961 may end up changing some of the code around CanLoadImage(). Please keep an eye on that bug. I don't think that will cause any material change to what has been discussed here but may end up bitrotting the patch...
Attachment #8742696 - Flags: ui-review?(squibblyflabbetydoo)
Attachment #8742696 - Flags: ui-review?(richard.marti)
Attachment #8742696 - Flags: ui-review?
I put the UI review back which apparently hasn't worked before since the requested parties weren't CC'ed at the time of the request. I just want to hear your opinion about the data UR's in the user interface.
Comment on attachment 8742696 [details] Screenshot showing the data URI I'm opposing In Image Properties dialog it would be no problem. But if you have to edit the message code in Insert HTML dialog then it's a pain with the normally long base64 code filling the window. If the base64 part could be folded then I would see no problem. ui-r- only for the Insert HTML case.
Attachment #8742696 - Flags: ui-review?(richard.marti) → ui-review-
Comment on attachment 8742696 [details] Screenshot showing the data URI I'm opposing It's hard for me to tell all the times that you'd get data: URLs. If I add an inline image while editing, is it a file: URL until I click send? If I reply to a message, is it a cid:* URL? I don't think I can say whether this is ok or not without knowing the exact scenarios where we'd start using a data: URL. * I think it's cid: for the multipart/related messages.
Attachment #8742696 - Flags: ui-review?(squibblyflabbetydoo)
(In reply to Jim Porter (:squib) from comment #77) > It's hard for me to tell all the times that you'd get data: URLs. If I add > an inline image while editing, is it a file: URL until I click send? If I > reply to a message, is it a cid:* URL? > > I don't think I can say whether this is ok or not without knowing the exact > scenarios where we'd start using a data: URL. With Magnus approach, no file URL would ever be used any more: 1) Inline pictures added while editing would be immediately converted to data URIs, (see attachment 8742696 [details]). 2) Pictures from signatures would be converted to URIs when inserting the signature. 3) Pictures pasted from a file:// based web page would also be converted to data URIs, although Magnus has not provided a way to do this yet. In short: The whole HTML would be polluted with data URIs everywhere. That renders the image properties dialogue useless (imagine someone editing the data string), it renders "Insert HTML" useless and it renders all add-ons that offer HTML editing (most notably "Stationary") useless. From a UI perspective this is a catastrophe.
Ok yeah, that's bad. I think the only thing we should be changing is what happens when you paste HTML. While other attack vectors may exist, they're so close to valid use cases that we'd have to be *extremely careful* about changing them.
Sorry to repeat it again: Are are four ways to ship out HTML that would drag local files with it: 1) Reply 2) Forward 3) Edit as New 4) Paste from the attackers e-mail. 1) and 2) are not an issue since they are already treated in TagEmbeddedObjects(). Pasting is taken care of by sanitising, that is, no longer being a APP_TYPE_EDITOR, and switching the default to not send the file unless explicitly asked for. So far Magnus' and my approach are the same. I'd like to create a new app type APP_TYPE_EDITOR_MAIL which would still allow image insertion from a file via M-C code, therefore maintaining the current UI, whereas Magnus doesn't want to rely on M-C code and convert all images to data URIs immediately, therefore damaging the current UI. If we all agreed on the way forward, we could put a safe and working solution together in a day, we have all the pieces required.
Do you know what happens with drafts? When we save a draft, we convert from file: URLs to attachments (possibly with cid: URLs), correct? No valid draft should have a file: URL, right? If that's the case, then it makes sense to sanitize messages and strip file: URLs every time we edit as new. This probably has some ramifications on bug 877159, although I haven't thought them all through. In any case, I agree that data: URLs seem like the wrong way to go here. Unless there's really no other way to resolve this, I think we should avoid them.
Drafts maintain the file:// URL. The conversion to cid: happens when we send. Note that "edit draft" and "edit as new" are two different actions these days. I haven't looked into the "edit as new" of an attacker's message yet. My assumption so far is that I will do the same processing as for forward and reply.
(In reply to Jorg K (GMT+2) from comment #82) > Drafts maintain the file:// URL. The conversion to cid: happens when we send. I double-checked on 45.0. That's not the behavior I see. I inserted an image into an HTML mail via the toolbar button, saved the draft, and viewed the source in the reader. I see a cid: URL. When I edit the draft, I see the URL has changed to an imap: URL instead (or a mailbox: URL for Local Folders). I did notice that, at least on Windows, dragging and dropping an image into the body of an HTML mail already gives us a data: URL...
OK, I tested a different case. I copied a picture from a file:// based web page: <html> <body> <img moz-do-not-send="true" src="file://D:/Desktop/Bugzilla-down.png"> </body> </html> The file:// URL is maintained in the draft. Yes, dragging an image already produces a data URI. But we don't need to make things worse, right?
That behavior definitely seems wrong. Doesn't moz-do-not-send mean that the src attribute will be sent unchanged? I wouldn't expect that behavior as a user.
There seems to be a misunderstanding. The HTML above shows the web page I copied from. I added various attributes to check the new sanitisation upon paste. moz-do-not-send=true means: Do not send this attached. moz-do-not-send=false means: Send this attached. The attack vector was to send invisible content with moz-do-not-send=false, which, when pointing to a known location on the user's machine, would access files and sent them as attachments when copied to another message. In the future it will default to true, so nothing gets sent unless explicitly asked for. Sanitisation will remove any pre-existing values during copy/paste, so the new default value will be used and nothing will get sent. Where the user explicitly inserts an image (also via a signature), we will set moz-do-not-send=false to trigger attaching. What do you mean by: "the src attribute will be sent unchanged?"
(In reply to Jorg K (GMT+2) from comment #86) > What do you mean by: "the src attribute will be sent unchanged?" If you have "<img moz-do-not-send="true" src="file://D:/Desktop/Bugzilla-down.png">" in an email message, I thought the moz-do-not-send="true" attribute means, "don't do anything to the src URL; just send it as-is (i.e. *don't* attach the src and make a cid: URL)." Is that wrong?
Just a few quick notes here: 1) we're not a web page editor 2) the attack vector of this bug is dual - A) not removing moz-do-not-send and also B) by default attaching when that's not present at all There's really not a solid solution around using data uris. You'll just play wack-a-mole, because is we use the editor as an editor it's a TRUSTED editor. We're not (going to), so we must play by the rules of the web, which means no file:// access. If you try to cheat you open an attack vector.
In that case, shouldn't we just create cid: URLs immediately? That's what we want to send anyway.
(In reply to Jim Porter (:squib) from comment #87) > If you have "<img moz-do-not-send="true" > src="file://D:/Desktop/Bugzilla-down.png">" in an email message, I thought > the moz-do-not-send="true" attribute means, "don't do anything to the src > URL; just send it as-is (i.e. *don't* attach the src and make a cid: URL)." > Is that wrong? What you said is correct. (And I still don't understand your comment #85.) moz-do-not-send is normally for non-file URLs, so the sender can decide whether or not they want to attach an image. For example, people who have a 30KB image in their signature don't want to attach it to every message, so they have <img moz-do-not-send="true" src="http://mysite.com/images/sig-pic.png"> in their signature. (In reply to Jim Porter (:squib) from comment #89) > In that case, shouldn't we just create cid: URLs immediately? That's what we > want to send anyway. Sadly that doesn't work since we have no where to get the image from as long as the draft isn't saved.
(In reply to Jorg K (GMT+2) from comment #90) > (In reply to Jim Porter (:squib) from comment #89) > > In that case, shouldn't we just create cid: URLs immediately? That's what we > > want to send anyway. > Sadly that doesn't work since we have no where to get the image from as long > as the draft isn't saved. Can't we store a reference to it in memory? Even if they're not real cid: URLs, we could create some kind of a mapping to an internal list of files that we know the user intended to attach.
(In reply to Magnus Melin from comment #88) > Just a few quick notes here: > 1) we're not a web page editor Some people (and may add-ons) use the compose window as an HTML editor. > 2) the attack vector of this bug is dual - A) not removing moz-do-not-send > and also B) by default attaching when that's not present at all And those will be fixed in both approaches. > There's really not a solid solution around using data uris. You'll just play > wack-a-mole, because is we use the editor as an editor it's a TRUSTED > editor. We're not (going to), so we must play by the rules of the web, which > means no file:// access. If you try to cheat you open an attack vector. I disagree. Of course always using data URIs solves the problem, but I'm not convinced that the problems can't be fixed any other way. Defaulting to "don't send" will just not send unless it's one of the exceptions cases: 1) Signature 2) User inserted image via 2a) direct insertion or 2b) paste of single image. As Jim said in comment #79: We have to be very careful not to affect valid use cases. A "therapia sterilisans magna" is not the right way here. <off topic> There is just that much change users will wear. We've spent man weeks containing the "correspondents column debacle" just because someone (not me!! I implemented the auto-upgrade-opt-out) decided to force a new unbaked feature onto the users. </off topic>
(In reply to Jim Porter (:squib) from comment #91) > Can't we store a reference to it in memory? Even if they're not real cid: > URLs, we could create some kind of a mapping to an internal list of files > that we know the user intended to attach. The M-C editor that rules inside the <div contenteditable> that we're using for HTML editing doesn't support that. However, Ehsan suggested something along those lines (comment #62) (quoting) === On the question of whether it's fine to show a data URI in the UI, I personally don't care much either way. If it's just the string in the UI, perhaps upon pasting you could remember the original URI somewhere (preferably outside of the DOM being edited) and use it in the UI when needed? === However, I still don't see why a solution that carefully manages sending from files can't work.
(In reply to Jorg K (GMT+2) from comment #93) > (In reply to Jim Porter (:squib) from comment #91) > > Can't we store a reference to it in memory? Even if they're not real cid: > > URLs, we could create some kind of a mapping to an internal list of files > > that we know the user intended to attach. > The M-C editor that rules inside the <div contenteditable> that we're using > for HTML editing doesn't support that. It supports other protocols we control, like imap: and mailbox:. Couldn't we create a pendingattachment: protocol that we hook up in the appropriate places?
(In reply to Jim Porter (:squib) from comment #94) > It supports other protocols we control, like imap: and mailbox:. Couldn't we > create a pendingattachment: protocol that we hook up in the appropriate > places? Why so much effort? Can someone clearly state why the solution I set out in comment #73 at the bottom doesn't work or is for other (good) reasons undesired? (I don't count the "wack-a-mole" argument as a good reason.)
In comment 59 Jorgk asked for my opinion. I'm following the discussion, but for now I feel like Magnus, Jorg, Ricahrd, and Jim are still working toward the right solution. If there is an impasse I will try to help resolve it, but I'd rather let these people work it out.
Flags: needinfo?(rkent)
Comment on attachment 8742665 [details] [diff] [review] JK C-C part: Paste listener to attach moz-do-not-sent="false" to single pasted images Review of attachment 8742665 [details] [diff] [review]: ----------------------------------------------------------------- This is also not fixing the problem. It just requires the attacker to put html content with a fake file:/// image on your clipboard instead, which is not that much harder. You can't win here...
Attachment #8742665 - Flags: review-
(In reply to Jorg K (PTO during summer, NI me) from comment #95) > (In reply to Jim Porter (:squib) from comment #94) > > It supports other protocols we control, like imap: and mailbox:. Couldn't we > > create a pendingattachment: protocol that we hook up in the appropriate > > places? > Why so much effort? I certainly agree there. We already *have* data uris. There's no reason to invent the wheel again. > Can someone clearly state why the solution I set out in comment #73 at the > bottom doesn't work or is for other (good) reasons undesired? (I don't count > the "wack-a-mole" argument as a good reason.) I did so in comment 97. But you really should count the "wack-a-mole" argument as a good reason too.
Attached patch bug1151366_sec_file_attach.patch (obsolete) (deleted) — Splinter Review
Changes from earlier: Makes the insert HTML dialog use short data uris (very similar to ff devtools inspector) during editing. With this I believe this is ui-r+ per comment 76.
Attachment #8741489 - Attachment is obsolete: true
Attachment #8751444 - Flags: review?(mozilla)
Are you going to propose a solution for the copying of an image from file:// based web page? As per comment #47 the proposed M-C change came back with a test failure.
Yes, once we can agree on the mailnews part. The test just needs to be adjusted for a different expected result.
Attached image Insert HTML view (obsolete) (deleted) —
I gave the new patch a quick whirl. Here's a screenshot of the "Insert HTML" windows with the, well, shortened (not wrapped into a clickable node) string. The user can of course edit that string and destroy the image. They can also edit the data URI in the image properties and destroy the image. The argument has been that data URIs already happen when an image is dragged into a composition, so perhaps it's about time we disable the editing of those data URIs. Also, I found another hole in your approach: If in "Insert HTML" you insert, for example, my test case, file:///D:/Desktop/Bugzilla-down.png, the image is not displayed. You've have to reach in there as well and replace the image with a data URI. Let me summarise: You have to change processing in - image insertion - signature processing - HTML insertion (still to do) - pasting from a file:// based web page (still to do) (and I'm not sure how willing the M-C people are going to be to wear those changes).
Attachment #8751502 - Flags: ui-review?(richard.marti)
(In reply to Magnus Melin from comment #97) > Comment on attachment 8742665 [details] [diff] [review] > JK C-C part: Paste listener to attach moz-do-not-sent="false" to single > pasted images > > This is also not fixing the problem. It just requires the attacker to put > html content with a fake file:/// image on your clipboard instead, which is > not that much harder. Can you explain to me how the attacker would do that? This code I proposed inspects the text/html flavour of the clipboard at paste time and if it contains a single image, it inserts that with "moz-do-not-send"=false. So the attacker needs to send HTML e-mail that contains <img src="file://file-steal.ext"> in some invisible form. He needs to get the victim to select this one piece of invisible HTML and then paste it. OK, that would have to be a pretty skilled attacker and, more importantly, also a pretty skilled victim to select just that piece of invisible data and paste it. This clipboard inspection was WIP just to show the concept. It can be tightened to ensure that the only visible images would be inserted with "moz-do-not-send"=false. I would argue that if the user actively pastes something and the image pops up in front of him, there is no harm in shipping that out. BTW, I've written this piece of code so you could use it for your solution with the data URIs if M-C won't permit the changes you still haven't specified. You can grab the image and convert it to data URI in the paste handler. (In reply to Magnus Melin from comment #101) > Yes, once we can agree on the mailnews part. The test just needs to be > adjusted for a different expected result. I don't think M-C will agree on behaviour changes in FF or any test change. Therefore, I'd like to see the whole solution before signing off on any of the parts. IMHO it would make more sense to settle the M-C part first or it least start the negotiation.
Comment on attachment 8751444 [details] [diff] [review] bug1151366_sec_file_attach.patch (No offense intended. I just don't like the red indicator in BMO telling me I have to do something. I've looked at the patch and found another hole and some UI issues, see comment #102.)
Attachment #8751444 - Flags: review?(mozilla)
Comment on attachment 8751502 [details] Insert HTML view It's already better than before. But it's still possible to edit the data content by accident. Also that's not possible to insert a file:// link is not desired.
Attachment #8751502 - Flags: ui-review?(richard.marti)
Yes, of course it's possible to edit data content by accident - you can also edit/insert whatever other invalid html you want, and there's not a thing we can do about that. You'll find out soon enough though when you see what your html looked like. It would not be that hard to convert file:// sources to data if they were present in the Insert HTML dialog. I did at first agree, but thinking about it some more I think we should not: 1) we're not a web page editor 2) that's an unnecessary complication, it's not like something people have grown accustomed to 3) when you're inserting plain html you don't expect what you write to change, you may want to for instance compose a test cased for this bug 4) inserting local pictures by Insert HTML is likely not very used, I don't know why you would do that - it's highly error prone. You're really likely better off linking to http sources 5) the current patch would be welcome behaviour for the editor also. Yes it's possible to add an override but it's all over-engineering the whole feature.
You are correct on two things: - data URI already exist due to drag&drop. - Editing HTLM manually can of course introduce errors, in the HTML and any data URIs contained in it. I don't agree with the rest you're saying or I don't understand it: > 1) we're not a web page editor We have a function to edit HTML, that function works and there is no apparent reason to break it. > 2) that's an unnecessary complication, it's not like something people have grown accustomed to We don't know how many people will be affected. You plan to silently break existing functionality. > 3) when you're inserting plain html you don't expect what you write to change, > you may want to for instance compose a test cased for this bug Well, when you insert a picture from file://mypic.jpg you don't expect to find a data URL in the image properties when you visit it again. But you force this upon the user. Surely, if the user inserts an image they want to see it in their e-mail composition and not some placeholder indicating a broken image. > 4) inserting local pictures by Insert HTML is likely not very used, I don't know > why you would do that - it's highly error prone. You're really likely better off > linking to http sources Here you're repeating point 3). It's an existing function and we shouldn't break it. > 5) the current patch would be welcome behaviour for the editor also. Yes it's possible > to add an override but it's all over-engineering the whole feature. Which editor? The M-C editor? It prefers data URIs? The second part I don't understand. Which "over-engineering"? You're proposing a huge change to the way images are handled, so of course there is some engineering involved. If we go with data URIs, we need to do it fully. That includes: - image insertion. Here I'd really like to see some (image data) place holder and not the base64 string (still to do). - signature processing (done) - Showing data URIs in the HTML window: Done, but I'd prefer not to see any of the base64 stuff, src=(image data) should be enough, same goes for the image properties (see above). - HTML insertion (still to do) - pasting from a file:// based web page, either with an M-C change or the paste listener (still to do) Whilst the TB compose window is not strictly a HTML editor, we know that people use a whole lot of HTML. There are add-ons that do special template processing or formatting of the message body ("Stationery", "SmartTemplate4"). Consequently there are also add-ons which provide HTML editing facilities ("Stationery", "ThunderHTMLedit"). These add-ons will just have to work much harder to cope with the data URIs. TB core at least should also fix all the various corners that break due to the adoption of data URIs. Since this won't land on TB 45.x, we still have months to do it properly for TB 52.
Flags: needinfo?(Pidgeot18)
(In reply to Jorg K (PTO during summer, NI me) from comment #107) > - Showing data URIs in the HTML window: Done, but I'd prefer not to see any > of the base64 stuff, > src=(image data) should be enough, same goes for the image properties (see > above). Meanwhile I implemented the src="(image data nn)" in my add-on: https://addons.mozilla.org/en-us/thunderbird/addon/thunderhtmledit/
There hasn't been much progress here lately, so let me make a suggestion. Let's go with the data URIs and finish it off properly as per comment #107: - Image insertion. Would it be possible to show an (image data) place holder and not the base64 string in image properties/image location? (still to do) - Signature processing (done) - Showing data URIs in the HTML window: Done, but I'd prefer not to see any of the base64 stuff, src=(image data) should be enough, same goes for the image properties (see above). - HTML insertion of an image in the HTML windows also needs to convert to data URI (still to do) - Pasting from a file:// based web page, either with an M-C change or the *paste listener*. I suggest to use attachment 8742665 [details] [diff] [review] to detect a single image insertion and turn the image into a data URI (still to do).
Attached file clipboard-test.html (obsolete) (deleted) —
(In reply to Jorg K (GMT+2, PTO during summer, NI me) from comment #103) > > This is also not fixing the problem. It just requires the attacker to put > > html content with a fake file:/// image on your clipboard instead, which is > > not that much harder. > > Can you explain to me how the attacker would do that? Try this... it's using an http url just since it's easier to see.
You've been doing too much web work recently. Not sure what you try to prove here. Sure, if I view that web page, select the agadfadfadsf and paste into a TB composition, I get the image pasted. And I see it. And so will the user. After the copy is done, there is an image on the clipboard, and that the user should be able to copy. But your example doesn't work if the source is an e-mail, at least I tried, and I pasted agadfadfadsf. Do we run JS when displaying a message?
Attached file Clipboard test as mail message. (obsolete) (deleted) —
Try this. I pastes "agadfadfadsf". Am I missing something? If there is a HTML for a single image on the clipboard, we should insert the image into the composition in order not to affect current usage.
I'm just proving that your suggested approach of looking for a single image on the clipboard does not really work, since we can easily put a file "image" in there. Yes it requires JavaScript, but the whole exploit is socially engineered. Instead of copying a bait straight from the mail, you just put the bait you want the user to send to you on a web page and have them go copy it from there. It's one more step, but hardly far fetched. Or you put it in a news feed, we do run JavaScript there.
And how do you intend to distinguish "baited" clipboard content from user-intended clipboard content? We can't stop image insertion in general. As Jim said: (In reply to Jim Porter (:squib) from comment #79) > Ok yeah, that's bad. I think the only thing we should be changing is what > happens when you paste HTML. While other attack vectors may exist, they're > so close to valid use cases that we'd have to be *extremely careful* about > changing them. There is a fine line between closing a security hole and damaging the product for everyone. If there is HTML for an image on the clipboard, then the image should get pasted IHMO. If the attacker wants to extract compromising images from the victims machine, they know where they are stored and they manage to get them onto the clipboard and they get the victim to paste that into a message and then *SEES* the compromising image and presses send, well, then we can't help this.
(In reply to Jorg K (GMT+2, PTO during summer, NI me) from comment #114) > And how do you intend to distinguish "baited" clipboard content from > user-intended clipboard content? The thing is we don't have to. If we don't use file:// uris while pasting there is no real problem. > We can't stop image insertion in general. Of course not, just make it safe.
(In reply to Magnus Melin from comment #115) > The thing is we don't have to. If we don't use file:// uris while pasting > there is no real problem. The user may paste from a file:// based web page and it would be good not to break that. === The following argument against stop being an APP_TYPE_EDITOR of some sort (I suggested a new type APP_TYPE_EDITOR_MAIL) occurred to me: We will break all add-ons which insert HTML with file:// based images. The first add-on which will break is the popular "Signature Switch" which I use myself. That rips out the signature and places a new one, most likely with some images from files. And the users will be very surprised if the images don't show any more. I'm CC'ing Axel on this bug. Here's the executive summary for Axel: One option to fix the security issues in this bug would for the TB compose window to cease being an APP_TYPE_EDITOR. The immediate consequence is that <img src="file:// ...> would not be displayed any more. Magnus suggestion is to convert those images to <img src="data:image/png;base64, ...>. We would do this when inserting for example images from signatures. However, there are add-ons which change the body of an e-mail and if those add-ons were to place <img src="file:// ...> into the body, the image wouldn't be displayed any more. Axel, what do you day? Your SmartTemplate4 adds HTML, potentially with those images.
Flags: needinfo?(axelg)
(In reply to Jorg K (GMT+2, PTO during summer, NI me) from comment #116) > The user may paste from a file:// based web page and it would be good not to > break that. My suggested approach does not break that. Add-ons may need to adapt, but the changes are not substantial. I don't see the point of discussing this further, I've already proved the alternative is not safe.
OK, you want to stop the discussion and so do I. How about to answer what I have asked (a felt) million times now. Let me summarise (again) the problems introduced by your approach. 1) Manual image insertion. As before already with dragged images, that will now show "data:image/png;base64 ..." more frequently in the UI in the image properties dialogue. Would it be possible to show an (image data) place holder and not the base64 string in image properties/image location? ** Do you plan more action on this item? ** 2) Signature processing. Here you convert any file:// based signature content into a data URI. Maybe it would be good to expose this function for add-ons to call, see below. Or maybe "GenerateDataURI(url)" is that function. ** Do you plan more action on this item? ** 3) Showing data URIs in the HTML window: You proposed to shorten the data URI shown. I'd prefer not to see any of the base64 stuff. src="(image data)" (as I do in ThunderHTMLedit) should be enough, same goes for the image properties (see point 1). ** Do you plan more action on this item? ** 4) HTML insertion of an image in the HTML windows also needs to convert to data URI: If the user manually adds a file:// based image in the HTML window, the image won't show. ** Do you plan more action on this item? ** 5) Pasting from a file:// based web page. You said in comment #117 that your "suggested approach" doesn't break that. Sadly, it is not clear to me, what the suggested approach is. Maybe the M-C change to switch the clipboard flavours around. That doesn't have a complete patch (the one M-C patch presented has test failures). ** What is the "suggested approach"? If it's an M-C change, when will you present this for review with the M-C people? ** 6) Add-ons which insert HTML with file:// based images, as for example "Signature Switch": Similar to point 4), those images won't show and therefore the add-on functionality will be broken. ** How will you communicate this to the add-on authors? IMHO (quote): "Add-ons may need to adapt, but the changes are not substantial." is misleading and a clear understatement. Add-ons *WILL BREAK* and changing processing to extract the file:// based image and convert them to data URIs is not a completely simple task. However, if you set a good example for point 4), I'm sure add-on authors could adapt the TB changes to their needs. You could even provide a function to call. I'd also have to make the change in my ThunderHTMLedit. (Further discussion, see below: (*)). On *all* items I am still unclear whether you will add a better solution or what the solution is in the first place. So let's stop discussing an nail down the solution, implement it, review it and get it landed. === *) A little off topic: The experience with Tb 45.x has shown that there are many negligent add-on authors who don't test their add-ons with alpha/beta versions in order to adapt them. So the breakage and outcry happens on release of TB 52. I haven't counted the endless list of bugs caused by incompatible add-ons in TB 45.
(In reply to Jorg K (GMT+2, PTO during summer, NI me) from comment #116) > (In reply to Magnus Melin from comment #115) > > The thing is we don't have to. If we don't use file:// uris while pasting > > there is no real problem. > The user may paste from a file:// based web page and it would be good not to > break that. > > === > > The following argument against stop being an APP_TYPE_EDITOR of some sort (I > suggested a new type APP_TYPE_EDITOR_MAIL) occurred to me: We will break all > add-ons which insert HTML with file:// based images. The first add-on which > will break is the popular "Signature Switch" which I use myself. That rips > out the signature and places a new one, most likely with some images from > files. And the users will be very surprised if the images don't show any > more. > > I'm CC'ing Axel on this bug. Here's the executive summary for Axel: > > One option to fix the security issues in this bug would for the TB compose > window to cease being an APP_TYPE_EDITOR. The immediate consequence is that > <img src="file:// ...> would not be displayed any more. Magnus suggestion is > to convert those images to <img src="data:image/png;base64, ...>. We would > do this when inserting for example images from signatures. that would work for me - see special cases in my example below. > > However, there are add-ons which change the body of an e-mail and if those > add-ons were to place <img src="file:// ...> into the body, the image > wouldn't be displayed any more. Yes, ST4 does this and Stationery as well. Doesn't it depend on _when_ the conversion is done? If the security issue only applies to quoted emails (replying to an email with an attack vector <img> tag) could the conversion be restricted to <blockquote> only? > > Axel, what do you day? Your SmartTemplate4 adds HTML, potentially with those > images. My questions are: 1) are the img tags not expanded when loading composer or editing the tags in HTML view? - if you are planning on writing a conversion function we could potentially call it as part of our workflow by parsing just the template (we never modify the quoted block anyway). I have several mail templates that use tags like the below in order to inject some icons: <img src="file:///E:/Dev/Mozilla/DEV/QF/_Mozdev/quickfolders/www/ico/QF16x16.png" style="float:left;margin-right:1em;"> These are injected via Stationery - I am okay with automatic conversion to inline pictures as it doesn't present any additional problems in WYSIWYG mode. I think Joerg's ThunderHTMLEdit extension already makes the code more manageable in HTML by collapsing the hex-data according to his suggestion. 2) where conversion fails, could we add a (right-click menu) UI to the broken image icon for manually fixing / browsing to the approximate location of the broken file link? 3) we currently still have a bug that leads to invalid picture data (my guess is that it references a mail:// location which can break when mails are moved to other folders via filter rules) and stops the email from being sent out ("attaching files...") - is there a bug for this one and what can be done to alleviate this? Generally it is very hard to find invalid reference links like this while in WYSIWYG composer and often the only solution is deleting all inline pictures (cut and paste sometimes also works if I am not mistaken). Not sure what to do about mail references, but a tidy up option (remove all broken links) to force sending would be fantastic. 4) Clipboard Behavior: I think when cutting a (displayed) picture that comes from a (mailbox / file) reference, it should automatically be expanded to the raw picture data when pasting it back. Some of these suggestions may involve creating new (or linking existing other) bugs.
Flags: needinfo?(axelg)
Axel, thanks for your input. We know now that we need to keep add-ons in mind which place file:// based images. Also, I think we haven't considered, or at least, I haven't considered, images pasted via mailbox references, like I've just tried pasting one of those and see this using ThunderHTMLedit: <img src="mailbox:///D:/MAIL-THUNDERBIRD/jorgk.default/Mail/jorgk.jorgk.com/Sent.sbd/Test%20attaching?number=4&amp;part=1.2&amp;filename=lijbmghmkilicioj.png" ... We have to ensure that the solution works for those images. As for the "Attaching ...": You may not be aware that we landed bug 453196 which greatly improves the error handling in these cases. But we all agree, converting links to data URI is the way to completely avoid these problems.
(In reply to Jorg K (GMT+2, PTO during summer, NI me) from comment #120) > Axel, thanks for your input. We know now that we need to keep add-ons in > mind which place file:// based images. > > Also, I think we haven't considered, or at least, I haven't considered, > images pasted via mailbox references, like I've just tried pasting one of > those and see this using ThunderHTMLedit: > <img > src="mailbox:///D:/MAIL-THUNDERBIRD/jorgk.default/Mail/jorgk.jorgk.com/Sent. > sbd/Test%20attaching?number=4&amp;part=1.2&amp;filename=lijbmghmkilicioj. > png" ... yes generally it would be a good idea to convert these ones to data as soon as they hit another email, as it is doubtful that they can be tracked and updated in a meaningful way when users draft replies and then move the original thread. Happens to me plenty :)
There hasn't been a lot of attention to this bug lately. Working on bug 882104 this occurred to me: Further to comment #118, here another summary of how HTML with file:// based images can get into the composition: 1) Manual image insertion. 2) Signatures 3) (this was about the ugly data URIs). 4) HTML insertion of an image in the HTML window and add-ons that let you add HTML. 5) Pasting from a file:// based web page. 6) Add-ons which insert HTML with file:// based images. 7) *New*: Including a HTML file with message= compose switch. The list has just become one item longer and I don't know how many more we've missed. I think we're overcomplicating the system and losing editing capability just for the sake of plugging a hole where I'm still not sure that no other solution exists. We could do the solution I outline in comment #49 / comment #73: Create an app type APP_TYPE_MAIL_EDITOR that still allows *viewing* for file:// bases images, do full sanitisation, switch the default to do-not-sent=true, and here's a new idea: When the user pastes and image from a file:// bases source, insert the image and show it and display a message: You've just pasted an image. Thunderbird has inserted the image into the composition, but to protect your privacy, the image will not be sent unless you change the 'Attach this image to the message' option in the image properties. How's that?
Thinking about this a little further, this could be: You've just pasted nn image(s). Thunderbird has inserted the image(s) into the composition, but to protect your privacy, the image(s) will not be sent unless the option 'Attach this image to the message' in the image properties is set (for each pasted image). [Attach image(s)] [Do not attach image(s)] (Note the plural form of the message). This fixes the problem and even notifies the user that something potentially fishy is going on instead of turning the whole system upside down.
I'll be presenting my solution here in the next couple of days to get some movement here. This is after all a security problem that we should fix one day. Here is the M-C patch. New app type APP_TYPE_MAIL_EDITOR, what it does is explained in the IDL.
Attachment #8742488 - Attachment is obsolete: true
Attachment #8742665 - Attachment is obsolete: true
Attachment #8742696 - Attachment is obsolete: true
Attachment #8742872 - Attachment is obsolete: true
Attachment #8743135 - Attachment is obsolete: true
Attachment #8751444 - Attachment is obsolete: true
Attachment #8751502 - Attachment is obsolete: true
Attachment #8761772 - Attachment is obsolete: true
Attachment #8761929 - Attachment is obsolete: true
Oops, there have been some changes in M-C, so the previous patch doesn't work any more. This one does.
Attachment #8796453 - Attachment is obsolete: true
Attachment #8796645 - Flags: feedback?(rkent)
Attachment #8796645 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796645 - Flags: feedback?
Attached patch JK C-C part: Minimal solution. (obsolete) (deleted) — Splinter Review
Sadly, this bug has stalled. However, this is a real security issue, so we should fix it one day, preferably in TB 52. This my suggestion for a the basic fix. We become a APP_TYPE_MAIL_EDITOR and therefore only receive sanitised paste content, that means, the moz-do-not-send attribute is stripped. We change the default around, to anything without moz-do-not-send=false doesn't get sent. We alert the user when they paste file:// based images. Optional work: - Treat images in signatures as if moz-do-not-send=false were set (so users don't have to manually change their signatures) - On paste, instead of showing the alert, offer the option to set moz-do-not-send=false (see comment #123).
Attachment #8796648 - Flags: feedback?(rkent)
Attachment #8796648 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796648 - Flags: feedback?
Attachment #8736919 - Attachment description: [checked in] bug1151366_sec_file_attach.m-c.patch → [checked in, comment #31] bug1151366_sec_file_attach.m-c.patch
Attachment #8796645 - Flags: feedback? → feedback?(acelists)
Attachment #8796648 - Flags: feedback? → feedback?(acelists)
Attached patch JK C-C part: Minimal solution. (obsolete) (deleted) — Splinter Review
(sorry about the noise, break was at wrong level.)
Attachment #8796648 - Attachment is obsolete: true
Attachment #8796648 - Flags: feedback?(rkent)
Attachment #8796648 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796648 - Flags: feedback?(acelists)
Attachment #8796756 - Flags: feedback?(rkent)
Attachment #8796756 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796756 - Flags: feedback?(acelists)
(In reply to Jorg K (GMT+2) from comment #126) > Optional work: > - Treat images in signatures as if moz-do-not-send=false were set > (so users don't have to manually change their signatures) Actually, signatures with a single image don't work right now since the image does not have moz-do-not-send=false. So that's not optional an needs to be fixed. That would be an easy fix in the signature processing. However, the aim of presenting the patches is to get agreement on the general direction.
Attached patch JK C-C part: Minimal solution (v3). (obsolete) (deleted) — Splinter Review
Sorry about the noise. I fixed the single image signature case since I had advertised a *working* solution. Now the optional work is this: - Treat images in HTML signatures as if moz-do-not-send=false were set (so users don't have to manually change their HTML signatures) - On paste, instead of showing the alert, offer the option to set moz-do-not-send=false (see comment #123).
Attachment #8796756 - Attachment is obsolete: true
Attachment #8796756 - Flags: feedback?(rkent)
Attachment #8796756 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796756 - Flags: feedback?(acelists)
Attachment #8796821 - Flags: feedback?(rkent)
Attachment #8796821 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796821 - Flags: feedback?(acelists)
Attached patch JK C-C part: Proposed solution (v4). (obsolete) (deleted) — Splinter Review
Sorry about further noise ;-) This is no longer "minimal" as I "stole" and adapted a hunk from Magnus' patch to add moz-do-not-send=false in signature file:// URLs so users don't even notice the change. All the files referenced in the signature will now be sent. So the optional further work is reduced to: - On paste, instead of showing the alert, offer the option to set moz-do-not-send=false (see comment #123).
Attachment #8796821 - Attachment is obsolete: true
Attachment #8796821 - Flags: feedback?(rkent)
Attachment #8796821 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796821 - Flags: feedback?(acelists)
Attachment #8796965 - Flags: feedback?(rkent)
Attachment #8796965 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796965 - Flags: feedback?(acelists)
More noise ;-) I noticed that the image insertion also needed some tweaks. Most of this was stolen from Magnus' patch ;-) Now if you insert an image from a file, the panel proposes to attach the image and sets moz-do-not-send=false on it. For a pasted image with no attributes, this is also the proposition. After the alert message the user just has to accept when checking the image properties.
Attachment #8796965 - Attachment is obsolete: true
Attachment #8796965 - Flags: feedback?(rkent)
Attachment #8796965 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796965 - Flags: feedback?(acelists)
Attachment #8796983 - Flags: feedback?(rkent)
Attachment #8796983 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796983 - Flags: feedback?(acelists)
(In reply to Jorg K (GMT+2) from comment #131) > For a pasted image with no attributes, this is also the proposition. I could change this, so pasted images show the panel with the box unticked so the user has to explicitly say: Yes, I want to attach this image. (It should just be a matter of checking the URL since it will be empty for new images and populated for paster images.) Opinions?
I've now spent way too much time on this. Let me give an opinion. Although I have no fundamental objection to a plan that requires us to use data uris instead of file uris in messages, I think that we need to give a lot of thought to the migration process for that, which we simply do not have the time or energy for at the moment. So I think it is premature to attempt that in this bug. Mitigation might involve for example an entire release cycle where this is controlled by a hidden option to discover issues as a workaround for awhile for affected users. So I think at the moment the correct mitigation strategy is something along the lines of comment 132 and its predecessors, which involves warning the user when a file is being inserted into a composed message and requiring them to click a non-default checkbox to opt-in to attaching the file. Normally in security, prevailing wisdom says that users will simply ignore warnings, and that is a risk. But I also think the whole security issue in this bug is already a second-order issue since it requires some social engineering and manual actions on the part of the user. A warning that their actions will result in an attached file (which is unexpected), along with an opt-in, should be sufficient. It has the downside that it introduces additional friction into the operation of file insertion, perhaps we can figure out a way to avoid that extra friction when we know the user is opting in.
Comment on attachment 8796983 [details] [diff] [review] JK C-C part: WIP presented for initial feedback (v5). Review of attachment 8796983 [details] [diff] [review]: ----------------------------------------------------------------- I had a couple of small comments, but did not attempt to review the code details. But I think that a warning to the user when files are going to be sent is the right approach. ::: mail/components/compose/content/MsgComposeCommands.js @@ +2353,5 @@ > > + // Add a listener for paste, so we can tag pasted images. > + // False: dispatch to us last, so we get called once the paste has happened. > + // Note: Since we are a APP_TYPE_MAIL_EDITOR, we only receive sanitised content. > + document.addEventListener("paste", pasteListener, false); What happen with drag and drop, which also inserts html content? ::: mail/locales/en-US/chrome/messenger/messengercompose/composeMsgs.properties @@ +393,5 @@ > replaceButton.accesskey=l > replaceButton.tooltip=Show the Find and Replace dialog > + > +imagePasteFromFileTitle=Paste into compose window > +imagePasteFromFileMessage=You've just pasted an image referencing a file. Thunderbird has inserted the image into the composition, but to protect your privacy, the image will not be sent unless you change the 'Attach this image to the message' option in the image properties. This message is way too long. When the user gets the warning, they need to see 1) the file name, and 2) have the choice immediately of yes or no without having to search for some Thunderbird feature they probably have never used. Maybe just "Include the content of <the file name> when sending this message?"
Attachment #8796983 - Flags: feedback?(rkent) → feedback+
Comment on attachment 8796645 [details] [diff] [review] JK M-C part: Handling image insertion for APP_TYPE_MAIL_EDITOR (v3). Review of attachment 8796645 [details] [diff] [review]: ----------------------------------------------------------------- I did not review this code, but I have no objection to having a specialized editor type.
Attachment #8796645 - Flags: feedback?(rkent) → feedback+
(In reply to Kent James (:rkent) from comment #134) > This message is way too long. When the user gets the warning, they need to > see 1) the file name, and 2) have the choice immediately of yes or no > without having to search for some Thunderbird feature they probably have > never used. > > Maybe just "Include the content of <the file name> when sending this > message?" Actually I this part of the patch is more or less correct. The pasted content may include multiple images, some of them file:// so it's trivial to trick someone to just "click ok to get the job done" if you automate any of the steps. But it all just goes to show, it's a plan B solution if anything.
Thanks for the comments. A bit of a mid-air collision here, but I submit my comments anyway. When the user uses the image insertion dialogue, nothing will change, "Attach image" will be preselected. I would think that it is rather uncommon to *paste* a file-based image. So the extra friction should be acceptable. Besides, we have no way to decide whether a user-initiated paste including HTML with a file-based image is voluntary or the effect of an attack. I don't see how data URIs help us at all in the paste case, which is what this bug is about. In Magnus' approach, pasting HTML with a file-based image is simply not showing the image which is not what the user expects. Magnus hasn't addressed the paste aspect. As far as I know, he was going to try to change the order clipboard flavours are processed in M-C to prefer a bitmap for pasting, but that you only work if a single image were on the clipboard and not a longer HTML fragment including an image. How do we proceed here? Shall I ask for review for the M-C part? Shall I bring the C-C part to review quality? So according to comment #133 Kent agrees with comment #132 that in case of pasted images, the "Attach image" should *not* be preselected unlike for new image insertions? And in comment #134 he opts for a "just do it button". Which one is it? Addressing comment #134: Perhaps we could shorten the message, but I would advise *against* a "just do it button". The user should need to visit his image or images and give the OK. And comment #136: Sorry, but after all these months of looking at it, I still don't know what the "Plan A" solution is and how data URIs can help us with paste.
OK suggestion was: You've just pasted an image referencing a file. Thunderbird has inserted the image into the composition, but to protect your privacy, the image will not be sent unless you change the 'Attach this image to the message' option in the image properties. How about: To attach the pasted image referencing a file to the message, set 'Attach this image to the message' in the image properties. Or: Set 'Attach this image to the message' in the image properties to send the pasted image as part of the message.
Can Magnus and Kent please decide whether they want a "just do it button" or let the user visit the image "manually"? And perhaps Magnus can explain "Plan A" regarding paste and drag and drop, see below. And I forgot to answer: > What happen with drag and drop, which also inserts html content? Drag and drop of a single image inserts a data URI, try it now. Drag and drop of a larger fragment inserts the HTML of the fragment including any contained file-based image. Looks like I need another listener and I need to check whether dragged content is sanitised. Damn, I never tried dragging a larger segment.
Flags: needinfo?(rkent)
Flags: needinfo?(mkmelin+mozilla)
"set 'Attach this image to the message' in the image properties." As a typical user, I have no idea what the image properties are. Also in some cases the images are completely hidden, right, so how do you select the image properties? The "just do it" steps I would suggest are a dialog that has two choices "Attach file" and "Don't attach file", plus an Accept. So to accept is two steps, press "Attach File" then "Accept. This is meant for a case where the user was not expecting to be attaching a file, and attaching a file is something they understand.
Flags: needinfo?(rkent)
For me, drag an drop of an image inserts an invalid data uri. But that is probably another bug.
(In reply to Jorg K (GMT+2) from comment #138) > OK suggestion was: > You've just pasted an image referencing a file. Thunderbird has inserted the > image into the composition, but to protect your privacy, the image will not > be sent unless you change the 'Attach this image to the message' option in > the image properties. > > How about: > To attach the pasted image referencing a file to the message, set 'Attach > this image to the message' in the image properties. > > Or: > Set 'Attach this image to the message' in the image properties to send the > pasted image as part of the message. I believe it is critical that information on the file (at least its name) be given in the error message. You have to assume that the user has no idea what "image properties" are when they just wanted to insert an image, so I really dislike that. If you want them do do something, popup the dialog that allows it. I also do not think you can assume this is rare. This might be a standard part of some user's workflow, and the extra friction is going to be annoying.
(In reply to Kent James (:rkent) from comment #140) > As a typical user, I have no idea what the image properties are. Also in > some cases the images are completely hidden, right, so how do you select the > image properties? They could be hidden by CSS, but please remember, this bug is not about images, it is about extracting whatever document as part of an <img src=...>. So if the attacker wants to extract the list of the people you're bribing, this list will not display as an image. > The "just do it" steps I would suggest are a dialog that has two choices > "Attach file" and "Don't attach file", plus an Accept. So to accept is two > steps, press "Attach File" then "Accept. This is meant for a case where the > user was not expecting to be attaching a file, and attaching a file is > something they understand. Typically these dialogues have buttons, "Do it" and "Cancel", not radio buttons and "Accept". But anything is doable. We could certainly list all the files (plural) here: "Include the content of <the file names> when sending this message?" As for drag & drop of an image: Hmm, try dragging my logo here to a TB message. That works fine now and always has.
(In reply to Jorg K (GMT+2) from comment #143) > Typically these dialogues have buttons, "Do it" and "Cancel", not radio > buttons and "Accept". But anything is doable. How about a panel like this: === Include the content the following images when sending this message? [ ] lover-at-beach.jpg [ ] compromising-image.png [Accept] [Cancel] === We should only list images that M-C supports in rendering, so jpg/jpeg, png, gif (see kPNGImageMime, kJPEGImageMime, kJPGImageMime) and not the other documents like doc, pdf, odt, etc. There is also kNativeImageMime, and at least on Windows, FF renders BMP images.
Attached patch JK C-C part: WIP (v6). (obsolete) (deleted) — Splinter Review
In this patch: - Handle drag and drop as well as paste. The good news is that dropped content also arrives sanitised. - Changed image insertion so that for pasted images the attach checkbox is *not* automatically ticked (see comment #132). Next up: Dig out the image names from the pasted/dropped HTML fragment and present them to the user in a nice panel to tick and accept (see comment #144).
Attachment #8796645 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796645 - Flags: feedback?(acelists)
Attachment #8796983 - Flags: feedback?(mkmelin+mozilla)
Attachment #8796983 - Flags: feedback?(acelists)
Comment on attachment 8796645 [details] [diff] [review] JK M-C part: Handling image insertion for APP_TYPE_MAIL_EDITOR (v3). After some deliberation we'd like to introduce a "mail editor" app type as suggested by Daniel Glazman in comment #21. Its properties are described briefly in the IDL. Could you please review the minimal change this entails. Thank you. Given that M-C maintains an option for HTML editors like BlueGriffon and SeaMonkey, there shouldn't be a problem also maintaining an option for Thunderbird which has a wider user base than the other two mentioned.
Attachment #8796645 - Flags: review?(ehsan)
Attachment #8796983 - Attachment description: JK C-C part: Proposed solution (v5). → JK C-C part: WIP presented for initial feedback (v5).
Richard, what would be the best way to do a panel as described in comment #144? === Include the content the following images when sending this message? [ ] lover-at-beach.jpg [ ] compromising-image.png [OK] [Cancel] === Base it on a XUL <dialog>? Do we have something like this in the system? I saw some in the calendar. I can only find a lot of <prefwindow>s in the system. Where would be a good point to start?
Flags: needinfo?(richard.marti)
Actually, I had a better look and found some small ones like mailnews/base/search/content/viewLog.xul or mailnews/compose/content/askSendFormat.xul
Never mind, I'm using askSendFormat.xul as a starting point.
Flags: needinfo?(richard.marti)
Attached patch JK C-C part: WIP (v7). (obsolete) (deleted) — Splinter Review
In this patch: Dialogue that lists all files is presented to the user. Next up: When the user clicks "OK", set the moz-do-not-send attribute to "false" on the chosen images.
Assignee: mkmelin+mozilla → jorgk
Attachment #8798839 - Attachment is obsolete: true
Attachment #8798957 - Flags: ui-review?(richard.marti)
Attachment #8798957 - Flags: feedback?(rkent)
Comment on attachment 8798957 [details] Picture showing the file attach dialogue as proposed by Kent This dialog is directly before sending the message? What happens when I press "Cancel" or the close button? Will the message be sent without the images? If this is the case the "Cancel" button needs an other text or should be hidden and the "OK" button should have something like "Send Message" as text. For me the description text sounds wrong: "Include the content the following...". Should this be "Include *to* the content the following..." or "Include following images..."?
Comment on attachment 8798839 [details] [diff] [review] JK C-C part: WIP (v6). Review of attachment 8798839 [details] [diff] [review]: ----------------------------------------------------------------- ::: mailnews/compose/src/nsMsgCompose.cpp @@ +4254,5 @@ > +nsMsgCompose::AddMozDoNotSendFalse(nsString& aData) > +{ > + int32_t fPos; > + int32_t offset = -1; > + while ((fPos = aData.RFind(NS_LITERAL_STRING("file://"), offset)) != kNotFound) { Rolling out your own HTML parser, especially when fixing a security bug, is extremely dangerous. For example, if an attacker provides the following HTML and convinces people to paste it in their signature: <img src="file:///bad.png><span ">I win!</span> This code will turn it into: <img src="file:///bad.png><span " moz-do-not-send=false>I win!</span> and we lose. Note that I'm not bringing this up so that you can fix this one bug with this code and resubmit the patch. The reason why I'm bringing this up is to demonstrate that the basic approach is flawed. Do note that security researchers have looked at the patches that we land for security bugs for ages and depending on the nature of the patch, they may be able to decipher what the security bug was, and find more holes into the patch. Doing things such as parsing HTML yourself trying to add the moz-do-not-send attribute is just not going to work well, unless if you use a real HTML parser, serialize the source HTML into a DOM, perform mutations there and serialize back to an HTML string.
Sorry, mid-air collision, answer to Richard first. (In reply to Richard Marti (:Paenglab) from comment #152) If you apply the M-C patch and the C-C patch, you can try it out ;-) Maybe that would be best. Create yourself a page: <html><body> huhu<br> <img src="file://D:/Desktop/Bugzilla-down.png"><br> <img src="file://D:/Desktop/Dell%20Latitude%203150.png"><br> hihi </body></html> and copy its content from FF. The dialogue comes up immediately after you *pasted* or *dropped* HTML into/onto the composition that contains references for file:// based images. The images are always inserted into the composition, but if you don't select the ones you want and hit "OK", they will have no moz-do-not-send attribute set and thus won't be sent later since we default this to "true" now. If you hit cancel or close the dialogue, the images won't be sent either. (Mind you, the function behind the "OK" button is still missing.) Yes, sorry, the text is wrong, it was taken from Kent's suggestion in comment #134 Include the content of <the file name> when sending this message? and changed to Include the content of the following images when sending this message? but I messed up, "of" is missing. I don't find the message all that great, what is content of an image? We could say: Attach the following images when sending this message? but then people won't understand since they don't consider a (embedded) image in the HTML as an attachment (of course it is attached, but never shows as attachment). Maybe: Send the following images as part of the message? The window title also needs to change, currently "Attach Images to Message", perhaps: "Images referencing files detected". Any good ideas? Kent?
Comment on attachment 8796645 [details] [diff] [review] JK M-C part: Handling image insertion for APP_TYPE_MAIL_EDITOR (v3). Review of attachment 8796645 [details] [diff] [review]: ----------------------------------------------------------------- Sorry, this is a security bug, and I can't really sign off on this approach. The code changes are probably fine although I didn't spend a ton of time verifying that. I won't try to argue about, but I'm personally not comfortable signing off on this. Perhaps you can find another reviewer who would be open to r+ing this.
Attachment #8796645 - Flags: review?(ehsan) → review-
(In reply to :Ehsan Akhgari from comment #153) > For example, if an attacker provides the following HTML and convinces people > to paste it in their signature: > <img src="file:///bad.png><span ">I win!</span> Thanks for your interest, but I don't understand the comment. A signature is a file users store on disk, Thunderbird reads the file and adds the content to the compose window. I order that people don't have to change pre-existing signature files, we read the file and add the moz-do-not-send to it before placing the HTML into the compose windows. Where is the attack now? You want the attacker to convince the victim to modify their signature files? I know you're using TB, perhaps are you saying that the attacher is going convince the victim to change their HTML signature in the account settings? (I need to check that I add moz-do-not-send in this case.) I don't get the attack vector here. The security hole is that the attacker can get users to paste HTML referencing files, not only images, into their composition and the files will be sent. The security hole is not that the attacker can convince the victim to re-configure TB.
Comment on attachment 8796645 [details] [diff] [review] JK M-C part: Handling image insertion for APP_TYPE_MAIL_EDITOR (v3). Christoph, can you please review this. You added https://hg.mozilla.org/mozilla-central/rev/65911fba8069#l1.13 so you might be the right person to review this. BTW, could you adjust the user in your patches: Christoph Kerschbaumer <mozilla@christophkerschbaumer.com> doesn't seem up-to-date.
Attachment #8796645 - Flags: review?(ckerschb)
Comment on attachment 8798957 [details] Picture showing the file attach dialogue as proposed by Kent (In reply to Jorg K (GMT+2) from comment #154) > The dialogue comes up immediately after you *pasted* or *dropped* HTML > into/onto the composition that contains references for file:// based images. Then the dialog is good. > Maybe: > Send the following images as part of the message? > > The window title also needs to change, currently "Attach Images to Message", > perhaps: "Images referencing files detected". > > Any good ideas? Kent? This looks better, but let's decide Kent.
Attachment #8798957 - Flags: ui-review?(richard.marti) → ui-review+
Jörg, please don't steal other people's bugs without asking. Also, the only case the data:-uri approach is stalled is to worry about copying images from file:// based web sites. Still figuring that out, but even if we'd leave that broken it's way better than your approach. We should really just have landed that before summer and worried about the file:// based web sites issue later.
Assignee: jorgk → mkmelin+mozilla
Flags: needinfo?(mkmelin+mozilla)
Attached patch JK C-C part: WIP (v8). (obsolete) (deleted) — Splinter Review
This is my current state of work. I will stop now. I've adjusted the text of the message and removed some unused strings. I checked that in my patch I have *not* covered the case of <img src="file://D:/Desktop/Bugzilla-down.png"> in a HTML signature. (In reply to Magnus Melin from comment #159) > Jörg, please don't steal other people's bugs without asking. Last you commented on the bug before yesterday was on the 10th of June (!!) I have repeatedly asked you to explain your solution (supposedly Plan A) (see for example comment #118) and I stated in comment #122 that HTML can get into the composition in a few ways 1) Image insertion via the image insertion dialogue. 2) Images from a signature. 3) HTML inserted via the HTML insertion or add-ons that insert general HTML (like HTML editors). Also add-ons that explicitly add images, for example "signature switch" and other "template" add-ons. 4) The -compose switch with message=file (or body=) where the message content is taken from a file (or passed on the command line). 5) Pasted/dropped content. of which you have only covered 1) and 2).
Attachment #8798956 - Attachment is obsolete: true
(In reply to Kent James (:rkent) from comment #133) > Although I have no fundamental objection to a plan that requires us to use > data uris instead of file uris in messages, I think that we need to give a > lot of thought to the migration process for that I think you're overestimating the impact it would/could have compared to the other approach. The key thing is that the send-by-default exist no more in either approaches (for good reason). Also, security is not typically rolled out behind a pref, you just roll it out.
Carrying forward Richard's ui-r+ I hope the new strings are better.
Attachment #8798957 - Attachment is obsolete: true
Attachment #8798957 - Flags: feedback?(rkent)
Attachment #8799008 - Flags: ui-review+
Attachment #8799008 - Flags: feedback?(rkent)
(In reply to Jorg K (GMT+2) from comment #160) > I have repeatedly asked you to explain your solution (supposedly Plan A) > (see for example comment #118) and I stated in comment #122 that HTML can > get into the composition in a few ways > 1) Image insertion via the image insertion dialogue. > 2) Images from a signature. > 3) HTML inserted via the HTML insertion or add-ons that insert general HTML > (like HTML editors). Also add-ons that explicitly add images, for example > "signature switch" and other "template" add-ons. > 4) The -compose switch with message=file (or body=) where the message > content is taken from a file (or passed on the command line). > 5) Pasted/dropped content. > of which you have only covered 1) and 2). #3 is not an issue as add-ons would obviously have to adapt (in your solution too). It's easy to cargo-cult the JavaScript code needed for this. #4 didn't exist until a few days ago, there's no back-compat to worry about here. We can easily say that in the case they need images in there they simply data: uri them. #5 Pasted content work just fine, with the one exception of images with file:// based web sites. Dropped content works from there too already AFAIR, because they are already using data uris! The A-solution is to finish off what I started. Then no user interaction is needed for something they don't understand anyway. If we can't figure that out, maybe I should steal your pastelistener for that corner case...
Comment on attachment 8796645 [details] [diff] [review] JK M-C part: Handling image insertion for APP_TYPE_MAIL_EDITOR (v3). Review of attachment 8796645 [details] [diff] [review]: ----------------------------------------------------------------- In case it wasn't clear, I'm opposed to this. There's simply no reason to do this approach given there's a good alternative.
Attachment #8796645 - Flags: feedback-
(In reply to Magnus Melin from comment #163) > #5 Pasted content work just fine, with the one exception of images with > file:// based web sites. Dropped content works from there too already AFAIR, > because they are already using data uris! No, it doesn't see comment #139.
Dragging of fragments, how do you even do that? Dragging of images (which makes sense) works, like you wrote.
(In reply to Magnus Melin from comment #166) > Dragging of fragments, how do you even do that? See example in comment #154. You drag a little more than just an image. It's the same as paste as you can see from my patch.
Doesn't seem to do anything at all on linux at least.
(In reply to Magnus Melin from comment #168) Works fine in Windows: huhu + image + hihi gets dragged. (In reply to Magnus Melin from comment #159) > even if we'd leave that broken it's way better than your approach. Frankly, after all these months I haven't understood what is "good" or "better" about your approach of the data URIs. The arguments I've heard so far were: Comment #88: There's really not a solid solution around using data uris. You'll just play wack-a-mole, because is we use the editor as an editor it's a TRUSTED editor. We're not (going to), so we must play by the rules of the web, which means no file:// access. If you try to cheat you open an attack vector. E-Mail to TB Council of 27/09/2016 22:27 ... and it's the web thing to do anyway. To me, sending an e-mail is packing a bundle of data and shipping it out and it would be good to only ship what the user intended. Both solutions actually ship the same data, since data URIs are also changed to CIDs referencing an attachment. The idea is that the UI of the e-mail program should be easy to use and presenting *raw image data* is really not part of that. So I'm not convinced at all that your solution is better then mine, since the key point, not sending be default is the same, and of course, your idea. With that changed, it is irrelevant how the data is handled before shipping and IMHO data URIs make things worse rather than better.
(In reply to Magnus Melin from comment #168) > Doesn't seem to do anything at all on linux at least. On my Linux Mint 17.1 with Cinnamon, I can drag huhu+image+hihi to a TB 38.2 compose window with no problem.
(In reply to Jorg K (GMT+2) from comment #169) > E-Mail to TB Council of 27/09/2016 22:27 > ... and it's the web thing to do anyway. If you open a page <html><body> <div style="background-color:#eee;border:1px solid #000;padding:10px; height:200px;" contenteditable=""></div> </body></html> locally, that editor has access to local files. I don't understand why the TB compose window should behave any differently. So I'm asking for the felt 1000th time: Why are the data URIs right, good or even better that just showing the file-based image?
That page would have access to local files only as long as you're viewing it via file://. It works then because it's the same origin. Most of the web security model revolves around the same origin policy, and by using data URIs the data is accessible when needed so you don't have to break that fundamental security model by disabling the security checks. Naturally when you disable the security check you expose yourself to all kind of unexpected trouble, this bug being a prime example of that. Now, a web page editor doesn't do any kind of attaching of the data it references and the data is not sent anywhere, which is why a mail editor is so much different. Hope you got the answer you were looking for. Let me know if it's not clear.
I'm afraid it's not clear. This bug is about tricking users so that data that they didn't mean to send out is in fact sent out. My preference would be addressing this bug. The obvious solution is to not send anything by default but instead send only data that was explicitly requested: 1) Images inserted under user control. 2) Images from signatures inserted under program control (but also explicitly requested by the user since the configured their signatures). 3) Data inserted under user control using HTML or add-ons inserting HTML. For pasted content we will have the policy to "sanitise" pasted content, so that the "send this" directive gets stripped and nothing that is pasted is sent by default. We all agree that not sanitising as we currently do is wrong, and together with shipping by default, that's the attack vector we need to disable. These are the two cornerstones that both solutions have in common. I see no advantage in converting image data to data URIs for viewing purposes, since as we established, according to the "same origin policy" the FF browser and currently the TB compose window will show file-based images. And that's OK, as long as this data isn't shipped out. Or are you saying: I don't trust the Thunderbird software, somehow it will be possible that data is shipped out although it wasn't meant to be? (And that wouldn't happen when converted to data URIs first?) In your solution so far, paste simply won't work. The user doesn't see what they pasted (always referring to file-based images, of course). As far as I can see, we have no way to distinguish a voluntary paste from one that is part of an attack. So the best we can do is display a list of files and send those the user explicitly accepted. But there is no harm done in displaying all pasted content. Since you're planning to change the app type to "none", you can only view data URI images (and of course images with a source via http(s)). So if you were to give the user a view of the images they pasted, you'd have to convert them to data URIs as well, and they would then have the same problem of accidentally being shipped as if they were viewed from a file. You can also not fix the case where the pasted fragment is controlled by CSS with display:none and the user accepts the image when prompted. Repeating: How does converting images from local files to data URIs fix any issue? Which issue? Which fundamental security model am I breaking and which checks am I disabling when Firefox, assumed secure, currently shows me local images in a contenteditable?
(In reply to Magnus Melin from comment #172) > Which fundamental security model am I breaking and which checks am I > disabling when Firefox, assumed secure, currently shows me local images in a > contenteditable? OK, you're saying that the TB compose window doesn't have a file-based origin and therefore shouldn't access local files. The check we're disabling would be to show file-based images anyway. Got that. Please clarify further what advantages upholding the "same origin policy" in a program that serves as a local editor would bring other than avoiding "all kind of unexpected trouble".
(In reply to Jorg K (GMT+2) from comment #173) > I see no advantage in converting image data to data URIs for viewing > purposes, since as we established, according to the "same origin policy" the > FF browser and currently the TB compose window will show file-based images. Let's get things straight: Firefox shows it due to that same origin policy says ok, as long as it's a file:// based web site. Thunderbird compose displays it because it's set as app=EDITOR atm. > And that's OK, as long as this data isn't shipped out. Or are you saying: I > don't trust the Thunderbird software, somehow it will be possible that data > is shipped out although it wasn't meant to be? (And that wouldn't happen > when converted to data URIs first?) If all you need to do is somehow sneak in an attribute on the "image", that is clearly an attack vector. If you only use data: uris all the data is there already, and you couldn't have tricked the data to be there. The attack vector is gone. > Since you're planning to change the app type to "none", you can only view > data URI images (and of course images with a source via http(s)). So if you > were to give the user a view of the images they pasted, you'd have to > convert them to data URIs as well, and they would then have the same problem > of accidentally being shipped as if they were viewed from a file. No, because the data is already on the clipboard. The attacker can't put that there, while they can easily guess the name of a few files on my drive. It's not *me* who is converting to data uris (except for in the back-compat signature case). > Which fundamental security model am I breaking and which checks am I > disabling when Firefox, assumed secure, currently shows me local images in a > contenteditable? None, but that's why it also doesn't work once you put the same page on http:// - exactly because the same origin policy prevents that. It's not a very useful comparison though.
Mid air-collision, but I'll post this anyway since it goes with comment #174. And perhaps you can also give some references for "same origin policy" when applied to local files. I'm not a security expert, but I understand that this policy is there to avoid certain attacks where content is placed on different sites on the WWW. Maybe Christoph, who is still nominated as a reviewer of the patch that is "breaking the rules", can explain this.
(In reply to Magnus Melin from comment #175) > If all you need to do is somehow sneak in an attribute on the "image", that > is clearly an attack vector. Yes, all they need to do is "somehow" install some malware onto my machine, then take over the machine, install an add-on that goes around and sets moz-do-not-send=false on all the images in the composition. But hold on, they already have full access to the machine, so why do it the hard way and not simply ship out *all* data without guessing the file names first. Sure, this is an attack vector: - They guess the name of the file. - They get you to paste. - They somehow sneak in an attribute on the "image". *Very* unlikely. There are many a thousand times more likely attacks. > No, because the data is already on the clipboard. The attacker can't put > that there, while they can easily guess the name of a few files on my drive. > It's not *me* who is converting to data uris (except for in the back-compat > signature case). ... and for image insertion. I'd like to see your solution to the paste problem before I can comment further. As I said, if paste were to do anything useful, you've have to convert file-based images to data URIs.
(In reply to Jorg K (GMT+2) from comment #177) Sorry I forgot: > Sure, this is an attack vector: > - They guess the name of the file. > - They get you to paste. They persuade you not be be alerted by the message that is displayed: DO YOU WANT TO SEND THIS FILE??? > - They somehow sneak in an attribute on the "image". > *Very* unlikely. There are many a thousand times more likely attacks. Even more unlikely. What you're sacrificing is a semi-decent HTML editor just to get this one minuscule additional morsel of pseudo-security. There are a few much more important things to worry about in TB: Messages being sent to the wrong recipient due to faulty autocomplete and we have bugs where the wrong file is attached (fatal).
(In reply to Magnus Melin from comment #175) > If all you need to do is somehow sneak in an attribute on the "image", that > is clearly an attack vector. If you only use data: uris all the data is > there already, and you couldn't have tricked the data to be there. The > attack vector is gone. Is it? Please consider this: The attacker gets you to paste: <img src="file://C://Users/Magnus/Documents/private/important.doc"> (or equivalent for Linux). This *is* pasted into the composition (unless you do some processing on paste) and so far in your solution there isn't even a warning. Also, with app type "none" you don't even see a broken image. Now, in the same inexplicable way, you sneak your attribute onto the "image", and voilà, it is shipped out and no data URI was ever involved. What am I missing? As far as I remember your patch, you don't rip out sending when moz-do-not-sent=false altogether. Again, apart from destroying a semi-decent editor, data URIs ain't solving nothing yet.
Magnus, please answer: (In reply to Jorg K (GMT+2) from comment #173) > How does converting images from local files to data URIs fix any issue? > Which issue? The very unlikely attack vector of 'somehow sneak[ing] in an attribute' remains 100% in place. Upholding the "same origin policy" for a local editor seems purely academic, so therefore data URIs offer zero advantage over file:// access since they're only used for viewing in a voluntarily curtailed access model.
(In reply to Jorg K (GMT+2) from comment #177) > (In reply to Magnus Melin from comment #175) > > If all you need to do is somehow sneak in an attribute on the "image", that > > is clearly an attack vector. > Yes, all they need to do is "somehow" install some malware onto my machine, Of course not, once you can install malware it's game over. > Sure, this is an attack vector: > - They guess the name of the file. > - They get you to paste. > - They somehow sneak in an attribute on the "image". > *Very* unlikely. There are many a thousand times more likely attacks. Unlikely? What are you talking about?? That's the very scenario from this bug! It's very easy to guess the path for certain critical files on linux, e.g. your ssh keys are almost always in the same place. And paste is just one path to get content into the composer. You have drag'n'drop, forward (in various ways), replies, and probably a few more ways. All it takes is one little miss somewhere in those checks and you will have snuck in your phony image with attribute to include a file. (In reply to Jorg K (GMT+2) from comment #178) > What you're sacrificing is a semi-decent HTML editor just to get this one > minuscule additional morsel of pseudo-security. I don't see how this is really degrading anything, and what yo call pseudo-security is the very security cornerstone that the platform is built upon. (In reply to Jorg K (GMT+2) from comment #179) > The attacker gets you to paste: > <img src="file://C://Users/Magnus/Documents/private/important.doc"> (or > equivalent for Linux). > > This *is* pasted into the composition (unless you do some processing on > paste) and so far in your solution there isn't even a warning. Also, with > app type "none" you don't even see a broken image. Yes, but it's also not sending anything. All anybody can trick me to do is to send a broken link, and who cares about that. > Now, in the same inexplicable way, you sneak your attribute onto the > "image", and voilà, it is shipped out and no data URI was ever involved. No, because I made the attribute a no-op for file:// urls so there's no file attached. Only a broken link. > What am I missing? As far as I remember your patch, you don't rip out > sending when moz-do-not-sent=false altogether. Yes it's preserved so you can choose to include images from http inline if you like. But it's ONLY http. > Again, apart from destroying a semi-decent editor, data URIs ain't solving > nothing yet. It changes the editor surprisingly little, and like I've written it solves all the security issues that comes from the bad design of letting an attribute include a random file on send.
(In reply to Magnus Melin from comment #181) > > Sure, this is an attack vector: > > 1) They guess the name of the file. > > 2) They get you to paste. > > 3) They somehow sneak in an attribute on the "image". > > *Very* unlikely. There are many a thousand times more likely attacks. > Unlikely? What are you talking about?? That's the very scenario from this > bug! It's very easy to guess the path for certain critical files on linux, > e.g. your ssh keys are almost always in the same place. And paste is just > one path to get content into the composer. You have drag'n'drop, forward (in > various ways), replies, and probably a few more ways. All it takes is one > little miss somewhere in those checks and you will have snuck in your phony > image with attribute to include a file. The "very scenario" are parts 1) and 2) which meet faulty software. No argument that the software needs fixing. The very unlikely part is number 3) which could only be done via another software fault. So you don't have any faith in the software, that's why you want to do a "clean sweep" approach. BTW, you don't touch replies or forwards as they are already covered by code that you apparently don't trust in https://dxr.mozilla.org/comm-central/rev/75d461c3461613bb44fa1373240f1d4197895023/mailnews/compose/src/nsMsgCompose.cpp#468 > No, because I made the attribute a no-op for file:// urls so there's no file > attached. Only a broken link. I missed that in the patch then, it's been a while, let me see, four months ;-( Sorry, but you can't do that without withdrawing even more functionality: Do this: - Open a compose window - Insert > Link. Chose a file. Notice the "Attach the source of the link to the message" When you do this, a link to the file is inserted, and the file is attached. The recipient can click the link and the file opens. Are you going to rip this out or are you intending to change general files to data URIs too? > ... bad design of letting an attribute include a random file on send. That's in the eye of the beholder. If the attribute is correctly controlled, I see no problem. Software also controls where the message is sent to, and as mentioned, faulty software has led to messages being sent to the wrong recipient with one documented case of a $50.000 financial loss as a consequence. So do we therefore stop sending messages or remove the error-prone autocomplete? You need to see this problem here in proportion. But slowly your line of argument becomes clear. Main argument: bad design of letting an attribute include a random file on send - since if you get this wrong, an undesired file will be shipped. That's driven by distrust in the software in general. Fix: Make moz-do-not-send a no-op for file:// URLs. Consequence: Turn necessary file references into data URIs. May I ask why you want to stop being an EDITOR app then? Users could paste file based references as much as they like, with or without sanitising, since you'd never ship out any file-based stuff. I don't want to think this further, but just as a hint: Showing the paste/drop message I've implemented would give the user the chance to see what they pasted and you can then turn the selected content into data URIs. You still need to trust your software, since if you convert the wrong file, ... well, you know what happens. With making moz-do-not-send a no-op for file:// URLs, why do you need to sanitise and why do you need to revert the default at all? One thing just occurred to me: If you paste HTML with <img src="http://...> into your composition, the current default behaviour is to attach those images. Is this intended to change? I believe it would change in my patch, so I'd have to revisit that.
(In reply to Jorg K (GMT+2) from comment #182) > When you do this, a link to the file is inserted, and the file is attached. > The recipient can click the link and the file opens. Are you going to rip > this out or are you intending to change general files to data URIs too? Looks like your patch from June, which I hadn't memorised, already does that. So you'd haul in a 25 MB PDF attachment into the DOM, right? That will go down real well with editing, editing the HTML (using an add-on) and it will also affect the sending pipeline where the editor DOM, now including a 25 MB PDF, is serialised to text representing the body of a message, and this body is repeatedly copied from here to there, charset-converted, written to a temporary file, read in again, written out, etc. IIRC from the Asian crisis, every message passes through two files (nsemail.html and nsmail.tmp, I actually had to analyse them to detect the source of the superfluous spaces). Comparing this to simply reading in a file at attachment time you're causing a major performance hit which you haven't even considered. Or have you? Can I see the analysis then.
On the same note I can just imagine that system administrators in an enterprise context will not appreciate very much that you're ripping out the mail.compose.dont_attach_source_of_local_network_links processing. So where the employees were drilled not to attach a 25 MB document from a server but instead send a file link, you now just attach the file anyway since the link is turned into a data URI and that is turned into an attachment. I was going to write about broken porcelain before, but due to the etiquette I removed this wording. Now thinking it through, your approach seems more and more damaging: - damage HTML composition - performance hit in the sending pipeline - replication of server based documents. And all this, to fix a paste problem due to faulty default processing. Frankly, I don't see the proportion. It may change the "editor surprisingly little" (your comment #181) but it has other undesired side effects.
Attached patch JK C-C part: WIP (v9). (obsolete) (deleted) — Splinter Review
I said that I'd stop but I just wanted to fix some issues. In this patch: - Changed default for moz-dont-not-send to true only for file URIs. Images with src="http://" still get attached to maintain existing behaviour. Issue detected in comment #182. - In the discussion it became clear that it's also valid to paste links containing file references and not only images. So this patch caters for these, too. Thunderbird supports adding links to files and shipping the files as attachment, so why should one not be able to copy such a link to a different message. However, the href attribute is sanitised away, so there is not much point to this. Maybe we shouldn't rely on M-C sanitising but do our own. Or silently drop all references to files via links? - Finally it fixes the issue that moz-do-not-send wasn't set for HTML signatures directly configured in the account settings (detected in comment #156, copy/paste error).
Kent, should this approach go ahead, there are two options: 1) Only process images on paste as shown in the other screenshot. 2) Process images and general files linked to the composition via a link/anchor. In this case, we need to remain an EDITOR app, since M-C is sanitising away the href attribute. We'd need to do our own sanitising on the pasted content. Of course that would save us the discussion with the M-C people. It could be interesting in an enterprise environment where people send "attachments" via file references to a server, like so: Hi Paul<br> take a look at my latest draft, <a href="file:////sever/salesdocs/klaus/sales/draft.odt">see here</a>.<br> Greetings, Klaus.
Attachment #8799254 - Flags: feedback?(rkent)
This is an interesting security bug. Thanks Jorg for working on it. But it is hard for me to follow this discussion as I am not familiar with the area. I'll better unsubscribe now.
(In reply to Jorg K (GMT+2) from comment #182) > The "very scenario" are parts 1) and 2) which meet faulty software. No > argument that the software needs fixing. The very unlikely part is number 3) > which could only be done via another software fault. So you don't have any > faith in the software, that's why you want to do a "clean sweep" approach. You realize "very unlikely" is exactly this bug? So it already happened at least once, which makes your comment simply not true and repeating it doesn't make it more so. Software will always have bugs, that's the reality. > BTW, you don't touch replies or forwards Yes because there's no reason to. > May I ask why you want to stop being an EDITOR app then? Users could paste > file based references as much as they like, with or without sanitising, > since you'd never ship out any file-based stuff. I want the sanitizing, I want the added security. There's no point showing images in the editor when they won't show to the recipient anyway. It's convenient to just let the policy handle that, showing a broken image. > With making moz-do-not-send a no-op for file:// URLs, why do you need to > sanitise and why do you need to revert the default at all? Because we don't want anyone but the user deciding if he/she wants to include or not (this requires sanitize): e.g. we don't want a default that would let an attacker include a http page at random. Say http://intranet/ ... which is a slightly smaller problem, but still certainly a problem. . And it's a smaller message without superficial includes.
(In reply to Jorg K (GMT+2) from comment #186) > It could be interesting in an enterprise environment where people send > "attachments" via file references to a server, like so: I really doubt they do. People will either include the file as attachment, or just paste the path to it (as text). Anyway, the pref is obsolete since not attaching is the default. My patch just need a one line change in the dialog code not to convert for the link case.
Another mid-air collision ... I'll post it anyway. (In reply to Jorg K (GMT+2) from comment #185) > Maybe we shouldn't rely on M-C sanitising but do our own. In my solution we'd have to visit pasted content in the DOM anyway to set moz-do-not-sent=false on the files that the user chose, it's easy to set 'true' on the other ones. Magnus, do you have a comment on the issues raised in comment #182 through to comment #184. What happens when the user adds a link to a 25 MB PDF? That's loaded into the DOM, right? And the enterprise users which may chose to send file URLs without attaching the files since they point to local servers, what about them? Of course, like always, we have no data the prove that this feature is used or not used. Or maybe those would use an http://intranet/ reference. (In reply to Magnus Melin from comment #188) > It's convenient to just let the policy handle that, > showing a broken image. Have you tried? I think to see no image, which is not the best user experience. Anyway, maybe you're working on some sort of paste solution. Also, what about images from http(s) sources. Default behaviour now is to attach those. If I read your last patch correctly, this is going to change, or are you adjusting that?
(In reply to Jorg K (GMT+2) from comment #190) > In my solution we'd have to visit pasted content in the DOM anyway Which is not super. Yes we're at least partly protected due to no javascript but as a rule you shouldn't put anything in the dom that you don't trust. > Magnus, do you have a comment on the issues raised in comment #182 through > to comment #184. What happens when the user adds a link to a 25 MB PDF? 25M docs aren't really that common, and you can't usually send that large mails anyway. We can let the user choose and default to send just a link for the link case. One line change. > experience. Anyway, maybe you're working on some sort of paste solution. Yes. It would go faster without all the questions ;) > Also, what about images from http(s) sources. Default behaviour now is to > attach those. If I read your last patch correctly, this is going to change, > or are you adjusting that? No, the default should be not to send for http too, like I wrote in my previous comment.
(In reply to Magnus Melin from comment #191) > Yes. It would go faster without all the questions ;) To that I can only say: If you had written a little essay about all the aspects of your solution right as the start as I requested about 1000 times, we could have understood your solution so much faster. Let me summarise what you should have written in about comment #39, we're at 192 here. The basic idea is an attribute on an DOM node shouldn't decide about sending content referenced by this node. Reason: Processing can go wrong and referenced content is sent by accident. Conclusion form that: 1) Pull all the data that needs to be sent into the DOM as data URIs under program control. 2) Stop being an EDITOR, so paste will receive sanitised content. 3) Switching the default to "do not send" 4) Make moz-do-not-sent a no-op for file-based references To solve the file-based problem 2)+3) *or* 4) would be sufficient, but to also protect data from http://intranet/... resources, you want 2)+3) *and* 4). Not being an EDITOR any more also makes the data URIs necessary, since otherwise file-based images won't show. I hope I'm reflecting your reasoning correctly and if you can show me a comment where you've explained it clearly (instead of saying "it's the web thing"), I will take the blame for asking too many questions. As I said many times before, your brief answers at times confuse more then they help. If course I can achieve all the above without stopping being an EDITOR or a MAIL_EDITOR and without the data URIs, but of course there would be more potentially error-prone C-C code necessary.
Christoph, to give a bit of background here: There are two approaches considered here, Magnus approach, which I described in comment #192 and my approach which achieves about the same, but without using the data URIs and without stopping being an "editor app" of some sort. As you can see, I've asked you to review the introduction of a new app type that will be able to access file-based images, but will receive sanitised paste content. I don't think will take long to review the trivial changes, what is more important is what you think about it as a security expert. That said, I find Ehsan's r- a little surprising since he said in comment #155: === Sorry, this is a security bug, and I can't really sign off on this approach. The code changes are probably fine although I didn't spend a ton of time verifying that. I won't try to argue about, but I'm personally not comfortable signing off on this. Perhaps you can find another reviewer who would be open to r+ing this. === To me that results in a cancellation of the review but not an r-. There is another issue: If I try to paste a <a href="file://...>the file</a> into a contenteditable in Firefox, the href gets stripped that thus the link is lost. Is that a feature or a bug? I tried in Chrome and the href does get pasted. Looking at: https://dxr.mozilla.org/comm-central/rev/e8fa13708c070d1fadf488ed9d951464745b4e17/mozilla/dom/base/nsTreeSanitizer.cpp#184 href is actually an attribute that shouldn't be sanitised away. I my approach I need the href to come through otherwise the new "mail editor" app type is no good to me and I'd have to remain a "full editor" and do the sanitising in the paste callback (which I'd love to avoid). Perhaps my patch is not complete and it needs another tweak to get the href and still receive the rest sanitised. In current Thunderbird the compose window being a "full editor" does receive the href.
Flags: needinfo?(ckerschb)
Flags: needinfo?(ckerschb)
Comment on attachment 8796645 [details] [diff] [review] JK M-C part: Handling image insertion for APP_TYPE_MAIL_EDITOR (v3). Review of attachment 8796645 [details] [diff] [review]: ----------------------------------------------------------------- Jorg, thanks for the summary in comment 193. Unfortunately I am not a docshell peer and I simply don't know the implications of that change, hence I don't feel comfortable reviewing that changeset. Even though I don't like putting more work on smaug, he is probably the best person to ask for help and review.
Attachment #8796645 - Flags: review?(ckerschb) → review?(bugs)
I think I like the approach, but figuring out whether the callers of TextEditor::IsSafeToInsertData expect this new behavior isn't trivial. Jorg, did you go through *all* the callers of TextEditor::IsSafeToInsertData to verify the patch works the expected way?
Flags: needinfo?(jorgk)
Though, the issue with TextEditor::IsSafeToInsertData would be that we'd be possibly too strict in some cases, so at least from security point of view, that is better place to be. But still, better to go through all those callers.
(In reply to Jorg K (GMT+2) from comment #193) > There is another issue: If I try to paste a <a href="file://...>the file</a> > into a contenteditable in Firefox, the href gets stripped that thus the link > is lost. Is that a feature or a bug? I tried in Chrome and the href does get > pasted. I dug this out. The href is removed here: https://dxr.mozilla.org/comm-central/rev/e8fa13708c070d1fadf488ed9d951464745b4e17/mozilla/dom/base/nsTreeSanitizer.cpp#1318 Error returned from NS_NewURI(getter_AddRefs(attrURI), v, nullptr, baseURI); is 0x805303f4 which is NS_ERROR_DOM_BAD_URI. baseURI is |about:blank| and attrURI is |file:///D:/Desktop/BVG%20Preise%202016.pdf| in my test case *after* the call returned. Does this look like a bug or is this intentional?
(In reply to Olli Pettay [:smaug] from comment #195) > Jorg, did you go through *all* the callers of TextEditor::IsSafeToInsertData > to verify the patch works the expected way? I've been lazy. We know that for app type EDITOR, which the TB compose windows is now, we see file-based images and we don't get sanitised content. In in the two spots were app type EDITOR is mentioned in the context of images, I added my new app type "MAIL EDITOR" and I can successfully see the file-based images now. TextEditor::IsSafeToInsertData() has a third reference to APP_TYPE_EDITOR, so I figured that that's where the sanitising is skipped for the EDITOR app type. Since we want sanitising, or so I thought until I saw that the href is sanitised away, I didn't look at the callers of TextEditor::IsSafeToInsertData() at all. To me, there are two problems here: If we were to create a MAIL EDITOR app type with this patch, I'm sure I've covered the file-based image access. The second problem is the unwanted sanitising of the href which I looked at in comment #197. So should I look at the callers of TextEditor::IsSafeToInsertData() for my "oops, href gone" problem or for the image access? Please clarify. Also please note that we're at comment #198 which is due to the fact that Magnus doesn't like the MAIL EDITOR approach. He wants to just stop being any editor at all and pull in images as data URIs as outlined in comment #192. So I think the approach needs to be this: First we need to decide whether M-C will tolerate a MAIL EDITOR app type. Ehsan wasn't a great friend of this idea. If so, the patch I presented should fix the file-based image access problem. TextEditor::IsSafeToInsertData() and "oops, href gone" are a secondary problem. I could even put the href back in C-C code. Maybe we should meet on IRC to sort this out quicker.
Flags: needinfo?(jorgk)
Comment on attachment 8796645 [details] [diff] [review] JK M-C part: Handling image insertion for APP_TYPE_MAIL_EDITOR (v3). I had a long conversation with Olli on IRC. Here a brief summary: 1) The patch is OK from a Gecko standpoint, however, Olli wants us to check that the change behaviour in TextEditor::IsSafeToInsertData() doesn't have any undesired effects on TB. A desired effect is of course the additional sanitising for pasted content. 2) Olli expressed concern about the use of data URI from a memory usage point of view. On low-end machines loading images and attachments into the DOM may use too much memory. 3) He suggested instead to introduce a new URI scheme. This was already suggested by Jim in comment #94 and preceding comments. BTW, revisiting comment #81, Jim wasn't a great friend of the data URIs. 4) The issue of the "oops, href gone" is related to bug 482909 and we should consult Henri Sivonen (which I will do in the next comment). I'm clearing this review for now until the TB team have decided which approach we're going to take, data URIs or MAIL EDITOR (or even remain an EDITOR if the href sanitising (see comment #197) can't be resolved satisfactorily).
Attachment #8796645 - Flags: review?(bugs)
Hooray, comment #200 is mine!! Henri, I'm terribly sorry to drag you into a complicated bug at comment #200. However, the question is very simple. Please take a look at comment #197: If you paste a <a href="file:// ..."> into a contenteditable, href="file:// ..." is removed during sanitisation, so the link is lost. The contenteditable is in a page loaded from a file. Chrome and IE don't do that. I didn't debug it in FF, but I'd assume the baseURI would be my test case file (file:///D:/Desktop/Mozilla%20bugs/HTML/contenteditable.html). This can also be seen in TB(*) where I did debug it and the baseURI is |about:blank|. Your thoughts would be welcome. (*) I patched TB: I stopped being an EDITOR app type so it receives sanitised content on paste, and I expected href *not* to be stripped.
Flags: needinfo?(hsivonen)
Further to comment #200. I've debugged it in FF now. Comment #197 wasn't quite right. Here are the facts: I'm pasting <a href="file:///D:/Desktop/BVG%20Preise%202016.pdf"> into a contenteditable in my local test case. baseURI: |file:///D:/Desktop/Mozilla%20bugs/HTML/contenteditable.html| attrURI: |file:///D:/Desktop/BVG%20Preise%202016.pdf| 0x805303f4 returned from rv = secMan->CheckLoadURIWithPrincipal(sNullPrincipal, attrURI, flags); at https://dxr.mozilla.org/comm-central/rev/e8fa13708c070d1fadf488ed9d951464745b4e17/mozilla/dom/base/nsTreeSanitizer.cpp#1315 Looks like the baseURI doesn't really matter here. Bug or feature? Chrome and IE don't strip the href and don't destroy the link upon paste.
(In reply to Jorg K (GMT+2) from comment #199) > 2) Olli expressed concern about the use of data URI from a memory > usage point of view. On low-end machines loading images and attachments > into the DOM may use too much memory. This needs to be put in perspective: a common limit for over all mail size is 10M, with gmail at 25M. That's the *maximum* you would ever be able to send at any occasion. Maybe there's a slight overhead, but in the end if your machine is so low-end it can't handle 10 megabytes in memory, things aren't going to work out. That simply can't be the design goal.
If you have images, you already have probably the encoded and decoded versions in memory, and data url would add yet another version (taking possibly quite a bit memory). So overall memusage may end up quite high.
I've moved the href sanitising issue to bug 1309058. We already have enough discussion here ;-)
Flags: needinfo?(hsivonen)
(In reply to Olli Pettay [:smaug] from comment #203) > If you have images, you already have probably the encoded and decoded > versions in memory, and data url would add yet another version (taking > possibly quite a bit memory). So overall memusage may end up quite high. There is overhead, but why do you think it matters when the data amounts are still small? "Quite high" is relative. I'd also like to hear how(if) you can justify mixing origins and letting files sneak out unless we're really careful. Paste is just one method of putting content into the message.
Flags: needinfo?(bugs)
I think the priorities seen in a number of previous comments are wrong when it comes to security vs. UI & data: URLs. The top priority should be to put an end to the vulnerability in a timely fashion. Looking at what has been landed and on which branches, it looks to me like no mitigation has landed on the current Thunderbird release branch. Am I reading correctly? The difference between the reporting date and today's date is unreasonably large if indeed no mitigation has shipped yet. (In reply to Magnus Melin from comment #11) > - on paste (even for app=mail), set moz-do-not-send=true for file: urls Storing an ephemeral security-sensitive property in a content attribute seems like a bad idea in the first place. This should probably be a kind of flag on the C++ node that's not exposed for writing via the means the Web provides (parsing HTML or setting something via JS). Making that kind of change in a timely manner may not be feasible, though. (In reply to Jorg K (GMT+2) from comment #30) > Surely hell will break lose if suddenly showing pictures in signatures stops > working. Breaking people's signatures is not cool, but letting this vulnerability go unaddressed for an extended period of time is way worse. If this bug can't be fixed in a timely manner without breaking people's signatures, I think the right thing to do is to address the vulnerability ASAP even if the band-aid breaks people's signatures. (In reply to Jorg K (GMT+2) from comment #36) > What problem are we trying to solve here? The problem is that file: URLs in the message composition DOM are super-dangerous unless they have trusted provenance, but Thunderbird does not have the means of tracking their provenance. Since Thunderbird is unlikely to be able to develop a means of tracking the provenance of file: URLs in a timely manner, it is reasonable to solve the problem by 1) not letting file: URLs end up in the message composition DOM intentionally and 2) not to dereference the ones that have ended up there somehow (i.e. unintentionally). > I must say that I am not thrilled at all about the data URIs in the image > properties. Considering the mechanisms that Thunderbird has available in the form of the DOM, in order to avoid having to track the provenance of file: URLs, it is completely reasonable to convert intentional insertions of local files into data: URLs at the time of insertion, which removes the need for provenance tracking. It is unfortunate that this doesn't work nicely with the current UI, but I think it would be better to hide the URL from the UI than to keep doing something as dangerous as dereferencing file: URLs that have ended up in the DOM when you don't know how they ended up there at the time of dereferencing. If you want to allow users to specify a signature that contains file: references, it follows that to avoid having to track the provenance of those file: URLs in the message composition DOM, the file: references should be dereferenced and converted into data: (or cid:) URLs before the signature is inserted into the message composition DOM. The same thing applies for other methods of the user injecting explicitly-trusted HTML source. (In reply to Jim Porter (:squib) from comment #81) > Do you know what happens with drafts? When we save a draft, we convert from > file: URLs to attachments (possibly with cid: URLs), correct? No valid draft > should have a file: URL, right? I don't know what currently happens, but it's not OK to trust file: URLs serialized into drafts, because the UI makes it possible for the user to move an untrusted message into the drafts folder and open it. (It doesn't matter if such a move is rare--the app should still make sure it's not a vulnerability.) (In reply to Jorg K (GMT+2) from comment #90) > For example, people who have a > 30KB image in their signature don't want to attach it to every message, so > they have <img moz-do-not-send="true" > src="http://mysite.com/images/sig-pic.png"> in their signature. Such an external reference from email is a privacy problem for the recipient. I think it should not be a goal for Thunderbird to facilitate the authoring of such privacy-problematic beacons. (In reply to Jorg K (GMT+2) from comment #92) > Some people (and may add-ons) use the compose window as an HTML editor. Sometimes, you have to break the spacebar-heat-as-control guy's (https://xkcd.com/1172/) workflow to fix a *security vulnerability* for *all users*. (In reply to Magnus Melin from comment #106) > 1) we're not a web page editor Indeed! (In reply to Jorg K (GMT+2) from comment #200) > If you paste a <a href="file:// ..."> into a contenteditable, href="file:// > ..." is removed during sanitisation, so the link is lost. The > contenteditable is in a page loaded from a file. Chrome and IE don't do > that. I didn't debug it in FF, but I'd assume the baseURI would be my test > case file (file:///D:/Desktop/Mozilla%20bugs/HTML/contenteditable.html). By the time you paste, the sanitizer doesn't know the provenance of the file: URL, so it errs on the side of removing it. The focus is on being a secure client for rendering the Web. Loading Web-tech content from the local disk is an ancillary capability and didn't drive the design of the sanitizer. I'll comment further over in bug 1309058.
Wow, Henri, you really read through the whole bug ;-) And made a case for the use of the data URIs. You're observation is correct. Sadly, nothing has been landed apart from https://hg.mozilla.org/mozilla-central/rev/335006a543ef which would cause moz-do-not-send to be sanitised away for a non-EDITOR app type.
The list of obsolete patches is long enough to be confusing. However, attachment 8741489 [details] [diff] [review] which switches us to data uris only is basically landable. The only case it breaks is pasting images from file:// based web sites - which we can assume is rare. It's unclear if that's completely fixable or not at the moment.
It also breaks pasting links <a href="file:// ...> from one e-mail to another. Rare or not, I do not know. And didn't you say that file link insertions needed a tweak (comment #189) and you're working on mitigating the paste a little? Henri, I appreciate your statement that this should have been fixed much earlier. But since four months have passed without action, this is obviously not considered super urgent. The next ESR release is in March, and the next branch day is in four weeks, so there is still a bit of time. I doubt that we will be able to retrofit this into the current TB 45.x ESR.
(In reply to Magnus Melin from comment #205) > (In reply to Olli Pettay [:smaug] from comment #203) > > If you have images, you already have probably the encoded and decoded > > versions in memory, and data url would add yet another version (taking > > possibly quite a bit memory). So overall memusage may end up quite high. > > There is overhead, but why do you think it matters when the data amounts are > still small? "Quite high" is relative. > > I'd also like to hear how(if) you can justify mixing origins and letting > files sneak out unless we're really careful. Paste is just one method of > putting content into the message. FWIW, as comment 199 said, I suggested adding a new uri scheme. All the explicit file:/// references would prevented and there wouldn't be any extra memory usage. Use of data: urls feel like a hack to me. Perhaps acceptable temporarily, but I'm quite worried about the memory use, which is already high enough with TB.
(In reply to Jorg K (GMT+2) from comment #209) > It also breaks pasting links <a href="file:// ...> from one e-mail to > another. It seems appropriate, even necessary not to allow emails to have that kind of links. > And didn't you say that file link > insertions needed a tweak (comment #189) and you're working on mitigating > the paste a little? I'm not working on anything related to this. (In reply to Olli Pettay [:smaug] from comment #210) > Use of data: urls feel like a hack to me. Perhaps acceptable temporarily, > but I'm quite worried about the memory use, which is already high enough > with TB. Considering that a vulnerability persists in the mean time, I suggest landing a conversion to data: URLs and then addressing memory usage once the vulnerability time window has been closed.
I'll work on getting my patch polished soon yes. Re ESR: yes we need to patch that at the same time this lands on trunk/branches. It's not like it's hard to figure out from the code what's going on - so otherwise you have an attack window of half a year. That we need it on ESR means no string changes. Re custom protocol: doesn't sound all that feasible to do. In a longer run we could use blob: urls but it's way to hard to do with the current (very messy) cpp code that's responsible for sending. In an all-js world that would be pretty trivial.
(In reply to Henri Sivonen (:hsivonen) from comment #211) > It seems appropriate, even necessary not to allow emails to have that kind > of links. Sorry, this is existing behaviour. In a Windows environment we even have provision not to attach files which live on a server. > I'm not working on anything related to this. Of course not, this was directed to Magnus and his comment #189 and comment #191 where he talks about further work he's doing. I'd appreciate if you could look into bug 1309058 (and clear any inappropriate NI there as well). > Considering that a vulnerability persists in the mean time, I suggest > landing a conversion to data: URLs and then addressing memory usage once the > vulnerability time window has been closed. Note that other suggestions have been made to close the vulnerability. However, they are not as "pure" as removing file URIs from the composition.
How is custom protocol much harder than use of data: urls? You anyhow need to convert from file:/// to some other url. And I wouldn't use blob: urls, but simple foobar url mapped to file url.
Flags: needinfo?(bugs)
Because data uris works out of the box for viewing and reading as data. Inventing something custom is bound to be error-prone, and that's something mostly undesired in this area. Besides a slight temporary increase in memory I just don't see any issues with data-uris (and I say slight, b.c. a typical web image is maybe 100K which is what people likely send around). There's also the larger issue that we're trying to move to web-tech only (will take years, but still) and it's quite unclear to me if that would be workable with a custom protocol.
(In reply to Magnus Melin from comment #212) > Re ESR: yes we need to patch that at the same time this lands on > trunk/branches. It's not like it's hard to figure out from the code what's > going on - so otherwise you have an attack window of half a year. That we > need it on ESR means no string changes. Landing this on TB 45.n would mean that upgrading users of TB 45.(n-1) would see their current workflows (Kent likes to call it that) smashed with the click of the upgrade button. We would give zero chance to add-ons which will break for sure. Here a few numbers: Signature Switch: 87,582 users, SmartTemplate4: 20,309 users, Stationery: 37,936 users, Shrunked Image Resizer: 8,730 users (that resizes image and inserts file URI). If you want to do that, IMHO you rule out data URIs. Even changing the "do send" default for http(s)-based images is questionable, since users rely on the fact that they send a "complete" e-mail with images included and not references to external sites which will be blocked at the receiving end, at least by TB.
If we prefer we can land a minimal rough fix for ESR: enable sanitation, and default sending to off. But I don't think it's conceivable to fix this bug without any disruption to certain add-ons. The minimal fix is suboptimal though, e.g. images inserted by (now broken) add-ons could be showing although they wouldn't get sent. Since they need to change some, might as well make them prepared for what's coming (code wise it's not a big deal to change if you're changing it). Anyway, let's focus on getting a patch for trunk before we worry about that.
My suggestion would be to land the same basic fix on all branches and then move further work to another non-secure bug. That would basically be my patch which is not complete yet. The OK button on the panel doesn't do anything yet. I also think we should do the "not super" sanitisation ourselves since app type MAIL EDITOR also doesn't do what we need for pasting anchors. The string change problem should be addressed by using existing strings for the panel: chooseFileToAttach=Attach File(s) or <!ENTITY attachFile.label "Attach File(s)…"> As for switching the default to "don't send" even for http(s)-based images: Well, say someone copies something from some intranet into an e-mail relying on the pictures being attached as we do now. If we change that, the recipient will receive (blocked) links, and even when unblocking, they won't see anything.
Attached patch JK proposed solution (v10). (obsolete) (deleted) — Splinter Review
Given the severity of the problem, there's been surprisingly little activity here as far as patches are concerned. Here I'm presenting my solution, you can tear it to shreds now. Key points: - Default switched to moz-do-not-send=true for file-based content only. That could be extended to all pasted content, also from http:// to protect against extraction of data from intranets. - Home-made sanitisation (without new app type MAIL EDITOR). - A panel that prompts the user which of the pasted content they want to ship out. - Signatures processed adding moz-do-not-send=false to automatically include contained images. - Image/Link properties dialogue tweaked so non-existing moz-do-not-send is defaulted to 'true' and 'false' is still pre-populated for new insertions. I haven't switched this to using pre-existing strings for ESR45 yet (see comment #218). Breakage of add-ons: Add-ons which place images or anchors need to set moz-do-not-send=false on them. Add-ons which add HTML need to include moz-do-not-send=false in the HTML they add.
Attachment #8796645 - Attachment is obsolete: true
Attachment #8796983 - Attachment is obsolete: true
Attachment #8799006 - Attachment is obsolete: true
Attachment #8799008 - Attachment is obsolete: true
Attachment #8799250 - Attachment is obsolete: true
Attachment #8799008 - Flags: feedback?(rkent)
Attachment #8800734 - Flags: feedback?(rkent)
Jörg, I really hate to break existing users of addons in the middle of an esr with no mitigation strategy. Do you have any suggestions for a recommended mitigation? Like, if the fix is clear can we get he addons fixed ASAP in time for our ESR? Or could we write a simple addon that we could offer that would allow some sort of fix?
I hope that we all agree that my approach does less damage than the data URIs since the user can simply adjust the missing attribute. What the damage is, depends on the add-on. Let's see: Signature Switch: 87,582 users: Here the users just have to manually update their signatures to include moz-do-not-send=false. SmartTemplate4: 20,309 users, Stationery: 37,936 users: I don't know about SmartTemplate4, you'd have to ask Axel. Stationary is like Signature Switch, users need to update the attribute in their templates. Shrunked Image Resizer: 8,730 users (that resizes image and inserts file URI): This really inserts a file URI pointing to a temp file. Given that the author is a TB/calendar contributor, this would be fixed quickly. Of course users could adjust the image properties in the meantime. We could of course produce some CSS that shows are images which won't be shipped with a red frame. Other than that, I don't think that there's a magic fix. It would also be good if a decision could be made re. flipping the default for images via http(s). I mentioned it at the bottom of comment #216, comment #218 and again in comment #219. I must sound like a broken record. The trouble is that we need to keep quiet about the bug, we can't start a large campaign with a red banner: "Add-on authors fix your add-ons, we're not shipping file-based images (and other referenced documents) any more by default!!"
A little off-topic: I've just checked my signatures. They all have moz-do-not-send="true" since I serve any images from my web server. Changing the default might be a little wake-up call for enterprise users to check their signatures to remove references to local files as much as possible.
Actually: The is a magic fix, it just occurred to me while washing baby bottles ;-) There is no need to switch the default to moz-do-not-send=true. A default is only necessary if we use M-C stripping which strips the attribute. My patch has home-made sanitising and I already set moz-do-not-send=true for all file-based pasted content. Broken record: That could be done for images via http(s) as well. So basically the patch reduces to the hunks that observe the paste/drop, sanitise the pasted/dropped content, present the panel and do the "accept" processing. How about that? Care to have yet another patch?
"Care to have yet another patch?" If you intended solution is significantly different than version 10, then yes. I'm looking at your patches under both esr45 and trunk now, and I'd like to make sure I understand what you are proposing as the best solution. No need to do new patches for minor changes.
Attached patch JK proposed solution (v11) - minimal. (obsolete) (deleted) — Splinter Review
OK, this is the same as v10 but with the mailnews hunks removed. So this is a pure mail/ solution sanitising pasted content after paste/drop. Repeating the key points: - Home-made sanitisation (without new app type MAIL EDITOR). That sets moz-do-not-send=true on pasted content so that switching of default behaviour is not necessary. Broken record: That could be extended to all pasted content, also from http:// to protect against extraction of data from intranets. - A panel that prompts the user which of the pasted content they want to ship out. I haven't switched this to using pre-existing strings for ESR45 yet (see comment #218). Optional work: Draw red frame around pictures that aren't sent with message. That could also be siwtch-offable ;-) with a preference. Breakage of add-ons: None.
Attachment #8800810 - Flags: feedback?(rkent)
Once we (finally) decide what to do, v11 needs some polishing: 1) Not sure that <link> elements are treated properly. 2) We could pass the images/anchors found to imageAttach.js so we don't have to get them a second time from the document. 3) Use existing strings for ESR 45. And of course 4), the broken record: All this needs to be adjusted to set moz-do-not-send=true for images/documents via http(s) sources if we so decide.
This is v11 as applied to ESR 45. It still uses *new strings*. I could switch this to pre-existing strings together with the polishing mentioned in the previous comment.
OK, here with old strings: <!ENTITY attachFile.label "Attach File(s)…"> This is untested since I can't build ESR 45.
Attachment #8800823 - Attachment is obsolete: true
I didn't imagine this bug would cause so much work. Thanks for working on it. From looking at the patch it appears you are doing a simple string comparison. Are you sure this will cover evasion techniques such as "FiLe://"? Additionally, "file:" is not the only dangerous protocol. As mentioned in comment #3, you can similarly use "imap:" URLs to attach entire emails. (Note that the attacker does not need to know the credentials if they are saved in the victims TB client. You only need to guess email IDs.) To me, something like <img src="imap://imap.gmail.com:993/fetch>UID>/INBOX>12345"> poses a bigger threat than filename guessing.
(In reply to Magnus Melin from comment #217) > If we prefer we can land a minimal rough fix for ESR: enable sanitation, and > default sending to off. That's not really acceptable. TB users copy a lot into the compose window, especially from MS Word. I just tried copying a text and an image and the image is this: "file:///C:%5CUsers%5Cjorgk%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_image001.png" And somehow the patch fails to detect it, grrr.
(In reply to Armin Razmjou from comment #229) > I didn't imagine this bug would cause so much work. Thanks for working on it. Well, it did. And landing a fix, once we worked out what we will do, on all versions concurrently is another challenge. > From looking at the patch it appears you are doing a simple string > comparison. Are you sure this will cover evasion techniques such as > "FiLe://"? I didn't try it, but we receive pasted content in a normalised form. > Additionally, "file:" is not the only dangerous protocol. As mentioned in > comment #3, you can similarly use "imap:" URLs to attach entire emails. We'll look into it.
(In reply to Jorg K (GMT+2) from comment #231) > (In reply to Armin Razmjou from comment #229) > > I didn't imagine this bug would cause so much work. Thanks for working on it. > Well, it did. And landing a fix, once we worked out what we will do, on all > versions concurrently is another challenge. > > > From looking at the patch it appears you are doing a simple string > > comparison. Are you sure this will cover evasion techniques such as > > "FiLe://"? > I didn't try it, but we receive pasted content in a normalised form. > > > Additionally, "file:" is not the only dangerous protocol. As mentioned in > > comment #3, you can similarly use "imap:" URLs to attach entire emails. > We'll look into it. When I did a select then drag from a test webpage (opened as a file), fiLE:/// survived the dnd and was not detected.
Attached patch JK proposed solution (v11a) - minimal. (obsolete) (deleted) — Splinter Review
Made it work for pasting from MS Word. The problem was that <img and src= where split into two lines and the regexp didn't find a match, sigh. Just goes to show that processing is error-prone :-( The ESR 45 patch also needs this line added: htmlData = htmlData.replace(/\n/g, " "); I haven't tried the cases mentioned in comment #229.
Attachment #8800734 - Attachment is obsolete: true
Attachment #8800810 - Attachment is obsolete: true
Attachment #8800734 - Flags: feedback?(rkent)
Attachment #8800810 - Flags: feedback?(rkent)
Attached patch JK proposed solution (v11b) - minimal. (obsolete) (deleted) — Splinter Review
Using case-insensitive comparison, should now work with FiLe:// The ESR 45 version needs updating.
Attachment #8800826 - Attachment is obsolete: true
Attachment #8800871 - Attachment is obsolete: true
Comment on attachment 8800875 [details] [diff] [review] JK proposed solution (v11b) - minimal. Review of attachment 8800875 [details] [diff] [review]: ----------------------------------------------------------------- Here is another round of feedback on this patch, following up on the issues raised in comment 153. Again, I would like to reiterate that this approach is not a suitable solution to a security bug, there is a long list of things that a patch like this would need to handle correctly. I know that I'm not a peer of any Thunderbird related module, but I do have some experience fixing security bugs in Firefox over the years, and I would like to suggest, once again, that solution that do things such as parse HTML and URIs using text processing utilities aren't suitable here. I really hope that you would consider this point. ::: mail/components/compose/content/MsgComposeCommands.js @@ +2283,5 @@ > + > +function sanitiseDroppedFileUris(aFilesImages, aFilesLinks) > +{ > + let images = getBrowser().contentDocument.images; > + // XXX .links doesn't return <link href=...> ??? .links returns <a> and <area> elements that have an href. @@ +2288,5 @@ > + let links = getBrowser().contentDocument.links; > + > + for (let img of images) { > + let src = img.getAttribute("src"); > + if (src.startsWith("file://") && aFilesImages.includes(src.replace(/file:\/\//i, ""))) { file isn't the only risky protocol, as Armin suggested. You should really do use a whitelist as opposed to a blacklist. And you should do proper URI parsing here. @@ +2297,5 @@ > + let href = link.getAttribute("href"); > + if (href.startsWith("file://") && aFilesLinks.includes(href.replace(/file:\/\//i, ""))) { > + link.setAttribute("moz-do-not-send", "true"); > + } > + } Are images and links the only things to worry about? Do we need to handle other means of including images, such as CSS? What about everything else that the built-in sanitizer deals with? @@ +2306,5 @@ > + // Detect image insertions from file:// URLs. > + // The HTML is "normalised", white-space is stripped > + // and the filename is always quoted. > + htmlData = htmlData.replace(/\n/g, " "); > + let re = /<img.*src="file:\/\/[^>]*>/ig; This doesn't work in the face of a whole category of markup. <img> src="file://...." <img src='file://....'> <img src=file://....> Again, parsing HTML using regular expressions or string manipulation will result in bugs. @@ +2320,5 @@ > + // We need to use setTimeout() to let the event complete first > + // so the user can see the pasted/dropped content before our message appears. > + setTimeout(function() { > + let filesImages = images.map(i => i.replace(/.*src="file:\/\//i, "").replace(/".*/, "")); > + let filesLinks = linksAndAnchors.map(l => l.replace(/.*href="file:\/\//i, "").replace(/".*/, "")); There are other similar issues in this function too.
(In reply to :Ehsan Akhgari from comment #236) > Again, I would like to reiterate that this approach is not a suitable > solution to a security bug, there is a long list of things that a patch like > this would need to handle correctly. Yes, I know, Magnus and you are promoters of the data URI solution. But we cannot just break the workflows of hundred thousands of users to get the box absolute watertight in a 45.x release. People do paste a lot into the compose window and that needs to remain workable with the pasted content being shipped out. > .links returns <a> and <area> elements that have an href. Indeed, that's what the documentation says. So how do I get <link> elements, since they are processed here: https://dxr.mozilla.org/comm-central/rev/593964199b659fdb8b5b7d8ce765c1976a783c99/mailnews/compose/src/nsMsgCompose.cpp#281 > @@ +2306,5 @@ > > + // Detect image insertions from file:// URLs. > > + // The HTML is "normalised", white-space is stripped > > + // and the filename is always quoted. > > + htmlData = htmlData.replace(/\n/g, " "); > > + let re = /<img.*src="file:\/\/[^>]*>/ig; > This doesn't work in the face of a whole category of markup. > <img> src="file://...." > <img src='file://....'> > <img src=file://....> I believe I tested that, and as the comment says, the HTML received is "normalised" and double-quoted. I'll consider the other comments, but not at 1:05 AM ;-)
(In reply to :Ehsan Akhgari from comment #236) > file isn't the only risky protocol, as Armin suggested. You should really > do use a whitelist as opposed to a blacklist. As was pointed out, even http can be risky if it's used to extract images/documents from an intranet. We could just whack all references onto the panel, but that will be a nightmare for the user. They just want to copy/paste and press send. And the want that the recipient gets all the data needed to view the message. No confusing questions. Just look at attachment 8800870 [details] to see how ugly a paste out of a word document already becomes. If I now also present http-based and other URIs, I'll just destroy the user interface completely. E-mail *is* about sending information and that is as such much more dangerous than viewing a web page. So please keep the problem in perspective. If you want to see real daily trouble, read bug 1201782 comment #31.
Jörg, you keep talking like pasting wouldn't work with the data-uri approach. It generally works. The only problem was file:// based web pages! Let's also put it in perspective: using images in (user created) mails at all is still rare. I imagine less than 1% of mails. Of those, a majority would still be in signatures, which we auto-fix.
Magnus: It's sort of funny that I work on a bug that is assigned to you until 1 AM and we still haven't seen *your* solution to the paste problem. You keep saying it "generally" works. That is clearly not the case. 1) Many users do paste from MS Word. As my experiments show, MS Work prepares a HTML clipboard with file-based images. Do you want to smash TB for those users or do you have a better solution than I have? 2) Users do paste HTML from websites into their compositions. In your solution so far you've changed the default not to send the images to protect intranet content. That will lead to the recipient receiving an e-mail with http references which may be blocked. 3) I don't want to mention again that the data URIs will break add-ons which is a no-no in a TB 45.x point release. In summary: Your solution so far smashes current workflows and usage. You have no data to prove that the effect is small. So please stop criticising and present a solution that addresses the problem instead of denying the problem. Off topic: We learn from bug 77304 or - say - the autocomplete switch from XPFE to toolkit that even the smallest change of behaviour affects many users. Here you're actively destroying TB editing capability and since most TB users actually use TB to send e-mail, that's pretty severe. Ehsan: Thanks again for your comments in comment #236: If you want to help to make the solution better, please answer the following questions: How can I retrieve all <link> elements in a document? |.links| doesn't do it. You're saying that I should use proper URI parsing and proper HTML parsing. I image that URI parsing can be done by creating nsIURI objects and then using methods of that class. As for HTML parsing: As you can see from the existing solution, I need to process the pasted HTML fragment. How do you suggest to use "proper" HTML parsing on the text representing the inserted HTML fragment in the paste/drop listener? Should I convert text to DOM and then traverse the DOM? How? Or can I identify the part of the DOM which got created in the document due to the paste/drop? I'm open to a better solution.
Flags: needinfo?(ehsan)
(In reply to :Ehsan Akhgari from comment #236) > file isn't the only risky protocol, as Armin suggested. In fact: All protocols are potentially risky. This is clear for file URLs and I hope it has become clear for http URLs since they can leak protected content from an intranet. TB's own "mailnews" URLs also pose a thread. Pasting an image from an existing message to a new message for example gives <img src="imap://info%40hostalpancheta%2Ees@mail.hostalpancheta.es:993/fetch%3EUID%3E.INBOX.SPAM%3E63?part=1.2&amp;filename=lijbmghmkilicioj.png" ...> Once again, there is absolutely no good answer here. The options I see are: 1) Drop that image upon send. That we can't do since it will break existing behaviour. That goes to show that flipping the default for moz-do-not-send in *general* as Magnus planned won't fly at all. 2) Leave everything as it is. Well, that's the attack vector. 3) Ask the user. Well, it will just drive them mad having to confirm on every single paste. And what am I going to put onto the panel? Do you want to ship: [ ] imap://info%40hostalpancheta%2Ees@mail.hostalpancheta.es:993/ fetch%3EUID%3E.INBOX.SPAM%3E63?part=1.2&amp;filename=lijbmghmkilicioj.png or [ ] lijbmghmkilicioj.png Both makes little sense. The long "mailnews" URLs are damn ugly and confusing and the even the short file name means absolutely nothing. OK, I could replace with "Picture pasted from message" (but again not in ERS 45.x where I can't have new strings). The panel makes sense for file URLs since the user will hopefully recognise their file, it's already bad for pasted content from MS Word (attachment 8800870 [details]). Putting stuff which is referenced via http URLs or "mailnews" URLs will just be deadly. So Armin, why did you think this was easy to fix? We simply cannot distinguish benign pasted content from malignant one. > What about everything else that the built-in sanitizer deals with? I have come to the conclusion that switching the default for a missing moz-do-not-send attribute to "don't send" breaks add-ons which rely on the previous "do send" default. Therefore I'm looking for a solution that doesn't change the default, see comment #223. So sanitising (= stripping) the attribute doesn't help in this approach, since I'd have to visit all the pasted content to set moz-do-not-send=true, which the current solution does anyway. Here a summary of the reasons why using M-C sanitisation is unattractive. 1) We would have to change default (breaks add-ons) or traverse pasted content to set moz-do-not-send=true (already mentioned above). 2) A new MAIL EDITOR app type was blocked so far (although Olli would approve that change). 3) This new MAIL EDITOR app type still wouldn't behave as required since href attributes are stripped so existing behaviour would be affected. The solution would be to visit pasted content to restore what was stripped. That's somewhat counter-intuitive. 4) As far as I can see, the only real problem is the moz-do-not-send attribute, I'm not aware that sanitisation would bring other benefits. Of course my ignorance is my bliss here ;-) 5) I would have to create a new MAIL EDITOR app type in this bug and address bug 1309058. Both are M-C changes which cause additional work for uplift situations. Conclusion: Without clear benefits, I suggest not to use M-C sanitisation for the immediate problem. Ehsan, not using M-C sanitisation doesn't mean we can't to the parsing better. The question re. those improvements are at the bottom of comment #240. In general we need to see the problem of this bug clearly. The PRIMARY problem is: How to handle pasted content since we cannot distinguish good from bad. Any solution needs to answer 1) How much is existing behaviour affected or completely broken? Can users still paste from MS Word documents, web pages or other e-mails. Can the rectify bad choices made by the software (by for example editing the properties to include or not include content). 2) Are add-ons affected? The SECONDARY problem is: How to best implement this keeping string changes, uplifts and other things in mind. Fair enough, data URIs come with added security since not a single attribute on a DOM element decides whether associate content is shipped or not. But to replace everything the program adds with data URIs and smash other editing capabilities is *clearly not the answer*, regardless of how many times Magnus repeats it.
Attachment #8800875 - Flags: feedback?(rkent)
(In reply to Armin Razmjou from comment #229) > something like <img src="imap://imap.gmail.com:993/fetch>UID>/INBOX>12345"> > poses a bigger threat than filename guessing. OK, we could drop anything with a "mailnews" URL unless it's referencing a part which we would automatically include. So summarising this idea: Protocol | Action ----------+----------------------------------------------- file | ask http(s) | still undecided mailnews | drop full messages and accept parts by default other | drop? Does anyone care to have a patch for that? "Undecided" is especially easy to implement :-(
(In reply to Jorg K (GMT+2) from comment #240) > Ehsan: Thanks again for your comments in comment #236: If you want to help > to make the solution better, please answer the following questions: > How can I retrieve all <link> elements in a document? |.links| doesn't do it. You can use various APIs such as getElementsByTagName(), querySelectorAll(), etc. > You're saying that I should use proper URI parsing and proper HTML parsing. > I image that URI parsing can be done by creating nsIURI objects and then > using methods of that class. Yes. > As for HTML parsing: As you can see from the > existing solution, I need to process the pasted HTML fragment. How do you > suggest to use "proper" HTML parsing on the text representing the inserted > HTML fragment in the paste/drop listener? Should I convert text to DOM and > then traverse the DOM? How? Or can I identify the part of the DOM which got > created in the document due to the paste/drop? I'm open to a better solution. Feed the data to Gecko's HTML parser, by either loading the data in a document or use DOMParser. (In reply to Jorg K (GMT+2) from comment #238) > (In reply to :Ehsan Akhgari from comment #236) > > file isn't the only risky protocol, as Armin suggested. You should really > > do use a whitelist as opposed to a blacklist. > As was pointed out, even http can be risky if it's used to extract > images/documents from an intranet. I'm not sure what the nature of the risk with HTTP is. If you send HTTP URLs verbatim in the body of the email, you won't be revealing any private information (since the attacker will only be able to resolve the link to the intranet site if they're on the same internal network). If you're modifying such URLs (for example by attaching images at such a URL to the email or convert those to data: URIs then you're revealing private information. For whatever it's worth, the problem of not revealing private data in such cases, is very well known. The same origin policy is essentially designed to mitigate such attacks with intranet URLs. -- I still think Magnus' solution is the right way forward, but I don't think I can say anything that I haven't said before that would convince you. I've run out of time and energy to keep commenting here, so I'm going to give up now.
Flags: needinfo?(ehsan)
Ehsan, thanks for the hints. In case you still read this. You didn't answer: Can I identify the part of the DOM which got created in the document due to the paste/drop? (In reply to :Ehsan Akhgari from comment #243) > I still think Magnus' solution is the right way forward, but I don't think I > can say anything that I haven't said before that would convince you. I know I sound like a broken record. But I'll try again. Magnus actually hasn't presented an up-to-date patch. The patch he has presented in June 2016 doesn't handle pasted content at all. The user pastes and no images of the categories mentioned below get pasted since his proposal is to stop being app type EDITOR. That will cause an *absolute* outcry. Users want to paste from - other e-mail (referencing images from mailnews URLs) - MS Word (referencing images from file URLs) - web pages, be it the WWW or their intranet. And they *do want* to reveal private data, that's why they pasted it in the first place for the recipient to see. Why is it so hard to understand that users want to ship data other than text with their e-mails? They do want to attach that data to the e-mail so the recipient receives a complete e-mail (with no http references that their client will block). Please read about the PRIMARY problem described at the bottom of comment #241. We can't just stop all data being sent just because it is an attack vector.
Flags: needinfo?(ehsan)
(In reply to Jorg K (GMT+2) from comment #244) > Ehsan, thanks for the hints. > > In case you still read this. You didn't answer: > Can I identify the part of the DOM which got created in the document due to > the paste/drop? No, you can't. > (In reply to :Ehsan Akhgari from comment #243) > > I still think Magnus' solution is the right way forward, but I don't think I > > can say anything that I haven't said before that would convince you. > I know I sound like a broken record. But I'll try again. > > Magnus actually hasn't presented an up-to-date patch. The patch he has > presented in June 2016 doesn't handle pasted content at all. The user pastes > and no images of the categories mentioned below get pasted since his > proposal is to stop being app type EDITOR. That will cause an *absolute* > outcry. > > Users want to paste from > - other e-mail (referencing images from mailnews URLs) > - MS Word (referencing images from file URLs) > - web pages, be it the WWW or their intranet. And they *do want* to reveal > private data, that's why they pasted it in the first place for the > recipient to see. > > Why is it so hard to understand that users want to ship data other than text > with their e-mails? They do want to attach that data to the e-mail so the > recipient receives a complete e-mail (with no http references that their > client will block). Please read about the PRIMARY problem described at the > bottom of comment #241. > > We can't just stop all data being sent just because it is an attack vector. With all due respect, you're reducing my argument to a ridiculous position (such as "we should stop all data being sent") and then argue against it. Which is why I'll refrain from the back and forth over this since it's not a good use of time. I'll let Magnus respond to the technical objections...
Flags: needinfo?(ehsan)
Thanks again for your input. I'm sure we can use your suggestions re. URL and HTML parsing.
(In reply to :Ehsan Akhgari from comment #245) > > Can I identify the part of the DOM which got created in the document due to > > the paste/drop? > No, you can't. I found a way to identify content that got added to the DOM during the paste. Patch attached. So we don't need to parse the pasted HTML at all. We can just process the pasted images. We can do the same for anchors and links. Together with the URI parsing that comes with the methods of nsIURI, we can create a more stable solution ... if we ever decide what we want to do ;-) I'm happy to keep working on this.
Depends on: 1310377
This patch offers the very same function that v11/v11b tried to offer but with Ehsan's comments addressed (Ehsan: I do listen to you!): No more regexp parsing of URLs or HTML. In fact, there is no HTML parsing at all any more, since I take a snapshot of the images and anchors (<link> processing still missing) before the paste/drop insertion into the DOM is executed. After the paste/drop, I work out what's new and sanitise. XXX in the code point out what still needs to be done, most importantly we need to decide how to treat http(s) and mailnews protocols.
Attachment #8800875 - Attachment is obsolete: true
Attachment #8801403 - Attachment is obsolete: true
Attachment #8800875 - Flags: feedback?(rkent)
Attachment #8801464 - Flags: feedback?(rkent)
(Sorry about the noise. Added missing ind++;)
Attachment #8801464 - Attachment is obsolete: true
Attachment #8801464 - Flags: feedback?(rkent)
Attachment #8801465 - Flags: feedback?(rkent)
This bug appears to be a variant of bug 819171. The solution proposed there "A message box asking for confirmation of the attachment should be displayed to the user. This should happen every time and a setting made available to set the default behavior." is essentially what Jörg is proposing here.
Kindly allow me access to bug 819171. Yes, my proposal is a message box. As per comment #242 we need to discuss multiple protocols and my suggestion is: Protocol | Action ----------+------------------------------------- file | ask http(s) | ask mailnews | drop full messages and ask for parts other | drop I discussed this casually with Aceman on IRC (and my wife, too). He/they are in favour of such a message box, even with an "Accept all" button and even with a "Don't show again" option. In any case, with a few new strings we could make this sophisticated, like: ============================== Send the following files as part of the message? Local files: [ ] salary-list.doc from C:/Users/TheBoss/Documents/ [ ] clip_image001.png from a temporary directory [Note: for paste from MS Word] Web content: [ ] CDcover.jpg from https://images-na.ssl-images-amazon.com [ ] salary-list.doc from http://intranet/TheBoss/Documents Message content: [ ] lijbmghmkilicioj.png from account info@hostalpancheta.es [use account *name* here] ==============================
(In reply to Jorg K (GMT+2) from comment #251) > even with a "Don't show again" option. IMO that defeats the purpose because users will opt out of a feature that they didn't know had a security purpose.
(In reply to Armin Razmjou from comment #252) > (In reply to Jorg K (GMT+2) from comment #251) > > even with a "Don't show again" option. > IMO that defeats the purpose because users will opt out of a feature that > they didn't know had a security purpose. Note that my comment had the word "even" to underline that this is of course questionable. That said, you need to assume that some/most users are in fact responsible and mature citizens (sometimes referred to as "consenting adults" in other contexts). I find the idea, how to say it, quite surprising, that the software should protect people against all possible dangers. It simply cannot. So personally, I can't see anything wrong with disabling the panel. I think I would disable it if it became annoying, since I would never paste anything from a foreign e-mail or website to which I was lured. There can also be situations where TB is used to only send e-mail on an intranet where due to the setup of the network it is impossible to mail anything to the outside world. There could also be setups where attachment are stripped by the MTA. Since we're already at comment #253, let me outline briefly the dangers of e-mail: 1) You send it to the wrong recipient. TB doesn't protect against that. If fact, changes to our address autocomplete caused such cases, causing in one documented case the potential loss of $50.000 worth of business. (bug 486501 comment #24). 2) You send the wrong attachment. TB doesn't protect against that and there are bugs that claim that TB will erroneously attach the wrong file. 3) You simply send the wrong content. TB also doesn't protect against that. Some people asked for a send delay, that is, some sort of "cooling off" button, so if the sender released that it wasn't a good idea to send their girl/boyfriend to hell in an e-mail or quit their job, they could change their mind. Sure, you will say that this is a lame comparison, since I'm comparing a clandestine attach against which it is difficult to protect oneself to an obvious risk. But anyway, those who want to live risky or who simply don't have any sensitive data on their machines, could (I'm not saying 'should') be enabled to do so. Humour: We're not Apple who determine how users have to use your gear/software. Also, if we don't allow disabling it, there will be an add-on for "consenting adults" which does.
(In reply to Jorg K (GMT+2) from comment #244) > Magnus actually hasn't presented an up-to-date patch. The patch he has > presented in June 2016 doesn't handle pasted content at all. Would you please stop twisting facts. > The user pastes > and no images of the categories mentioned below get pasted Yes, not handling *certain cases*, yet. > Users want to paste from > - MS Word (referencing images from file URLs) Works from LibreOffice. Know why? Because it gives us a data uri. Not to say we shouldn't fix it. > - web pages, be it the WWW or their intranet. And they *do want* to reveal > private data, that's why they pasted it in the first place for the > recipient to see. I suppose it's plausible people occasionally send intranet content to outside. That is likely in violation of company policy for, well, everyone. That the content sent would include relevant images seems even more unlikely. A bug report about that certainly would be interesting reading!
(In reply to Jorg K (GMT+2) from comment #253) > So personally, I can't see anything wrong with disabling the panel. Sorry but then you really don't understand the bug at all. In what way would it be ok to have your ssh keys stolen? In what way would it be ok to have most of your Inbox attached? The minimal user survey data you've presented is saying exactly what we already knew: You can't ask people complex tech questions and expect a reasonable answer. It's just an annoying click through.
(In reply to Magnus Melin from comment #254) > (In reply to Jorg K (GMT+2) from comment #244) > > Magnus actually hasn't presented an up-to-date patch. The patch he has > > presented in June 2016 doesn't handle pasted content at all. > > Would you please stop twisting facts. > > > The user pastes > > and no images of the categories mentioned below get pasted > > Yes, not handling *certain cases*, yet. Magnus, why are fighting each other here? I am not twisting any facts. The complete paragraph read: 1) Magnus actually hasn't presented an up-to-date patch. 2) The patch he has presented in June 2016 doesn't handle pasted content at all. 3) The user pastes and no images of the **categories mentioned below** get pasted since his proposal is to stop being app type EDITOR. 4) That will cause an *absolute* outcry. 1) is true. 2) is also true. Your patch simply withdraws app type EDITOR and don't worry about pasted content at all. You get M-C behaviour, that is: file:// simply dropped, and you've changed other code to not send pictures pasted from http, and it I read it correctly, also mailnews URLs (or perhaps they also don't get pasted, I haven't tried). 3) clearly refers to categories **mentioned below** and 2) needs to be read in that context. 4) I believe this is also try, but my aim here is not to prove this prediction correct. Magnus, what are we doing here? Today is the 17th of October, the next branch date is on the 7th of November. You haven't sent a patch since June and you're resisting the bug being assigned to someone else. You talked about fixing the links case (comment #189) and on working on the paste case. Where is that work? You haven't even commented on the panel solution I'm proposing and which data we should prompt the user for. So extrapolating the current process, we will discuss 200 more comments and not implement anything.
(In reply to Magnus Melin from comment #255) > Sorry but then you really don't understand the bug at all. In what way would > it be ok to have your ssh keys stolen? In what way would it be ok to have > most of your Inbox attached? Why don't you send your solution so we get some proposals going instead of telling me that I don't understand the bug at all? Maybe I don't understand it, so that's why it is assigned to you. So please present a solution that will fly and not make our "users' lives miserable", as Kent put it. So far you've prolonged the time during with it is completely OK to have anything stolen by four months. Refer to Henri's comment #206: ... letting this vulnerability go unaddressed for an extended period of time ... P.S.: To have the inbox stolen, you'd have to guess the user's random profile name. Otherwise you can steal one message at the time via a mailbox URL. But perhaps I don't understand that part either.
I'm not fighting you, I just pointed out you keep talking about "doesn't work at all" which is not true. Yes the links case is fixed (locally). I'm actively working on figuring out a solution for the cases we have. This is complex so you can't expect a solution a day after I say I'll work on it. > To have the inbox stolen, you'd have to guess the user's random profile name. No such luck unfortunately. See comment 5. Handling the imap/mailbox uris appears to be the main pain point. I'll note though that with my patch if you paste content from another mail you get the broken picture for display (expected). But it (surprisingly) also won't get attached even if i try to force it by setting the attribute.
(In reply to Magnus Melin from comment #254) > Works from LibreOffice. Know why? Because it gives us a data uri. No so. If you insert an image from a file into Oo or Libreoffice and paste to TB, you get no picture at all. If you paste clipboard content from - say - a screenshot, you get a data URI.
Regarding using a real HTML parser and a real URL parser: See nsParserUtils.cpp in m-c for the code the invokes the parser and then invokes the m-c sanitizer. You can copy that code to c-c and insert processing of your choice before the sanitizer runs. The right time to do this URL rewriting processing is, as noted earlier, before the content has been inserted to the message composition DOM.
(In reply to Jorg K (GMT+2) from comment #259) > > Works from LibreOffice. Know why? Because it gives us a data uri. > No so. If you insert an image from a file into Oo or Libreoffice and paste > to TB, you get no picture at all. If you paste clipboard content from - say > - a screenshot, you get a data URI. I used Insert -> Image and selected an image file. At least on (Ubuntu shipped) LibreOffice 5.1.4.2 you get an image with data uri pasted along the other content.
(In reply to Magnus Melin from comment #261) > you get an image with data uri pasted *along the other content*. On Windows in the latest 5.2.2.2 you get no image if you select text + image. If you only select the image, you get a data URI. I checked the clipboard content. No image. Anyway, all not so relevant, since MS Word puts file:// references into their HTML.
I'd like to state what I think is the proper way forward for this bug. First, let's make sure we understand what the existing security model is supposed to be, and the problem. The particular security issue that we are concerned with here, as I understand it, are URLs whose content is downloaded and converted to attached MIME CID urls in the method nsMsgComposeAndSend::GetEmbeddedObjectInfo. Whether a URL gets downloaded and converted is largely determined by the presence of the moz-do-not-send attribute, with "true" meaning do not download. ("download" here includes the process of accessing the url by any method, which might include file, email, or http urls for example.) The current design attaches the moz-do-not-send='true' attribute to potentially attached content derived from supposedly untrusted sources (in replies and forward for example), assuming then that the content in the editor is now sanitized and may be trusted, including the editing process. It is the violation of that assumption that we are concerned with. The problem here comes from the fact that, in some cases, HTML attributes can exist that are totally hidden from the user in the existing UI, and could be from untrusted sources, that result in content downloaded and attached to the message using the current credentials or access of the sending user without his or her knowledge. Those violations are of two sources: 1) The content of a message might be placed in the editor from an untrusted source, for example using Edit As New. 2) Once in the editor, additional content might be added from untrusted sources, for example using cut and paste of HTML content from an untrusted source. We have to plug both of these issues in order to fix this issue, or eliminate the capability completely to convert urls to attached content. I am very reluctant to eliminate the capability completely in a security bug unless there is absolutely no other way to fix the issue, and I believe we have other options available that would solve the problem. To fix issue 1), we need to add some sort of reliably-maintained flag to the message that indicates whether the message is clean and/or sanitized, or to the contrary comes from untrusted content without sanitization. If the message is untrusted and unsanitized, sanitize it prior to adding it to the message compose editor. Currently sanitization is done for messages that the user flags as untrusted by forwarding or replying, but that method is not sufficiently reliable to track untrusted content. The only reasonably reliable way we have to do that is to add a header in the message that is stored with the message, and to prevent that header from being added by untrusted emails. So we have to 1) remove this header if it occurs in emails from untrusted sources prior to accepting these messages into Thunderbird, 2) add this trusted header when a message is prepared new from trusted sources, and 3) search for the header when messages are opened by the editor, if missing sanitize the message using nsMsgCompose::TagEmbeddedObjects and also add the header to the edited content to mark it now sanitized. Content created from scratch by the user in the editor also gets this header added. For problem 2), we need to eliminate the hidden aspect of this embedded content by adding an accept dialog, as discussed earlier in this bug. Yes it could be ugly, as the user is going to find references to files and message content confusing, but the expectation is that in the described attack scenarios, the user is not expecting attached content at all, so questions before proceeding. I would be opposed though to any user-visible UI that allows this option to be eliminated. Warning the user is not ideal, but I think it is the best compromise. Keep in mind that there are always instructions that an attacker could give via social engineering that could result in compromise ("Your password.doc file has been found to be infected! Please email it to us as an attachment for cleaning!"). We can't completely eliminate social engineering attacks, so whether a particular warning is sufficient is going to be a judgement call. What is unacceptable about the current situation is the lack of any warning at all in cases that most users would not recognize as dangerous (like Edit as New, or cut and paste). Another approach to the problem, which could be added with or without the proposals above, is to stop hiding the presence of embedded object attachments in the compose UI. If an embedded attachment were shown as an attachment, that would be an additional warning to the user of what they are about to send, and those attachments could also be opened and examined, which gives the user an additional layer of protection prior to sending the message. As for resolution of conflicts that are coming out in discussing this bug, I consider this issue primarily a mailnews backend bug, I'm going to claim myself as de facto module owner of the backend, and therefore responsible for getting some resolution of the issues here. If we cannot come to agreement, the next step would be to organize the issue for presentation to the Thunderbird Council for final resolution, but we are not there yet.
(In reply to Kent James (:rkent) from comment #263) > For problem 2), we need to eliminate the hidden aspect of this embedded > content by adding an accept dialog, as discussed earlier in this bug. Yes it > could be ugly, as the user is going to find references to files and message > content confusing, but the expectation is that in the described attack > scenarios, the user is not expecting attached content at all, so questions > before proceeding. Perhaps not expecting files to be attached, but it's very conceivable an image from a message might be required. "Copy this image and the text next to it, send it to me and you'll get nice things." Since you can't really go into which message it is, any notification about message uris would be really tricky.
(In reply to Magnus Melin from comment #264) > Since you can't really go into which message it is, any notification about > message uris would be really tricky. Right. An IMAP URL would look something like this: "imap://test%40dryrain%2Eorg@host301.hostmonster.com:143/fetch%3EUID%3E.INBOX.Drafts%3E12?part=1.2&amp;filename=dpfpakieecbcahhe.png" or decoded "imap://test@dryrain.org@host301.hostmonster.com:143/fetch>UID>.INBOX.Drafts>12?part=1.2&filename=dpfpakieecbcahhe.png" where the filename could be anything, unrelated to the filename provided in the actual message. The problem is less for http:// and file:// urls where we at least have a chance of providing a user-understandable notification. Any notification should include at least the subject of the email containing the content. Better would include the original attachment name from the email, as well as a straightforward way to view the actual content prior to deciding what to allow to be attached. In other words, something similar to the capability of the existing attachment filelist (which allows selection to open for viewing) but with a decision checkbox. I suppose we need to be open to simply disallowing cut-and-paste of embedded attachment links between messages, but that would be a significant reduction in capability, as that would also include copying any inline files added by the user to a draft message, which get converted to embedded message urls. It would not be hard to add a [View] option to the acceptance dialog, as well as the subject of the email. Would that be sufficient notification of content since the user could easily see what was going to be attached?
Please consider my suggestion from comment #251. IMHO quoting a potentially long subject doesn't help. If the user just pasted from another message, they're well aware of where the content came from. In the unlikely attack case, they will be surprised to receive such a panel and may use the suggested "view" button to see the content that might be attached. Conversations can be long and many attachments can be exchanged during the course of a conversation. So I don't think the subject is especially helpful.
(In reply to Jorg K (GMT+2) from comment #266) > Please consider my suggestion from comment #251. How is this a reasonable notice?: lijbmghmkilicioj.png from account info@hostalpancheta.es [use account *name* here] The filename can be spoofed if you are relying on the URL.
Before discussing further, let me give an update on my current plan, subject to change depending on issues arising while implementing it. Hope to finish it in a few days. - Copy from Word case: on paste look at the images. Convert to data uris if they lead to a file in the temp dir, which Word links likely do. Yes there's the off chance someone might steal something from the temp dir, but you'd have to be guessing really well, and there's all kinds of timing windows you'd have to cope with to really pull off an attack. Also make sure the file is really an image type. - Copy from other message case: on copy, replace successfully loaded images in the copied selection with their data uri. The message viewed is really the only one who can know reliably if the internal reference is ok to access or not. (This will also be useful for copying content to outside programs which was always broken.) In summary: very little breakage. But things get very hard to do if you stay in the current opt-out approach, which means you miss one case and there's a security problem. With opt-in, you miss one case and there's only a corner case functionality broken.
(In reply to Kent James (:rkent) from comment #267) > lijbmghmkilicioj.png from account info@hostalpancheta.es [use account *name* > here] > The filename can be spoofed if you are relying on the URL. You could cross check the filename with the filename in the attachment header. Anyway, I'm glad I'm not assigned to this bug so I don't have to work on it until 2 AM any more like you do.
(In reply to Kent James (:rkent) from comment #263) > The only reasonably reliable way we have to do that > is to add a header in the message that is stored with the message, and to > prevent that header from being added by untrusted emails. Message headers have the same problem as HTML attributes: both can come from untrusted sources, so there's a risk of mix-up. It would be safer to use an in-memory flag that doesn't intermingle with headers and cannot be serialized into mailbox storage (meaning that saving a draft and reopening it would make the message lose its flag).
(In reply to Magnus Melin from comment #268) That sounds somewhat appealing. Certainly there is not much point in prompting for successfully loaded and visible images (what about CSS: display:none?). Figuring out what the "temp" directory is on the various platforms might be tricky and we'd have to investigate whether the temp directory M$ Word uses can be relocated. You haven't covered the http(s) case. Does the user want to include the images from the referenced site because a) they don't want the recipient to get a blocked image (remote content) or b) he wants the recipient to view the image copied from the intranet. Maybe we could introduce a red frame (via CSS) for images with no moz-do-not-send=false, so that http pasted content will indicate its future "ship this" status. > In summary: very little breakage. Well, add-ons break since you'll ship this in a 45.x release with no warning. You haven't mentioned what will happen to pasting links. Dropping app type EDITOR would give you standard M-C sanitising and we know that that drops href=file://. I don't know how much the "Add link" to a local file is used and and how much copying will happen on those.
(In reply to Henri Sivonen (:hsivonen) from comment #270) > (In reply to Kent James (:rkent) from comment #263) > > The only reasonably reliable way we have to do that > > is to add a header in the message that is stored with the message, and to > > prevent that header from being added by untrusted emails. > > Message headers have the same problem as HTML attributes: both can come from > untrusted sources, so there's a risk of mix-up. It would be safer to use an > in-memory flag that doesn't intermingle with headers and cannot be > serialized into mailbox storage (meaning that saving a draft and reopening > it would make the message lose its flag). I don't understand how that could work. The issue that I am concerned with, for example, is when someone copies an untrusted email to a presumably trusted location (drafts or templates), or uses EditAsNew to open both supposedly trusted emails (say in Templates) as well as untrusted content. The problem is that in the email durable storage system (either locally or remotely) we have a mix of trusted and untrusted content, and email copies and moves can be done so that no location (such as drafts or templates) can be marked as reliably trusted. We need to open those emails in the editor, and (following the current security model) sanitize untrusted content, but leave urls in trusted content. The only reliable information that gets stored with these moved and copied messages is the message content itself, including its headers and MIME content. I don't see how in-memory flags are helpful here. Yes once in the editor, there will be in-memory structures that determine status, but that is not the concern here.
(In reply to Magnus Melin from comment #268) > - Copy from Word case: on paste look at the images. Convert to data uris if > they lead to a file in the temp dir, which Word links likely do. Yes there's > the off chance someone might steal something from the temp dir, but you'd > have to be guessing really well, and there's all kinds of timing windows > you'd have to cope with to really pull off an attack. Also make sure the > file is really an image type. So you are planning to assume that anything in the User's temp directory is safe content to send out in an email? I don't see how you can consider that secure. You're making a lot of assumptions that other programs don't create files with guessable names in the temp directory. Also, just because something is an image does not assure that it is safe-to-distribute content, as many a celebrity whose private images have leaked will attest to. So I don't see how this approach solves the fundamental problem. > - Copy from other message case: on copy, replace successfully loaded images > in the copied selection with their data uri. The message viewed is really > the only one who can know reliably if the internal reference is ok to access > or not. (This will also be useful for copying content to outside programs > which was always broken.) The use of message URLs as message links has been problematic for other reasons beyond security, namely that these URLs have ended up stored in drafts, and then the underlying message moved which breaks the link. So I think that eliminating message URLs in stored messages, and replacing them with data URIs, is something we've considered for awhile. So I am fine with this. You are also missing another case: http: links. These also cannot be considered save-to-distribute content, as the user could be located behind a firewall or have password-authenticated access to an http: url, so it is not safe to distribute. How do you distinguish safe from unsafe pastes of embedded http: urls?
(In reply to Magnus Melin from comment #268) > - Copy from Word case: on paste look at the images. [...] if > they lead to a file in the temp dir, which Word links likely do. > - Copy from other message case: on copy, [...] successfully loaded images > in the copied selection Regardless of which solution we adopt, we should incorporate these ideas. Certain images could be considered "secure" and could be preselected on the panel (if we have one) or we might not need to display a panel at all if only "secure" content is pasted. I'm not sure why file-based and message-based, or http-based images for that matter, would be processed differently. That would greatly reduce the pain. The common case is that the user wants to copy HTML (text+images) into the e-mail. As long as those images are visible, they should be good to ship regardless of which source they're from. Please don't say that there could be an 8x8 almost white image that would be visible but not distinguishable form the white background and that somehow could contain a state secret ;-)
Wires crossed, so let me reply to this separately ... and repeat some of what I've said already: (In reply to Kent James (:rkent) from comment #273) > Also, just because > something is an image does not assure that it is safe-to-distribute content, > as many a celebrity whose private images have leaked will attest to. Well, if you paste something into your composition which is clearly visible, why would that not be good to send? Why is seeing the image worse than getting a warning about it? You suggested a "View" button. Well, that's not necessary if you can see the pasted content not obscured by any panel that popped up in front of it. As for the celebrities: Someone got access to their cloud storage or extracted the images with physical access to the hardware, for example in a repair shop. I highly doubt that those images got stolen from a temp directory. As the Magnus pointed out, the likely attack is on file in well known locations and personal pictures don't count amongst those. As I said, if Madonna sees a compromising picture of herself in an e-mail after hitting paste and presses "Send", well, I'm not sure the system should have avoided it. Let's face it: The panel is annoying, the information it contains might not mean anything to the user, and there is the danger that they will hit "Accept all" after a while. So if we can reduce the cases it will pop-up or don't do a panel at all after ensuring that common use cased of pasting HTML work, that would be good. I mentioned the idea of focusing on images only (comment #144 at the bottom). That said, we still haven't discussed pasting links to other document types (comment #271 at the bottom). Surely if we find <img src=" .... .doc">, we can drop this. But what about other links? Maybe we only do a panel for those. As for http-based content: I think the same answer applies: WYSIWYG, or in this case, what you see is what the recipient gets. Or we could flip the default send and put a red frame around things that don't get send. Another comment: I oppose(d) the data URIs since by themselves they don't solve the problem at hand: Do something useful when the user pastes content into their composition. As I stated in comment #241, the *primary* problem we need to solve is the paste, what happens later is *secondary*. Data URIs integrated into a "paste solution" are less opposable, although they make the HTML of the message less editable, break add-ons and may cause memory issues.
(In reply to Kent James (:rkent) from comment #273) > So you are planning to assume that anything in the User's temp directory is > safe content to send out in an email? I don't see how you can consider that > secure. You're making a lot of assumptions that other programs don't create > files with guessable names in the temp directory. Well chances you can guess a user's exact temp dir, that there's a picture file with a certain name AND have them send you a message while that file happens to be in temp makes it fairly hard to do. We could also make sure the file was put there say less then a minute ago (by checking modification time of the file). > You are also missing another case: http: links. These also cannot be > considered save-to-distribute content, as the user could be located behind a > firewall or have password-authenticated access to an http: url, so it is not > safe to distribute. How do you distinguish safe from unsafe pastes of > embedded http: urls? I don't, they get sent as http links - remember I'm switching the include-in-send to opt in. For http, we just don't include unless the user manually sets the images to get included.
(In reply to Jorg K (GMT+2) from comment #271) > You haven't mentioned what will happen to pasting links. Dropping app type > EDITOR would give you standard M-C sanitising and we know that that drops > href=file://. I don't know how much the "Add link" to a local file is used > and and how much copying will happen on those. Frankly I had seen it but never even understood how it was supposed to used before I read this bug. I don't think it's an important feature to keep. People understand what a link means. That you can include "local data" in a link is... unexpected.
(In reply to Magnus Melin from comment #276) > I don't, they get sent as http links - remember I'm switching the > include-in-send to opt in. For http, we just don't include unless the user > manually sets the images to get included. I don't really like this. You're changing existing behaviour and producing messages that will have "remote content" that may be blocked at the receiving end. Then we should really draw a red frame around those images.
For the red frames put img:not([moz-do-not-send="false"]) { border: 2px solid red; } into editor/ui/composer/content/EditorContent.css Of course we'd have to negotiate with the SM guys on this.
(In reply to Kent James (:rkent) from comment #272) > (In reply to Henri Sivonen (:hsivonen) from comment #270) > > (In reply to Kent James (:rkent) from comment #263) > > > The only reasonably reliable way we have to do that > > > is to add a header in the message that is stored with the message, and to > > > prevent that header from being added by untrusted emails. > > > > Message headers have the same problem as HTML attributes: both can come from > > untrusted sources, so there's a risk of mix-up. It would be safer to use an > > in-memory flag that doesn't intermingle with headers and cannot be > > serialized into mailbox storage (meaning that saving a draft and reopening > > it would make the message lose its flag). > > I don't understand how that could work. The issue that I am concerned with, > for example, is when someone copies an untrusted email to a presumably > trusted location (drafts or templates), or uses EditAsNew to open both > supposedly trusted emails (say in Templates) as well as untrusted content. > > The problem is that in the email durable storage system (either locally or > remotely) we have a mix of trusted and untrusted content, and email copies > and moves can be done so that no location (such as drafts or templates) can > be marked as reliably trusted. We need to open those emails in the editor, > and (following the current security model) sanitize untrusted content, but > leave urls in trusted content. The only reliable information that gets > stored with these moved and copied messages is the message content itself, > including its headers and MIME content. I don't see how in-memory flags are > helpful here. Yes once in the editor, there will be in-memory structures > that determine status, but that is not the concern here. My point is that when one can't trust emails in the Drafts folder, one can't trust their headers, either. So the only option is treating anything that's loaded from storage as untrusted and having trustedness an ephemeral in-RAM thing. This is, of course, sad for the UX of saving a draft and then re-opening it for editing.
(In reply to Henri Sivonen (:hsivonen) from comment #280) > My point is that when one can't trust emails in the Drafts folder, one can't > trust their headers, either. So the only option is treating anything that's > loaded from storage as untrusted and having trustedness an ephemeral in-RAM > thing. This is, of course, sad for the UX of saving a draft and then > re-opening it for editing. Messages are placed into Drafts by us, so it is possible for us to control the presence or absence of specific headers in the email. Those specific headers (or their absence) would be trusted by us.
Re not including http images by default: I imagine the feature to always attach them could have had some value, but urls don't really change much these days, and we're not the mozilla application suite so any personalization images would not be there since all you get is what you see as non-logged-in (the cookies wouldn't be in Thunderbird). Also, basically all commercial mails include remote content and they seem quite fine with that. Another data point: Gmail doesn't even bother blocking remote images for privacy anymore.
This seems to work for me. Implementing comment 268.
Attachment #8804035 - Flags: review?(rkent)
Attachment #8804035 - Flags: review?(jorgk)
Attachment #8804035 - Attachment description: bug1151366_sec_file_attach.patch (swith to data uris) → bug1151366_sec_file_attach.patch (switch to data uris)
(In reply to Magnus Melin from comment #282) > Also, basically all commercial mails include remote content and they seem > quite fine with that. Another data point: Gmail doesn't even bother blocking > remote images for privacy anymore. FWIW that's because they fetch the images out of band and serve the remote images from a google.com domain when using the webmail interface: <https://gmail.googleblog.com/2013/12/images-now-showing.html> The privacy risks around remote images in emails remain to this date.
Comment on attachment 8804035 [details] [diff] [review] bug1151366_sec_file_attach.patch (switch to data uris) Review of attachment 8804035 [details] [diff] [review]: ----------------------------------------------------------------- Apart from two things I spotted by glancing at the code, I'd like to make the following comments: The r- is for items 1) and 2). 1) Pasting from MS Word doesn't work at all, I get HTML pasted as text. This shows up in the composition: <!-- /* Font Definitions */ @font-face {font-family:"Malgun Gothic"; panose- ... etc. 2) I right-clicked an image in another message and selected "Copy Image". That gets pasted as <p><img src="imap://info%40hostalpancheta%2Ees@mail.hosta ... and nothing shows. If you select a larger segment, it works. 3) I think we need to allow adding file:// images in Insert > HTML. 4) I think we should hide the data URIs in the Image Properties and Link Properties dialogue. 5) You're changing the behaviour to not attaching http-based images, I think we need to address this. I suggested a CSS trick. With these items fixed, the solution could be acceptable if it didn't break existing add-ons and workflows (meaning that users could paste some other file-based content). Altogether I think we should discuss which route we're going to take before taking this further. ::: mail/base/content/mailWindow.js @@ +53,5 @@ > .removeListener(window.MsgStatusFeedback); > } > > +/** > + * When copying/gradding, convert imap/mailbox URLs of images into data URLs so Dragging. ::: mail/components/compose/content/MsgComposeCommands.js @@ +2289,5 @@ > + // Not anywhere under the temp dir. > + continue; > + } > + > + if (!/\.(gif|jpe?g|png|svg)$/i.test(nsFile.path)) { BMP for Windows?
Attachment #8804035 - Flags: review?(jorgk) → review-
Comment on attachment 8804035 [details] [diff] [review] bug1151366_sec_file_attach.patch (switch to data uris) Review of attachment 8804035 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/components/compose/content/MsgComposeCommands.js @@ +2316,5 @@ > + // Now run it through sanitation to make sure there wasn't any > + // unwanted things in the content. > + let ParserUtils = Components.classes["@mozilla.org/parserutils;1"] > + .getService(Components.interfaces.nsIParserUtils); > + var out = ParserUtils.sanitize(html2, 0); let? @@ -2332,5 @@ > dictionaryRemovalObserver.addObserver(); > > var identityList = document.getElementById("msgIdentity"); > > - document.addEventListener("keypress", awDocumentKeyPress, true); I don't think that should be removed.
(In reply to Jorg K (GMT+2) from comment #285) > 2) I right-clicked an image in another message and selected "Copy Image". > That gets pasted as > <p><img src="imap://info%40hostalpancheta%2Ees@mail.hosta ... and nothing > shows. Dragging a single image from a HTML composition into a new message has the same effect.
I did a bit of research into why the paste from Word fails. The Word-generated HTML includes comments <!-- which |(new XMLSerializer()).serializeToString(doc)| turns into &lt;!--. So <!-- /* Font Definitions */ @font-face {font-family:"Malgun ... shows up in the composition window. Great! Hacking this with html2 = html2.replace(/&lt;!--/g, "<!--").replace(/--&gt;/g, "-->"); still doesn't make it work since the HTML contains <a0:img src="data:image/png;base64,iVBORw0 ... <=== Magnus inserted this. instead of <img src="data:image/png;base64,iVBORw0 ... The former seems to get sanitised away by ParserUtils.sanitize(html2, 0); So there are two problems here, the HTML comments and the funny <a0: tags. I can hack Magnus' patch into a working condition by adding these two lines: html2 = html2.replace(/&lt;!--/g, "<!--").replace(/--&gt;/g, "-->"); html2 = html2.replace(/<a0:/g, "<");
Ehsan/Henri, this is your solution perhaps you can give Magnus some hints. (Ehsan's nick says that he is away until 10th of Nov and Henri until tomorrow).
Flags: needinfo?(hsivonen)
Flags: needinfo?(ehsan)
OK, in defence of the XMLSerializer I should not that Microsofts HTML sucks, the original is 100% invalid: <style> <!-- /* Font Definitions */ @font-face {font-family:"Malgun Gothic"; --> </style> When will M$ learn that <!-- --> is not valid in a style block? However, FF can handle it, but the XMLSerializer can't.
Looking into Magnus' solution a little further. The ParserUtils.sanitize(html2, 0); doesn't fly since it removes any styling. So if you paste from Word with different text styles and colours, they are lost. I haven't looked what the '0' parameter does. If I comment out the sanitisation, it still doesn't work. This is HTML that is inserted: <p class="MsoNormal"><b style="mso-bidi-font-weight:normal"><span style="color:red;mso-ansi-language:EN-US" lang="EN-US">This<span style="color:red;mso-ansi-language:EN-US" lang="EN-US"> <span style="mso-ansi-language:EN-US" lang="EN-US">is text <span style="mso-no-proof:yes"> Note that all text is red since there is another span after the word "This" which turn the "is text" red too. The original HTML was: <p class="MsoNormal"><b style="mso-bidi-font-weight:normal"><span style="color:red;mso-ansi-language:EN-US" lang="EN-US">This</span></b><span style="color:red;mso-ansi-language:EN-US" lang="EN-US"> </span><span style="mso-ansi-language:EN-US" lang="EN-US">is text </span><span style="mso-no-proof:yes"> So pasting into an app type EDITOR works amazingly well, rebuilding that by getting data from the HTML clipboard, massaging it and then inserting it falls victim of a few M-C bugs: - (invalid) comments not done properly. - spans getting confused and closing much too late - funny <a0: tags appearing (or perhaps that's intentional) - [maybe: Sanitisation overzealous removing styling]. Feels like Don Quixote fighting against windmills.
Attached file HTML clipboard produced by MS Word. (deleted) —
Here is some HTML for further experiments. It displays fine in FF and pastes OK into the current TB editor.
As sad as it is, Magnus' solution doesn't seem to work due to bugs in the M-C XMLSerializer. So the only solution I can see working in the short term is the non-purist solution I proposed: Let the clipboard content be inserted into the DOM, then do a C-C "home-made" sanitisation. It's better than nothing. If we do that, we don't need the data URIs and we don't need to switch any defaults which will break add-ons. From Magnus' solution we could adopt the "no panel" approach, so it basically comes down to this modified table (see comment #251): Protocol | Action ----------+------------------------------------------------------------------------------- file | if from temp and younger than a minute: allow, otherwise moz-do-not-send=true, | mark with red CSS frame http(s) | maybe change the default to moz-do-not-send=true, mark with red CSS frame mailnews | allow if clearly visible, otherwise moz-do-not-send=true or remove altogether other | drop Gentlemen and Kent in particular: Branch day is in 10 days and we still even haven't decided what we will do. Extrapolating the current status we will have no solution at all. Clearing NI for Ehsan, maybe Henri has a hint, though I don't think we will be able to fix the XMLSerializer in a flash either, not to mention the sanitisation that tosses styles, etc.
Flags: needinfo?(ehsan)
Comment on attachment 8804035 [details] [diff] [review] bug1151366_sec_file_attach.patch (switch to data uris) Review of attachment 8804035 [details] [diff] [review]: ----------------------------------------------------------------- ::: editor/ui/dialogs/content/EdInsSrc.js @@ +51,5 @@ > + var html = gDialog.srcInput.value; > + // Add back the original data URLs we stashed away earlier. > + html = html.replace(/(data:[^"' >]+) …/g, function(match, p1) { > + return gDataURLs[p1]; > + }); It seems that if you attach multiple images that all start with the same 40 bytes, then invoke this UI and send, you end up sending the same image multiple times duo to the prefix collision. Furthermore, doing the replacement on source code instead of doing it on the DOM in risky. If shortening the URLs for editing is important, it would make sense to a) perform the replacement on the DOM level (in a DocumentFragment) b) use placeholders based on a cryptographic hash. ::: mail/base/content/mailWindow.js @@ +66,5 @@ > + // to data URLs. > + let sourceDoc = getBrowser().contentDocument; > + let selection = sourceDoc.getSelection(); > + for (let img of sourceDoc.images) { > + if (/^(http|data)/.test(img.src)) { I'd be safer to include the colon of the URL scheme here, just in case, and to spell out "http:", "https:" and "data:". @@ +90,5 @@ > + canvas.width = img.width; > + canvas.height = img.height; > + canvas.getContext("2d").drawImage(img, 0, 0); > + > + imgMap.set(img.src, canvas.toDataURL("image/png")); This seems sad compression-wise when the original is a JPEG. @@ +102,5 @@ > + var clonedSelection = selection.getRangeAt(0).cloneContents(); > + var div = sourceDoc.createElement("div"); > + div.appendChild(clonedSelection); > + > + let doc = (new DOMParser()).parseFromString(div.innerHTML, "text/html"); Why is the data first serialized (innerHTML getter) and then reparsed instead of cloning DOM nodes? Also note that the innerHTML getter serializes a fragment but DOMParser parses a full document, so there's a mismatch there. @@ +110,5 @@ > + } > + img.src = imgMap.get(img.src); > + } > + > + let html = (new XMLSerializer()).serializeToString(doc); The serialization should be an HTML serialization instead of an XML serialization. You should use the innerHTML (if you don't want to include the root) or outerHTML (if you do want to include the root). ::: mail/components/compose/content/MsgComposeCommands.js @@ +2266,5 @@ > + return; > + } > + > + let html = dataTransfer.getData("text/html"); > + let doc = (new DOMParser()).parseFromString(html, "text/html"); DOMParser expects a full doc. Aren't clipboard contents typically fragments? Range.createContextualFragment() or the innerHTML setter might be more appropriate here. @@ +2310,5 @@ > + pendingConversions--; > + img.src = dataURL; > + if (pendingConversions == 0) { // We're done! > + // Serialize the modified dom and insert it into the document. > + let html2 = (new XMLSerializer()).serializeToString(doc); Again, XMLSerializer is the wrong serializer to use for HTML, but... @@ +2316,5 @@ > + // Now run it through sanitation to make sure there wasn't any > + // unwanted things in the content. > + let ParserUtils = Components.classes["@mozilla.org/parserutils;1"] > + .getService(Components.interfaces.nsIParserUtils); > + var out = ParserUtils.sanitize(html2, 0); ...it's rather sad to serialize only to reparse again here. I suggest introducing a chrome-only WebIDL binding in c-c that takes a Node and runs nsTreeSanitizer on it without going through the parser. ::: mailnews/compose/src/nsMsgCompose.cpp @@ +4254,5 @@ > +nsMsgCompose::ReplaceFileURLs(nsString &aData) > +{ > + int32_t fPos; > + int32_t offset = -1; > + while ((fPos = aData.RFind(NS_LITERAL_STRING("file://"), offset)) != kNotFound) { Why doesn't this method use the real HTML parser plus DOM manipulation to do the replacement in a safe way?
(In reply to Kent James (:rkent) from comment #281) > (In reply to Henri Sivonen (:hsivonen) from comment #280) > > My point is that when one can't trust emails in the Drafts folder, one can't > > trust their headers, either. So the only option is treating anything that's > > loaded from storage as untrusted and having trustedness an ephemeral in-RAM > > thing. This is, of course, sad for the UX of saving a draft and then > > re-opening it for editing. > > Messages are placed into Drafts by us, so it is possible for us to control > the presence or absence of specific headers in the email. Those specific > headers (or their absence) would be trusted by us. Surely you can use another MUA to place messages in an IMAP Drafts folder.
Flags: needinfo?(hsivonen)
(In reply to Henri Sivonen (:hsivonen) from comment #295) > Surely you can use another MUA to place messages in an IMAP Drafts folder. Now the attack involves two e-mail programs. That second program would have to be specially prepared to produce the TB "trust header", or maybe some existing e-mail program will just pass that through. In the latter case the attack would consist in - getting the victim to download/buy/install that second e-mail program - receive the prepared message and move it to an IMAP drafts folder - Switch to TB and use that draft.
I need to add another severe issue here (which occurred to me while swimming laps in the pool this morning): (In reply to Jorg K (GMT+2) from comment #285) > 1) Pasting from MS Word doesn't work at all, I get HTML pasted as text. This > shows up in the composition: > <!-- /* Font Definitions */ @font-face {font-family:"Malgun Gothic"; etc. > 2) I right-clicked an image in another message and selected "Copy Image". > That gets pasted as > <p><img src="imap://info%40hostalpancheta%2Ees@mail.hosta ... and nothing > shows. > If you select a larger segment, it works. Point 2A): If you reply to/forward/edit-as-new an e-mail that contains an embedded image the following is placed into the composition: <img src="mailbox:///C:/Users/ ... ?number=11&amp;header=quotebody&amp;part=1.2&amp;filename=lijbmghmkilicioj.png" alt=""> or <img src="imap://... /fetch%3EUID%3E.INBOX.SPAM%3E63?header=quotebody&amp;part=1.2&amp;filename=lijbmghmkilicioj.png" alt=""> No image shows. So not only paste places images which are no longer displayed, also simple e-mail operations are broken by this patch. Magnus said: "This seems to work for me." Well, it doesn't for me at all.
(In reply to Henri Sivonen (:hsivonen) from comment #294) Thanks for the comments! > Comment on attachment 8804035 [details] [diff] [review] > ::: editor/ui/dialogs/content/EdInsSrc.js > @@ +51,5 @@ > > + var html = gDialog.srcInput.value; > > + // Add back the original data URLs we stashed away earlier. > > + html = html.replace(/(data:[^"' >]+) …/g, function(match, p1) { > > + return gDataURLs[p1]; > > + }); > > It seems that if you attach multiple images that all start with the same 40 > bytes, then invoke this UI and send, you end up sending the same image > multiple times duo to the prefix collision. Well not send, just insert. That someone used 2 such similar images twice doesn't seem that likely. And, you'd see directly after closing the dialog what you pasted. > If shortening the URLs for editing is important, it would make sense to The editing is not important at all IMHO, and usually you just have an empty dialog where to insert HTML. So this seemed to me like a fair tradeoff. > ...it's rather sad to serialize only to reparse again here. I suggest > introducing a chrome-only WebIDL binding in c-c that takes a Node and runs > nsTreeSanitizer on it without going through the parser. Sure, there's a bit of back and forth so that could be useful. I'll leave that to a followup bug though. > > +nsMsgCompose::ReplaceFileURLs(nsString &aData) > Why doesn't this method use the real HTML parser plus DOM manipulation to do > the replacement in a safe way? It probably could. I didn't want to complicate matters and it's only operating on what you could call internal data.
(In reply to Jorg K (GMT+2) from comment #285) > The r- is for items 1) and 2). > > 1) Pasting from MS Word doesn't work at all, I get HTML pasted as text. This Hopefully that's working now when I'm not using the XMLSerializer. > 2) I right-clicked an image in another message and selected "Copy Image". Fixed. Now only copying image data, not an html flavor to clipboard, for mail internal URIs. > 3) I think we need to allow adding file:// images in Insert > HTML. Not that I like it in other ways either, but it's a slippery slope with when you could attach a file. Yes an attack is not super easy, but it's not hard to imagine someone convincing you "hey, I've got this nice template created. paste this bunch of html into that dialog, it's really nice" - and nobody will notice (and/or understand) within that giant code chunk that they are sending files from their drive, because it's very non-obvious that something like that could happen. > 4) I think we should hide the data URIs in the Image Properties and Link > Properties dialogue. Why? We already have a bunch of cases (drag, some pastes) where data URIs are used. Nobody complained so far. And if you wouldn't see it, then the user has to wonder what it is, do I need to change it, why isn't it showing - and all that kind of problems. > 5) You're changing the behaviour to not attaching http-based images, I think we > need to address this. I suggested a CSS trick. A css trick will be hard to understand. The only way would be to try to explain to the user in some form of notification. But when you add images from a few sources to mix things up, it's just going to be a click-through. But I'm not too worried about this particular change of behaviour.
Attached patch bug1151366_sec_file_attach.patch (still WIP) (obsolete) (deleted) — Splinter Review
Still need to figure out comment 297 which may be a harder nut to crack :/
Attachment #8804035 - Attachment is obsolete: true
Attachment #8804035 - Flags: review?(rkent)
Attachment #8805259 - Flags: feedback?(jorgk)
(In reply to Magnus Melin from comment #299) > > 3) I think we need to allow adding file:// images in Insert > HTML. > Not that I like it in other ways either, but it's a slippery slope with when > you could attach a file. You're changing the way the system behaves and in this case there is nothing the user can do to get the file-based image to show. BTW, where is the code that add-ons could use to convert to data URI? You promised that in comment #163 ("It's easy to cargo-cult the JavaScript code needed for this.") - BTW, cargo-cult?? https://en.wikipedia.org/wiki/Cargo_cult_programming. You meant copy/paste? > > 4) I think we should hide the data URIs in the Image Properties and Link > > Properties dialogue. > Why? We already have a bunch of cases (drag, some pastes) where data URIs > are used. That's right. The UI is slowly deteriorating. We show the user BINARY DATA in the user interface. That's really a complete joke. Just because that crept in slowly doesn't mean it shouldn't be fixed, especially in a solution where data URIs are the normal case. > But I'm not too worried about this particular change of behaviour. I know you're not to worried to smash anything. I on the other hand go though new bugs on almost a daily basis and I know that behaviour change affects people. Especially this one. Someone sends data pasted from a public website and the recipient only sees the content blocked. Someone sends data pasted from an intranet and the recipient sees nothing. The user has no indication that the behaviour has changed and needs to inspect each picture manually.
Comment on attachment 8805259 [details] [diff] [review] bug1151366_sec_file_attach.patch (still WIP) Oh, I've become the testing slave here for a solution that I actually oppose. Let's see: 1) Pasting from Word works now to a certain extent: Text and image are pasted and the red and bold are also visible in the pasted result. However, sanitisation seems to remove all CSS, so the text has "Variable Width" instead of the original Calibri I had in MS Word. Working a little is of course better than not working at all, but still not good enough. 2) Copy image works now. Copying a larger HTML fragment with multiple images also works as before. Maybe you missed comment #287: Dragging a single image inserts: <img src="imap://... and nothing shows. 2A) Comment #297 is also not addressed. Altogether f- for losing the styles in 1) and overlooking comment #287. And as a whole, it doesn't fly so far without giving basic e-mail client functionality like reply/forward, etc. To do comment #297 (point 2A) you'd have to drill somewhere in nsMsgCompose.cpp where the body is assembled to swap any references via mailnews URL to data URIs. BTW, have you thought how all this is affecting SM?
Attachment #8805259 - Flags: feedback?(jorgk) → feedback-
Comment on attachment 8805259 [details] [diff] [review] bug1151366_sec_file_attach.patch (still WIP) Review of attachment 8805259 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/components/compose/content/MsgComposeCommands.js @@ +2289,5 @@ > + // Not anywhere under the temp dir. > + continue; > + } > + > + if (!/\.(gif|jpe?g|a?png|svg|ico)$/i.test(nsFile.path)) { Repeating: What about bmp?
(In reply to Jorg K (GMT+2) from comment #302) > However, sanitisation seems to remove all CSS, so the text has "Variable > Width" instead of the original Calibri I had in MS Word. Indeed: https://dxr.mozilla.org/comm-central/rev/d26ac63f1b81c3fce35448a7c502e95e0b5c56c0/mozilla/parser/html/nsIParserUtils.idl#82 The style here is done via classes, ie, <p class="MsoNormal"> and the CSS for those is stripped. You have my simple test document attached already. Can you not load this into the clipboard somehow for testing?
(In reply to Magnus Melin from comment #299) > Not that I like it in other ways either, but it's a slippery slope with when > you could attach a file. Yes an attack is not super easy, but it's not hard > to imagine someone convincing you "hey, I've got this nice template created. > paste this bunch of html into that dialog, it's really nice" - and nobody > will notice (and/or understand) within that giant code chunk that they are > sending files from their drive, because it's very non-obvious that something > like that could happen. In fact, in your solution you won't send any file since you're turning moz-do-not-send=false into a no-op. So general files are not an issue here. If the user uses the "nice template created" by a third party they don't know and suddenly one of their own pictures shows up right in the middle of it (since you converted the hidden pasted file reference into a data URI) and they click send on this, well, I don't think we need to protect them from this obvious phishing attack.
It would send any files (and likely hidden through styling or size) if they would be converted to data URLs when clicking OK. That's exactly why I'm saying it's totally non-obvious and should not be done. You didn't see it, and you've spent hours with this code. How would an novice user know to guard against something like that. Re preserving all and any styles from Word - given what mess it actually gives out, cleaning should be considered a feature. Changing how much to clean is just sending different flags to the sanitizer of course...
(In reply to Magnus Melin from comment #306) > It would send any files (and likely hidden through styling or size) if they > would be converted to data URLs when clicking OK. That's exactly why I'm > saying it's totally non-obvious and should not be done. I'm talking about images. HTML typically consists of text and images. So you can of course convert images to data URIs if a file based image is inserted as HTML. You do image treatment on paste, so why not here? What am I missing after spending hours with this code? > Re preserving all and any styles from Word - given what mess it actually > gives out, cleaning should be considered a feature. Changing how much to > clean is just sending different flags to the sanitizer of course... We developers all know that MS products produce horrible HTML/CSS. However, users don't know that and *destroying* the formatting of pasted content is not a feature but a *BUG* and won't pass my review. When will you start to understand that we can't destroy a working system to guard against a small security risk?
(In reply to Jorg K (GMT+2) from comment #307) > (In reply to Magnus Melin from comment #306) > > It would send any files (and likely hidden through styling or size) if they > > would be converted to data URLs when clicking OK. That's exactly why I'm > > saying it's totally non-obvious and should not be done. > I'm talking about images. HTML typically consists of text and images. So you > can of course convert images to data URIs if a file based image is inserted > as HTML. You do image treatment on paste, so why not here? What am I missing > after spending hours with this code? As you recall, I'm only converting files under tmp with a bunch of restrictions. If you wholesale convert in the Insert HTML dialog the files could be anywhere (to be useful). > users don't know that and *destroying* the formatting Users just want things to look good. You call it destroying could clear up a lot of inconsistent fonts and more which make their content look bad. > When will you start to understand that we can't destroy a working system to > guard against a small security risk? Well the sanitation flags can be discussed, but what I do now is what a normal pasted sanitation would do. And we do need sanitation, I hope we can agree on this.
(In reply to Magnus Melin from comment #308) > As you recall, I'm only converting files under tmp with a bunch of > restrictions. If you wholesale convert in the Insert HTML dialog the files > could be anywhere (to be useful). I'm not talking about files, I'm talking about *visible* images. And as I said before, in a phishing attack, where someone sends a HTML fragment to be inserted in a specialised expert dialogue, we don't need to be as restrictive as for simple paste that most users can carry out. > Users just want things to look good. You call it destroying could clear up a > lot of inconsistent fonts and more which make their content look bad. We're not implementing "pretty print e-mail" or "remove fonts here". If you paste, you want a 100% copy. Also, HTML produced by MS Word is stock-standard (ugly) and not necessarily inconsistent at all. You can write a perfectly fine and consistent document in MS Word and want to paste its content into an e-mail like thousands of your users do. > And we do need sanitation, I hope we can agree on this. Look, I'm the compose peer here and I need to defend the composing functionality. You need to define "sanitisation" here. You need to remove moz-do-not-send just for http-based images to protect intranet content (since you already turned moz-do-not-send into a no-op for files). I've opposed this change since you're changing existing functionality without any feedback leading to incomplete e-mails being sent. Frankly, even if we were to agree that this is the correct approach, I still wouldn't see why you need to apply a surgical strike here instead of just removing what needs removing.
(In reply to Jorg K (GMT+2) from comment #309) > I'm not talking about files, I'm talking about *visible* images. And as I At that point there is no such thing. All you have is an html fragment. Even if you were to load it in a separate dom and try to figure out visibility after things loaded there are a million ways to make that hard: opacity, placing images on top of each other, slightly off-screen and what not. That's why I check the files are under temp and fill certain criteria. > said before, in a phishing attack, where someone sends a HTML fragment to be > inserted in a specialised expert dialogue, we don't need to be as It's a harder attack. Surely you'd have plenty of luck with the right recipients though. > I still wouldn't see why you need to apply a surgical strike here instead of just removing what needs removing. I'm of course not doing this to break anything. I just find it close to impossible to fix is for real in any other way since it's all wrong by design. But yes, the solution is incomplete atm, and certainly we might choose to wack moles for the ESR - not that interesting in the long run though.
(In reply to Magnus Melin from comment #310) > It's a harder attack. Surely you'd have plenty of luck with the right > recipients though. As any phishing attack has plenty of luck with the right recipients. We need to compare risk with destructive effects of possible risk avoidance. TB doesn't prevent you from receiving phishing e-mail and FF doesn't prevent you from opening phishing links, although they try to some extent. Same here. But I won't argue this any further. "Insert HTML" is not frequently used, and if push comes to shove, users can insert the image directly. However, you still owe add-on authors very clear instruction of how they can haul a file-based image into the composition, since they *must* be able to do it. The best would be a function they can call so they don't have to copy/paste anything. > > I still wouldn't see why you need to apply a surgical strike here instead of just removing what needs removing. > I'm of course not doing this to break anything. Whether with intent or not, you're breaking things. With "surgical strike" I didn't refer to the whole approach (although that's a large scale surgical strike, too), I was merely questioning why you're using the overzealous M-C sanitisation instead of just getting rid of moz-do-not-send as you deem fit. Let's stop discussing. We have other things to do. We still need to hear from Kent which way he wants to go.
(In reply to Magnus Melin from comment #310) > > I'm of course not doing this to break anything. I just find it close to > impossible to fix is for real in any other way since it's all wrong by > design. But yes, the solution is incomplete atm, and certainly we might > choose to wack moles for the ESR - not that interesting in the long run > though. We seem to be having another wack-a-mole problem in figuring out all of the ways that switching off embedded attachment snarfing is breaking functionality, and trying to patch it. I'm not just concerned about the ESR, time is short until TB 52 as well. I just don't see how we can reasonably make such a radical design change this late. In the long run, yes, there are some major design changes that are needed. It seems to me that it is unreasonable to break existing templates and drafts with embedded file and message links, so in any case we need a solution to deal with the existing problem, and that solution is going to look a lot like the simpler solution where we inform the user of the existence of embedded content, and ask for their permission. I know that you want to focus on the long-term solution, but why can't we instead focus on a minimal short-term solution instead? We could land some of your pieces that use more data: uris with new edits. But I am not so sure we can go so far as to depart from APP_TYPE_EDITOR in the short run, and ban embedded file: and message URL snarfing. I'm still thinking that something along the lines of my comment 263 is the right short-term approach. For case #1 (existing messages), OK I see the problems with ever assuming that an opened file is clean, but that means that we need to show embedded content to be attached. To do that, we could add a second box similar to the existing "attachments" box that shows instead "embedded attachments". For case 2) (while editing) we could warn when new snarfable embedded content is being added (plus we would have to get it added to the "embedded attachments" list). I'm not claiming this is perfect, but I think we need to do it in any case to deal with existing drafts and templates. Can't we focus on that simpler case?
(In reply to Kent James (:rkent) from comment #312) > It seems to me that it is unreasonable to break existing templates and > drafts with embedded file and message links, so in any case we need a > solution to deal with the existing problem, and that solution is going to > look a lot like the simpler solution where we inform the user of the > existence of embedded content, and ask for their permission. I know that you > want to focus on the long-term solution, but why can't we instead focus on a > minimal short-term solution instead? Informing in a good way is really hard. At the moment neither solution really covers the mail protocols problem. > We could land some of your pieces that use more data: uris with new edits. > But I am not so sure we can go so far as to depart from APP_TYPE_EDITOR in > the short run, and ban embedded file: and message URL snarfing. These are a bit separate problems. I believe the file: problem is solved. The only thin missing is a solution for the mail protocols. Still investigating that, but it's indeed possible we aren't able to switch from being an EDITOR just yet. That doesn't mean we can't make the changes for the file: inclusions. > I'm still thinking that something along the lines of my comment 263 is the The header thing seems quite complicated to me, and in the end it's still not solving the issue that content will at times end up in the editor by things we don't fully control. For instance, there's been a lot of talk about how my patch might affect add-ons, but I would expect almost all add-ons that does anything with compose content would be affected by this bug. > To do that, we could > add a second box similar to the existing "attachments" box that shows > instead "embedded attachments". Those would be pretty hard to understand for an end user. Add a few of them, then they scroll out of sight anyway.
(In reply to Magnus Melin from comment #313) > (In reply to Kent James (:rkent) from comment #312) > ... I don't really disagree with anything that you said. I've abandoned the header thing as too unreliable, instead we need some sort of informing solution. Yes it is hard. But get my point: if we have existing messages (in drafts or templates) with embedded links, and we cannot assume that anything is safe but we have to give an update path for existing messages, then we have to do some sort of informing solution anyway. The only other option is to say "Thunderbird 52 breaks existing drafts and templates so that embedded content may not actually be sent with the message. Please delete all of your drafts and templates and recreate them". I don't see how that is viable. Informing is not ideal, but IMHO it is a viable minimum solution to the existing problem. For message URLs, the worst offender is editing of saved drafts, as embedded content gets recast as a message URL. But those are also the easiest to solve. I think it is fair to assume that message links to hidden attachments that are in the original draft or template are considered safe to embed. I experimented with detecting those, it is tricky because an attachment is a necko URL while the previous message is a -message url, but translating between those is a solvable problem. I would be willing to break links to attachment URLs from other messages, as they were a bad idea from the start and many get broken inadvertently anyway. We need to be converting those to data: or other protocol anyway.
Let me take a stab at proposing a minimum viable solution that would work for at least TB 52, with possible backport to esr45. 1) We take pieces of Magnus's patches that use data: protocols in various circumstances, with signatures being particularly important. 2) We need a method to detect snarfable content when a link is pasted (Jorg's patch?), and when a message is first opened for editing. Any items that do not fall into a safe category will bring up an inform dialog with a choice to not include. Safe items would include a) time-limited files in TMP that are likely Word (also SoftMaker) cuts and pastes, and b) links to content in the underlying message. Other file: links, and http: or https: links, would be informed. 3) We do NOT disable APP-EDITOR or stop snarfing of protocols. Snarfing is not time limited, as the check is made when content is inserted, either on initial opening, or on paste. I believe this represents a reasonable compromise, doable safely in the time that we have, that would move us in the right direction without causing unreasonable breakage. Comments? In the short run, I'm going to work on the problem of detecting when an attachment URL represents content from the opening message, which would be considered safe-to-snarf content.
(In reply to Kent James (:rkent) from comment #315) > Comments? I think using a panel to ask/inform is OK, but we should cut down the occasions where that will be displayed, ideally not at all in "normal" day-to-day use. For example pre-accept "young" files from temp. Of course asking comes with new strings which are a problem for back-porting. If we remain app type EDITOR and can therefore access files, I see no need to turn pictures in signatures in to data URIs, since that would of course break add-ons like "Signature switch" which just switches signatures by changing HTML in the message that will most likely contain references to local files. Kent, why don't you fill in this table. Do I read your comment correctly? Protocol | Action ----------+------------------------------------------------------------------------------- file | if from temp and younger than a minute: allow (=convert to data URI?), | otherwise ask? http(s) | ask? mailnews | allow of referencing the underlying? message, otherwise? other | drop How do you define underlying? What happens when the user pastes from a completely unrelated message? We also need to define these components of the solution: - Sanitise? How? Via M-C or by hand? - make moz-do-not-send on files a no-op? Or make sure it's sanitised? - Change default for moz-do-not-send or rely on sanitisation?
(In reply to Jorg K (GMT+2) from comment #316) > If we remain app type EDITOR and can therefore access files, I see no need > to turn pictures in signatures in to data URIs, ... Thinking about this a little more at 1 AM: Perhaps the idea is to convert file-based images in signatures to data URIs so that we never have to ask about the file reference later, should such a message be opened again from a draft or edited as new. Right? So the motto would be: "Once data URI, never ask again" ;-) So how about signature switch, the add-on? If it inserts a file URL and we save the message and edit it again later, we get asked about the file. What if the user just switches signatures, gets a file URL inserted and presses send? To not break that, we'd have to not change the default for moz-do-not-send. Or do we require people to edit their existing signature files and add moz-do-not-send=false to all file-based images. Then we couldn't make moz-do-not-send a no-op for file references.
(In reply to Jorg K (GMT+1) from comment #317) > So how about signature switch, the add-on? If it inserts a file URL and we > save the message and edit it again later, we get asked about the file. What > if the user just switches signatures, gets a file URL inserted and presses > send? To not break that, we'd have to not change the default for > moz-do-not-send. Or do we require people to edit their existing signature > files and add moz-do-not-send=false to all file-based images. Then we > couldn't make moz-do-not-send a no-op for file references. I'm still thinking about this. moz-do-not-send was originally designed to be a method to avoid adding the content of files to emails when these files were available on a network as links. It was not envisioned as a security method, that seems to have been added on later, and it is not very effective as a security measure. (If we follow that spirit, then when we convert files to data: uris, we should avoid the conversion if moz-do-not-send="true".) If we continue to allow snarfing of file: and other protocols at sending, then I'm trying to envision a scenario where we gain security by only snarfing if moz-do-not-send="false". It seems to me that if you break our security and can insert a malicious file: link, then you could also set moz-do-not-send="false". So if we allow snarfing of file: links at all, what do we gain by breaking commonly used addons like signature switch? It would not be hard to fix that addon, but why make them go through that hoop if there is nothing actually gained by the change? I still think though that we should be converting embedded cases to data: uris. Maybe we can get far enough that we can turn off file: snarfing completely, but I doubt that in the short run. file: is actually the easiest case. http:// and imap:// are harder because it is difficult to present the user with a notification of snarfing that is interpretable. For http:, here's a proposal. We turn off snarfing of http:// by default, but allow it as an advanced option that comes with some sort of extended description of the consequences. For the large majority of people who do not have access to http:// content that is blocked by a firewall, enabling that is OK (and has the advantage that the email is fully viewable offline, as well as increased privacy). Embedded imap:// links are our own fault, and should be eliminated for other reasons (except for the case of getting links from the current message, which is safe). I think that they are fairly rare anyway for links to other messages, but still common enough to be a source of grief when the attaching... hung after a message was moved. I've experimented with a notification dialog that shows the email subject and allows opening the content for viewing, it is ugly but might be sufficient.
(In reply to Kent James (:rkent) from comment #318) > (If we > follow that spirit, then when we convert files to data: uris, we should > avoid the conversion if moz-do-not-send="true".) Yes. > It seems to me that if you break our security and can insert a > malicious file: link, then you could also set moz-do-not-send="false". That depends on our sanitising effort. Sure, if that has a bug (mole) then the file is shipped out. > file: is actually the easiest case. http:// and imap:// are harder because > it is difficult to present the user with a notification of snarfing that is > interpretable. Yes, that's why I made a suggestion in comment #251 (bottom). > For http:, here's a proposal. We turn off snarfing of http:// by default, > but allow it as an advanced option that comes with some sort of extended > description of the consequences. For the large majority of people who do not > have access to http:// content that is blocked by a firewall, enabling that > is OK (and has the advantage that the email is fully viewable offline, as > well as increased privacy). OK. > Embedded imap:// links are our own fault, and should be eliminated for other > reasons (except for the case of getting links from the current message, > which is safe). I think that they are fairly rare anyway for links to other > messages, but still common enough to be a source of grief when the > attaching... hung after a message was moved. imap:// in this paragraph includes mailbox://, right? I don't follow the "fairly rare". If you reply to a message with an embedded image, you reference that image in 100% of the cases from the original message. So it's not "fairly rare", it is 100% common. After you saved the draft a twice, the reference goes to your latest saved draft. BTW, what do you mean by "current message"? Is that meant to be the latest saved draft? Or the currently viewed message, so no compose scenario?
(In reply to Jorg K (GMT+1) from comment #319) > (In reply to Kent James (:rkent) from comment #318) > > > > Embedded imap:// links are our own fault, and should be eliminated for other > > reasons (except for the case of getting links from the current message, > > which is safe). I think that they are fairly rare anyway for links to other > > messages, but still common enough to be a source of grief when the > > attaching... hung after a message was moved. > imap:// in this paragraph includes mailbox://, right? Yes - and the way that I checked was whatever url could QI to a mailnews URL > I don't follow the "fairly rare". If you reply to a message with an embedded > image, you reference that image in 100% of the cases from the original > message. So it's not "fairly rare", it is 100% common. After you saved the > draft a twice, the reference goes to your latest saved draft. BTW, what do > you mean by "current message"? Is that meant to be the latest saved draft? > Or the currently viewed message, so no compose scenario? These are both addressed by the "current message" exception. And actually there is existing code that does this, see nsMsgCompose::IsEmbeddedObjectSafe There is an original message being processed in the editor, and we assume that content from that message is safe to snarf. "content" here means converted cid: links, converted to message URIs and now pointing to attachments in that same message, not file: or imap: links to other content. The other think I experimented with, which is particularly important in email links, is a simple way to view the content. Unfortunately the filename comes from the link, which in the attack situation has been spoofed. So there is no point in displaying the file name, it only gives a false sense of security. Instead I would display the message subject, and allow you to open the link. I also included the original URL in a tooltip. I should show you my WIP which is meant as an experiment. As for you dialog on comment 251, yes that is what I had in mind. The main comment that I would make is that file names of email attachments
Does anyone know why we claim to support HTML link tags? As far as I can tell, embedded objects come from HTMLEditor::GetEmbeddedObjects(nsIArray** aNodeList) which has this selection criteria: // See if it's an image or an embed and also include all links. // Let mail decide which link to send or not if (element->IsAnyOfHTMLElements(nsGkAtoms::img, nsGkAtoms::embed, nsGkAtoms::a) || (element->IsHTMLElement(nsGkAtoms::body) && element->HasAttr(kNameSpaceID_None, nsGkAtoms::background))) { nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(node); nodes->AppendElement(domNode, false); Here "links" in the comment I think means the <a> element and not <link>, right? So we should not have to look at links? (They are only supposed to be in the header these days anyway, and AFAICT we never process them).
(In reply to Kent James (:rkent) from comment #318) > So if we allow snarfing of file: links at all, what > do we gain by breaking commonly used addons like signature switch? It would I think, nothing. > should be converting embedded cases to data: uris. Maybe we can get far > enough that we can turn off file: snarfing completely, but I doubt that in > the short run. Like I wrote, I believe the file part is completely covered by my patch.
(In reply to Kent James (:rkent) from comment #321) > Does anyone know why we claim to support HTML link tags? Right, there are links like <link href="xxx.css" rel="stylesheet" type="text/css"> and anchors <a>, commonly called links, just to confuse everybody. There is link processing, take a look at nsMsgCompose::IsEmbeddedObjectSafe(), nsMsgComposeAndSend::GetEmbeddedObjectInfo() and nsMsgComposeAndSend::ProcessMultipartRelated(). Without looking at it at all, I'd say that if you ship a HTML page, you need to ship the linked CSS file as well. Well, I tried it, a CSS file referenced in the header doesn't get send.
Then there is the question of anchor elements. Currently, you can insert an <a> element with the advanced dialog, and request that the underlying content be snarfed with the message. When I send the document, this is what I get: <a moz-do-not-send="false" href="cid:part1.635C877B.C12F71E2@fastmail.com">This is a link.</a> and the cid: content contains whatever was read by the original link, here http://mesquilla.com But as far as I can tell, there is no way to actually view that content, clicking on the anchor claims it is about:_blank, and wants to open that in Firefox. I could see the value of being able to create a wrapped document that includes all necessary content to display that offline, including <a> and <link> content (and <embed>). In fact I saw a proposal recently to make such a document a standard. But we don't actually currently really support that, and doing that securely would not be trivial. The half support that we have now seems to be worthless and only a potential hole for security problems. So I propose that we agree that we only support embedded, snarfed <img> elements, and specifically do not allow other types. Magnus' patch sort of implies that, but does not carry it to its logical conclusion of removing explicit support in other places. Are there any known current use cases for <a> in email that I am missing?
(In reply to Magnus Melin from comment #322) > (In reply to Kent James (:rkent) from comment #318) > > So if we allow snarfing of file: links at all, what > > do we gain by breaking commonly used addons like signature switch? It would > > I think, nothing. > > > should be converting embedded cases to data: uris. Maybe we can get far > > enough that we can turn off file: snarfing completely, but I doubt that in > > the short run. > > Like I wrote, I believe the file part is completely covered by my patch. It depends on you definition of "completely". You cover common uses cases, but not for example existing file: links that might be in stored messages, or operations being done by extensions such as Signature Switcher.
(In reply to Kent James (:rkent) from comment #324) > Are there any known current use cases for <a> in email that I am missing? Perhaps I'm missing something, but the most common use would be to insert a file:// URL. That works, the file gets send as attachment and you can click on it at the receiving end. In Magnus latest patch attached file links also get converted to data URIs. Try a PDF.
Comment on attachment 8805259 [details] [diff] [review] bug1151366_sec_file_attach.patch (still WIP) Review of attachment 8805259 [details] [diff] [review]: ----------------------------------------------------------------- I'm going to post some interim feedback here as questions. Still looking this all over (and have been for days!) ::: mail/base/content/utilityOverlay.js @@ +60,5 @@ > + param.setLongValue("imageCopy", > + Components.interfaces.nsIContentViewerEdit.COPY_IMAGE_DATA); > + document.commandDispatcher.getControllerForCommand("cmd_copyImage") > + .QueryInterface(Components.interfaces.nsICommandController) > + .doCommandWithParams("cmd_copyImage", param); I've spent quite a bit of time looking at this, trying to understand how it works and whether it is secure. The URL that we see here is whatever was in the original message. So an IMAP url survives, for example: <img width="1" moz-do-not-send="false" src="imap://msqtest%40fastmail%2Ecom@mail.messagingengine.com:992/fetch%3EUID%3E.INBOX%3E388?part=1.2&amp;filename=myspoofedname.jpg"> This will fetch the first attachment from message #388 that the attacker is interested it. In the viewed message, this is effectively invisible. When copied, the attachment from #388 is used, and ultimately gets sent out in a new message. However, in my tests it appears that the original attachment gets converted to a .png type much shorter than the original attachment, effectively destroying it. However I am not comfortable relying on attachment rewriting as a method of insuring security. Generally I don't believe that we can rely on m-c url handling for imap security, because normal same-origin security does not apply. If we delay the message snarfing until later, in the message composer, then we can confirm that the source message is the origin of the composed message, which is safe content. It's a pity because otherwise I really like this, as it solves the problem we've had of copying images from other messages, than having that fail when the source message is moved. What do you think, Magnus? ::: mail/components/compose/content/MsgComposeCommands.js @@ +2289,5 @@ > + // Not anywhere under the temp dir. > + continue; > + } > + > + if (!/\.(gif|jpe?g|a?png|svg|ico)$/i.test(nsFile.path)) { For detection of whether a file extension is an image, shouldn't you be using nsIMimeService.getTypeFromExtension and testing for "image" in the returned MIME type? See nsContentUtils::IsFileImage(nsIFile* aFile, nsACString& aType) @@ +2298,5 @@ > + let file = new File(nsFile); > + if (file.lastModifiedDate.getTime() < (Date.now() - 60000)) { > + // Not put in temp in the last minute. May be something other than > + // a copy-paste. Let's not allow that. > + continue; This is an interesting concept for an extra security check, but what happens if it fails (and it can since it is timing dependent)? The file does not get converted, right? Is the notification to the user the fact that they cannot see the image in the composer now? @@ +2317,5 @@ > + let out = ParserUtils.sanitize(doc.body.innerHTML, > + ParserUtils.SanitizerAllowStyle); > + getBrowser().contentDocument.execCommand("insertHTML", false, out); > + } > + }, false); Shouldn't you also have an error event? Otherwise on error this never completes, as onLoad does not get called on error.
Attachment #8805259 - Flags: feedback+
Correction, my comment on utilityOverlay.js should have been applied to onCopyOrDragStart in mailWindow. I see that is where the .png conversion was done, but really the same issue exists. It will grab any message URL, snarfing using: canvas.getContext("2d").drawImage(img, 0, 0); ... canvas.toDataURL(). Can we trust that those steps are sufficient to destroy a spoofed critical file that is disguised as an <img>?
So, more on comments 327 and 328: Magnus' patch, as written, modifies the Copy Image function from utilityOverlay.js to convert any URL (except http/data) to a data URL. If an attacker can convince someone to right click on an image, then copy and paste that into another message that is sent to the attacker, then an attachment from another message can be sent out. If the attachment is not actually an image, then the broken image icon is what is being clicked on and copied, but what is sent is the original attachment (like salaries.doc for example). That seems pretty far fetched, as you would have to guess the UUID of the message with the attachment you want, plus get the user to act on a broken image. Any opinions on whether that amount of social engineering is considered a security risk? Even if that is far fetched, it still seems like what we should do is to know what message we are in, and only permit snarfing URLs of the current message, and not just any URL.
(In reply to Kent James (:rkent) from comment #327) > Comment on attachment 8805259 [details] [diff] [review] > bug1151366_sec_file_attach.patch (still WIP) > > Review of attachment 8805259 [details] [diff] [review]: > ----------------------------------------------------------------- > > I'm going to post some interim feedback here as questions. Still looking > this all over (and have been for days!) > > ::: mail/base/content/utilityOverlay.js > @@ +60,5 @@ > > + param.setLongValue("imageCopy", > > + Components.interfaces.nsIContentViewerEdit.COPY_IMAGE_DATA); > > + document.commandDispatcher.getControllerForCommand("cmd_copyImage") > > + .QueryInterface(Components.interfaces.nsICommandController) > > + .doCommandWithParams("cmd_copyImage", param); > > I've spent quite a bit of time looking at this, trying to understand how it > works and whether it is secure. > > The URL that we see here is whatever was in the original message. So an IMAP > url survives, for example: > > <img width="1" > moz-do-not-send="false" > src="imap://msqtest%40fastmail%2Ecom@mail.messagingengine.com:992/ > fetch%3EUID%3E.INBOX%3E388?part=1.2&amp;filename=myspoofedname.jpg"> > > This will fetch the first attachment from message #388 that the attacker is > interested it. > > In the viewed message, this is effectively invisible. When copied, the > attachment from #388 is used, and ultimately gets sent out in a new message. > However, in my tests it appears that the original attachment gets converted > to a .png type much shorter than the original attachment, effectively > destroying it. However I am not comfortable relying on attachment rewriting > as a method of insuring security. I haven't noticed any destruction, if you have some test case please send it to me. It's not attachment rewriting to ensure security, I just made us skip producing pastable html with mail protocol links that no outside consumer could use (and thunderbird should ideally stop using too). So it's not about ensuring security, it's about making something work despite security policies. > If we delay the message snarfing until later, in the message composer, then > we can confirm that the source message is the origin of the composed > message, which is safe content. Not sure I understand what you mean. The reason you would copy is to copy an image into another message. How could you check at paste time that that the interlinking into another message was intended. > This is an interesting concept for an extra security check, but what happens > if it fails (and it can since it is timing dependent)? The file does not get > converted, right? Is the notification to the user the fact that they cannot > see the image in the composer now? Yes. I imagine people just notice it failed, then try again. Might actually be best to bail on the paste completely for such cases, exactly to make people copy again. > @@ +2317,5 @@ > > + let out = ParserUtils.sanitize(doc.body.innerHTML, > > + ParserUtils.SanitizerAllowStyle); > > + getBrowser().contentDocument.execCommand("insertHTML", false, out); > > + } > > + }, false); > > Shouldn't you also have an error event? Otherwise on error this never > completes, as onLoad does not get called on error. I guess so. Or not, if we just want to bail on the paste for that case.
(In reply to Kent James (:rkent) from comment #328) > Correction, my comment on utilityOverlay.js should have been applied to > onCopyOrDragStart in mailWindow. I see that is where the .png conversion was > done, but really the same issue exists. It will grab any message URL, > snarfing using: > > canvas.getContext("2d").drawImage(img, 0, 0); > ... canvas.toDataURL(). > > Can we trust that those steps are sufficient to destroy a spoofed critical > file that is disguised as an <img>? Yes. First of all, the message window does not allow you to link to file:// - so the image (or file for that matter) would not be loaded in the first place - only loaded images can be drawn. Also, even if it could load, only real images can be drawn to the canvas. I just tested linking to a random file and that fails.
(In reply to Kent James (:rkent) from comment #329) > So, more on comments 327 and 328: > > Magnus' patch, as written, modifies the Copy Image function from > utilityOverlay.js to convert any URL (except http/data) to a data URL. Well, skip producing an html flavor to paste. The pasting application will create a data URL when inserting in a document. > If an > attacker can convince someone to right click on an image, then copy and > paste that into another message that is sent to the attacker, then an > attachment from another message can be sent out. If the attachment is not > actually an image, then the broken image icon is what is being clicked on > and copied, but what is sent is the original attachment (like salaries.doc > for example). Did you test that? > That seems pretty far fetched, as you would have to guess the UUID of the > message with the attachment you want, plus get the user to act on a broken > image. Any opinions on whether that amount of social engineering is > considered a security risk? It does seem pretty far fetched. > Even if that is far fetched, it still seems like what we should do is to > know what message we are in, and only permit snarfing URLs of the current > message, and not just any URL. Yes, I completely agree with that.
Attached patch Part 1, snarf uris from same-message copyImage (obsolete) (deleted) — Splinter Review
This is what I'd like to do. I am getting totally lost with all of the pieces of this, let's land what we can to simplify. This is extracting from Magnus' patch just the section that handles the copyImage conversion of message URLs to data URLs. I added a check for same message, so it only does the snarf if the message matches. This is my "review" of a portion of Magnus' patch. This can land at any time. Magnus if you give feedback+ let's call this patch reviewed and ready to land, else modify if - it's still your patch. We might consider opening a new non-security bug to land these first pieces, as they can be justified to stop broken URIs in composed messages independent of any security considerations. So the overall plan is this. Add smaller patches like this one to convert as many embedded URIs as possible to data URIs, then after those are landed we can consider some sort of notification scheme for the remaining unsafe URIs, or disallow them completely depending on what is still left. I'll look at the copy/paste HTML portion next.
Attachment #8807820 - Flags: review+
Attachment #8807820 - Flags: feedback?(mkmelin+mozilla)
(In reply to Kent James (:rkent) from comment #333) > ... let's land what we can to simplify. OK, I'll look into a patch that will hide the ugly data URIs from the UI. We have them now by dragging images, so we can hide them now.
Attached patch part 2, snarf copy and paste images (obsolete) (deleted) — Splinter Review
Here's just the part that modifies copy and drag. I modified it to support moz-do-not-send, and to also snarf anything but data (like http:// urls) as well. However, it has a problem. If the original images is scaled, then what gets put into the canvas is not correct. So for example this will not work correctly in the original message: <img src="http://asset.homechef.com/email/shared/logo.png" width="50"> It acts like the source image is not scaled, but the canvas is truncated to a width of 50. So this needs additional work.
Attachment #8807825 - Flags: feedback?(mkmelin+mozilla)
data URI hiding: Bug 1315440.
Attached patch Use permission dialog on EditAsNew (obsolete) (deleted) — Splinter Review
Jorg, it would be great if you could try to get your comment 251 implemented. After we apply Magnus's patches, but without remove APP_EDITOR and allowing snarfing of any remaining URLs at the end, we still have the permission issue (but it will be for unusual cases). The dialog that you do must be also callable though from C++, since the EditAsNew opening would also use that dialog. I did some experimenting with the call sequence into your dialog, I was not sure how to use your sequence from C++ so I changed it. Maybe there is a better way? This patch is very much a WIP but it gives you some idea of how to integrate your dialog into EditAsNew. We use the same tagging that we use for Forwards and Replies, but instead of assuming all embedded content should not be snarfed, we ask if it is not clearly safe. The checking as safe still needs work so don't look at that.
(In reply to Kent James (:rkent) from comment #337) > After we apply Magnus's patches, but without remove APP_EDITOR > and allowing snarfing of any remaining URLs at the end, ... I'm really confused now too. Magnus has only submitted one patch, part of which you moved into two separate patches, and I moved a UI bit to bug 1315440. Or you refer to the set of them as Magnus' patches? I still don't see a decision on the general approach. I asked in comment #316 (bottom): - Sanitise? How? Via M-C or by hand? - make moz-do-not-send on files a no-op? Or make sure it's sanitised? - Change default for moz-do-not-send or rely on sanitisation? Part of Magnus' patch reaches into the "copy" and "on drag start" and removes any 'undesired' content. Also, copied/dragged content imap/mailbox is converted to data URIs. My panel is actually showing what was inserted into the DOM after "paste" or "drop" finish, but there will be nothing left apart from http-based content: - file URLs are removed unless recent temp. The latter are converted to data URI. - imap/mailbox are converted to data URI. So what goes onto the panel? You want the panel for http-based content? Or is Magnus going to let the file URIs through that he doesn't convert, so we can ask? (There's also the issue of breaking add-ons by disallowing file-based images). Can I please see the larger picture before I start working on a little part. I also have the impression that Magnus is still pursuing his "surgical strike" approach where as you, Kent, are taking a softer approach hitting the known moles.
I've played around with part 1 and 2. Dragging a single image still inserts a imap/mailbox URL. This is the third time I'm mentioning it, previously in comment #287 and comment #302, so this really means f- for part 2 since it's incomplete. As for the JK+RKJ patch: How do you trigger this part: + else if (neckoUri instanceof Components.interfaces.nsIMsgMessageUrl) { + // Get the message associated with this uri + let messageUri = neckoUri.uri; + let messenger = Components.classes["@mozilla.org/messenger;1"] + .createInstance(Components.interfaces.nsIMessenger); + dump("messageUri is " + neckoUri.uri + "\n"); + let hdr = messenger.msgHdrFromURI(messageUri); + + if (/[\?&]part=/.test(neckoUri.spec)) + fileNode.setAttribute("label", 'Attachment from message: "' + hdr.subject + '"'); + else + fileNode.setAttribute("label", 'Message: "' + hdr.subject + '"'); With part 2 also applied, anything copied from another message gets turned into data URIs so it won't go onto the panel. What am I missing? Also, http based images don't go onto the panel yet, I can add this. I noticed that + for (let argument of gElements) { + dump("Window has argument " + argument + "\n"); + } doesn't work and I also noticed that the onAccept() function never prints "=== Including ..." any more and no moz-do-not-sent=false is ever set. That's because the children of gVbox are now your new hbox'es and not my checkboxes any more. Anyway, I'm happy to work on it if we clarify the general direction, see comment #338. Also to clarify, as mentioned, whether imap/mailbox URL will be turned into data URIs or go on the panel.
OK, you can put your copy/paste stuff into bug 1315480 and get it landed. Don't forget to fix the single image drag which still inserts a mailnews URL. I wrapped the bug into some nice words, so it's not suspicious ;-)
Bug 1315440 just landed, so Magnus' patch is now bit-rotten. The hunks from EdInsSrc.js can just be removed and mailComposeEditorOverlay.xul needs to be merged. Well, if it's still required after we've decided on the general approach.
Comment on attachment 8807820 [details] [diff] [review] Part 1, snarf uris from same-message copyImage Review of attachment 8807820 [details] [diff] [review]: ----------------------------------------------------------------- While such isSame message checking could be useful somewhere, why would it be needed here? - Copy Image is only called from the context menu of an image in a message. - The image shouldn't be allowed to be from somewhere else (not sure if that's the case though), but even then, the user choose to copy that image - So it's just copying the one image the user specified. And then they are required to paste it somewhere for anything to possibly happen. At which point the user would see the image - quite different from the "copy a chunk of html" case. And importantly, isn't preserving the full mail protocol url when it's from somewhere else exactly what we DON'T want to do, since at least currently we haven't figured out how to not include-on-send for mailbox/imap urls without significant breakage. The plan to land in pieces is fine by me though. There are a lot of pieces to juggle here...
Attachment #8807820 - Flags: feedback?(mkmelin+mozilla) → feedback-
Comment on attachment 8807825 [details] [diff] [review] part 2, snarf copy and paste images Review of attachment 8807825 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/base/content/mailWindow.js @@ +94,5 @@ > + // in the source document, we wouldn't want it anyway. > + let canvas = sourceDoc.createElement("canvas"); > + canvas.width = img.width; > + canvas.height = img.height; > + canvas.getContext("2d").drawImage(img, 0, 0); Didn't try it yet, but this should either be - using img.naturalWidth and img naturalHeight (to use original sizes) - using ... drawImage(img, 0, 0 , img.width, img.height (to scale the converted image properly)
Attachment #8807825 - Flags: feedback?(mkmelin+mozilla) → feedback+
I'm surprised that this got an f+ since this doesn't handle single image drag. It's only the fourth time I'm asking (before in comments 287, 302 and 339), so to make it quite clear: Magnus and Kent: How do you intend to handle single image drag? With Part 2, a single image drag still leads to a mailnews URL to be inserted.
Flags: needinfo?(rkent)
Flags: needinfo?(mkmelin+mozilla)
"Magnus and Kent: How do you intend to handle single image drag? With Part 2, a single image drag still leads to a mailnews URL to be inserted." The approach that I am taking is trying to get pieces approved and landed that solve pieces of the (imap/file url) -> (data url) issue. A patch does not have to solve the entire problem to be valid as a landable piece. If there is a missing piece, it need not be done in the current patch.
Flags: needinfo?(rkent)
(In reply to Magnus Melin from comment #343) > Comment on attachment 8807825 [details] [diff] [review] > part 2, snarf copy and paste images > > Didn't try it yet, but this should either be > > - using img.naturalWidth and img naturalHeight (to use original sizes) > - using ... drawImage(img, 0, 0 , img.width, img.height (to scale the > converted image properly) I'm hoping that you WILL try it and submit a corrected patch.
(In reply to Magnus Melin from comment #342) > Comment on attachment 8807820 [details] [diff] [review] > Part 1, snarf uris from same-message copyImage > > Review of attachment 8807820 [details] [diff] [review]: > ----------------------------------------------------------------- > > While such isSame message checking could be useful somewhere, why would it > be needed here? While I do not feel strongly, generally in the future there will be no valid use case for an IMAP reference in an email other than to the source message. The only time that isSame would be violated is when an incoming email has a reference to another message, which should not be acceptable in any way. So I see no reason to skip the isSame check here. We are allowing cases where isSame is violated only because there could be existing templates or drafts that might use imap references to other emails that were added prior to the changes suggested in this bug. But if you feel strongly, I could accept leaving out isSame checks here, though I would leave them in, if nothing else than for the sake of consistency.
So how about landing part 1 (with or without the "is same" test) and part 2 in bug 1315480? We still need part 3 to convert the single dragged image. Or perhaps Magnus can address this in part 2 together with the scaling issue. When Kent can next dedicate 30 minutes to this, please answer: - Sanitise? How? Via M-C or by hand? - make moz-do-not-send on files a no-op? Or make sure it's sanitised? - Change default for moz-do-not-send or rely on sanitisation? - JK+RKJ patch: Questions in comment #339: Have we settled for a panel yet? I don't see Magnus' agreement anywhere. What goes onto the panel: Files, assuming that Magnus hasn't dropped or converted them to data URI? Mailnews references? How? They've already been converted to data URI in part 2? Http-based stuff? Can we please decide on the general approach? Otherwise I simply do not know how to take the JK+RKJ patch further as Kent requested in comment #337. Part 1 and 2 only cover issues which aren't controversial.
Flags: needinfo?(rkent)
(In reply to Jorg K (GMT+1) from comment #338) > (In reply to Kent James (:rkent) from comment #337) > > I'm really confused now too. Magnus has only submitted one patch, part of > which you moved into two separate patches, and I moved a UI bit to bug > 1315440. Or you refer to the set of them as Magnus' patches? "Magnus patch" is the one patch that he has added, which tries to convert any known cases where urls get added to the compose into data uris (and turns off snarfing in most cases). > > I still don't see a decision on the general approach. I asked in comment > #316 (bottom): > - Sanitise? How? Via M-C or by hand? > - make moz-do-not-send on files a no-op? Or make sure it's sanitised? > - Change default for moz-do-not-send or rely on sanitisation? The last time that I used the word "sanitize" was in comment 272, which referred to the now-abandoned proposal to track whether messages opened in the composer had been previously sanitized. Instead, the proposal now it to eliminate the need for snarfing in the vast majority of cases by detecting whether content is safe (that is, not of remote origin) at the time it is added to the message, effectively snarfing into a data: url at that point rather than later. moz-do-not-send would continue to work, but not as a security flag but rather, as originally intended, as a method to suppress snarfing for content that is available to recipients in URL form. > > My panel is actually showing what was inserted into the DOM after "paste" or > "drop" finish, but there will be nothing left apart from http-based content: > - file URLs are removed unless recent temp. The latter are converted to data > URI. file URIs should not be removed, unsafe file URIs would just not be snarfed into data uris: at the point of insertion. So if some other application other than MS Word, or an addon, adds a file: uri to the message, that needs to be detected and permission given. Ideally permission requests would be added when the content is first added to the message, as that is when the user knows the most about the source of the unexpected URIs. So scanning and the permission dialog would be used AFTER the conversion to data uris:s for any links that are not snarfed as safe, or during Edit As New. That assumes that we can whack all of the moles that might add content to the Editor, so we can assume it is safe if it is in the editor. If we cannot, then we would have to ask permission at the time of pre-sending snarfing, which is less optimal from a user knowledge perspective. > > So what goes onto the panel? You want the panel for http-based content? Or > is Magnus going to let the file URIs through that he doesn't convert, so we > can ask? (There's also the issue of breaking add-ons by disallowing > file-based images). Snarfing of known safe content into data: uris would leave possibly unsafe uris:, which then need the permission dialog prior to being inserted into the editor. That could include any allowable URIs, including http:, file: or message. If snarfing is denied, we add moz-do-not-send="true" to the tag. So existing addons would not be broken, and if they operate on content after it has been added to the editor, they could insert file: uris without requiring the permission dialog, unless we decide to more the permission dialog to the send process.
(In reply to Kent James (:rkent) from comment #347) > But if you feel strongly, I could accept leaving out isSame checks here, > though I would leave them in, if nothing else than for the sake of > consistency. I'm not too keen on the check at that point because it's never doing anything useful, and the thing the patch does when it theoretically would do something is also wrong, like I explained in comment 342. I'll handle the one-img-dragging, and the scaling bug (both should be easy).
(In reply to Kent James (:rkent) from comment #349) I'm not sure I understood, but there is no such thing as a safe file uri, that we could just leave in there and handle like before. Yes maybe for 45 ESR we would have to allow it, but add-on breakage is certainly allowed for 52. If they do insert file links they quite likely are exposing their users to this bug anyway.
Flags: needinfo?(mkmelin+mozilla)
So I still don't see a consensus here. And I still don't know whether we want that panel. If we want it, Kent now explained what he wants on it at the end of comment #349. However, I still don't see how imap/mailnews-based content could end up there since it's all converted to data URI. What am I missing? How do you trigger the code I quoted: + else if (neckoUri instanceof Components.interfaces.nsIMsgMessageUrl) { + // Get the message associated with this uri + let messageUri = neckoUri.uri; I panel for ESR45 won't work since we can't have new strings (unless we use an old string "Attach File(s)" (see comment #218), so if we're not doing it for ESR52 we don't need to do it at all.
(In reply to Magnus Melin from comment #351) > (In reply to Kent James (:rkent) from comment #349) > I'm not sure I understood, but there is no such thing as a safe file uri. In your patch, you are establishing that a "safe file uri" is one that is in the user's TMP directory, and has been added in the last minute. We will then snarf those without warning, because that check has determined them to be a "safe uri". Nowhere have I proposed "we could just leave in there and handle like before". > Yes maybe for 45 > ESR we would have to allow it, but add-on breakage is certainly allowed for > 52. If they do insert file links they quite likely are exposing their users > to this bug anyway. It is not just addons, but they are important. You have optimized your code to work with Word, meaning that you are assuming that any file: links are put into the TMP directory. I did a couple of other checks, and I could not find something that breaks that. But this is not really an established standard, so it is likely that users are going to have other programs that insert file: links into uris in clipboard content. What are we asking for then? Are we going to just break those programs? Same thing with addons. Experience shows that most of our addon authors are not going to update their software until many months after TB 52 is released, if ever. What happens before then? Do we just break existing users workflows, or make them uninstall our silent update? By using silent updates, Thunderbird should have a very high standard of what they will allow to be broken in updates, so I am proposing the option of the notification permission. I'm just asking for a reasonable path forward for them. As for "If they do insert file links they quite likely are exposing their users to this bug anyway." I don't think that is true at all. The signature addon inserts file links that are files uses have added containing signatures. That is a safe operation.
Flags: needinfo?(rkent)
Shrunked Image Resizer resizes images in the composition and references files from "temp", for example: file:///C:/Users/jorgk/AppData/Local/Temp/IMG_12590.jpg
(In reply to Magnus Melin from comment #350) > (In reply to Kent James (:rkent) from comment #347) > > But if you feel strongly, I could accept leaving out isSame checks here, > > though I would leave them in, if nothing else than for the sake of > > consistency. > > I'm not too keen on the check at that point because it's never doing > anything useful, and the thing the patch does when it theoretically would do > something is also wrong, like I explained in comment 342. > I explained the attack scenario in comment 329. Yes it is far-fetched, but yes I tested it and it works. I think that the point you are missing is that there is nothing to prevent a non-image file or message link from being displayed as an image, then copied as an image. So the point at which it would "do something useful" is when an attacker convinces a user to copyImage of an "image" that is displaying garbage because it is not, in fact, an image. I have no solution for this in the file: case, so I have not proposed to stop it. In the message case, we at least have the isSame check that could check this, so why not do it? Re your comment 342 "And importantly, isn't preserving the full mail protocol url when it's from somewhere else exactly what we DON'T want to do, since at least currently we haven't figured out how to not include-on-send for mailbox/imap urls without significant breakage." Well yes that is true. The argument against the same message check here is that, in the past, we have been inserting message links to other messages, and now we have the opportunity to fix that. OK I could buy that, but you have to accept the far-fetched attack scenario.
(In reply to Jorg K (GMT+1) from comment #348) > So how about landing part 1 (with or without the "is same" test) and part 2 > in bug 1315480? We still need part 3 to convert the single dragged image. Or > perhaps Magnus can address this in part 2 together with the scaling issue. I would be happy to land patches in an open bug without the "security" red flag, if we can. That bug is as good as any. Do not reference this bug there though until we are prepared to open this bug. (In reply to Jorg K (GMT+1) from comment #352) > I still don't see how imap/mailnews-based content could end > up there since it's all converted to data URI. What am I missing? How do you > trigger the code I quoted: > + else if (neckoUri instanceof Components.interfaces.nsIMsgMessageUrl) { > + // Get the message associated with this uri > + let messageUri = neckoUri.uri; This would be triggered in EditAsNew of an existing draft/template that has a message URI. We also need the isSame check to suppress the dialog there. Yes all the glue does not fully exist yet (but see a prototype https://bugzilla.mozilla.org/attachment.cgi?id=8807826).
(In reply to Kent James (:rkent) from comment #356) > I would be happy to land patches in an open bug without the "security" red > flag, if we can. That bug [bug 1315480] is as good as any. Do not reference > this bug there though until we are prepared to open this bug. "That bug" is especially good since I invented a nice LibreOffice story. And of course it has no references to anything. > This would be triggered in EditAsNew of an existing draft/template that has > a message URI. We also need the isSame check to suppress the dialog there. > Yes all the glue does not fully exist yet (but see a prototype > https://bugzilla.mozilla.org/attachment.cgi?id=8807826). Got it! Thanks, no more questions ;-) Oh, one question: Do we have a consensus on the general direction?
Attached patch bug1151366_sec_file_attach.patch (WIP) (obsolete) (deleted) — Splinter Review
Latest fixes. I'll start to split out parts next. Drag single image working, scaling etc.
Attachment #8805259 - Attachment is obsolete: true
Comment on attachment 8809167 [details] [diff] [review] bug1151366_sec_file_attach.patch (WIP) Hmm, this still removes the app type EDITOR, so that's incompatible with the panel solution. I don't see any changes to the paste processing, so (without trying) I'd say that this is still sanitising away the styles from MS Word.
Comment on attachment 8809167 [details] [diff] [review] bug1151366_sec_file_attach.patch (WIP) Sorry, bit-rotten by https://hg.mozilla.org/comm-central/rev/5cb6c4f805a525ffda697c35221af3612f4cccf3 which backed out all stuff in mailComposeEditorOverlay.xul from bug 1315440 in that file. Your original hunks will apply again.
Attachment #8799254 - Flags: feedback?(rkent)
Attachment #8801465 - Flags: feedback?(rkent)
Attached patch bug1151366_sec_file_attach.patch (WIP v2) (obsolete) (deleted) — Splinter Review
Current state after split out to bug 1315480 and bug 1316570.
Attachment #8809167 - Attachment is obsolete: true
Attachment #8807820 - Attachment is obsolete: true
Attachment #8807825 - Attachment is obsolete: true
It is the morning of branch day, 14th Nov. 2016. Three parts of the original patch have landed in bug 1315440, bug 1315480 and bug 1316570. There is still follow-up work in bug 1317049. I'm glad that the amount of content in this bug here has been greatly reduced. Kent keeps saying that I keep saying that no decision has been made on the approach to this bug, and yes, I keep saying this since that is the reality. It is true that Kent has outlined his approach, but I haven't seen any agreement from Magnus yet. We still have attachment 8810223 [details] [diff] [review] with Magnus' original approach: - Stop being app type EDITOR (which won't work for replies and forwards of messages with embedded images) and which won't show file-based images and thus affect add-ons which haul those into the composition. CORRECTION: That hunk has now (silently) been removed? By accident or intentionally? - Switch the default for moz-do-not-send so http-based images won't get send by default. Also, file-based content inserted by add-ons wouldn't get sent. - From discussion in 1316570 I heard of plans to ship data URI with no moz-do-not-send set at all (as produced by bug 1315480) "inline", that is, not as multipart and with no CID-referenced attachment. IHMO this is not a good idea at all since a) it will change existing behaviour, b) make the HTML of the message unreadable and c) stress the line length and lead to those messages being base64 encoded, so the base64 encoded data URI is again base64 encoded in the message body. And on the other hand, there is the panel approach which will present potentially unwanted content from paste and "edit as new" in a panel. Kent asked me to work on that, but I haven't since there it would clash/bitrot other changes in MsgComposeCommands.js. There's also bug 1317049 which needs to implement the function from bug 1315480 in MsgComposeCommands.js. So where do we go from here to minimise bitrot and unwanted work?
(In reply to Jorg K (GMT+1) from comment #362) > CORRECTION: That hunk has now (silently) been removed? By accident or > intentionally? At least temporarily removed until there's a plan to make reply/forward work. > - From discussion in 1316570 I heard of plans to ship data URI with no > moz-do-not-send set at all (as produced by bug 1315480) "inline", that Maybe miscommunication and too many patch versions but that's not my plan for a default. The idea was that that it should be possible, by setting moz-do-not-send=true for the data url. > There's also bug 1317049 which needs to implement the function from bug > 1315480 in MsgComposeCommands.js. Maybe maybe not. I wanted to hold off with that one as it may happen automatically depending on what our composition ends up with internally (=is everything that should already a data url there).
Status: With the attached patch we don't normally get any file:// urls into the DOM. mailbox: nothing changed so far. For remote content we create a RemoteContentNotifierEvent when blocking. How about we block the file/mailbox/imap urls, and do an (to be created) FileContentNotifierEvent/MailContentNotifierEvent - then have a similar bar as for remote content, but require people to go and ok each image separately. Blocking would convert it to data: at that moment, and file: would never be resolved at sent time. Actually we should also be able to convert mailbox to data: on unblock time also. Furthermore that needs to be done once the compose window has loaded (for quoted images). Maybe not being an EDITOR is possible after all. I'll have to check, but if it just causes the image's onerror to be called that's fine as we probably could even base the NotifierEvent on that. This is all just thinking loud - there may be something unforeseen that makes it harder than it should.
s/Blocking would convert it to data:/UNBlocking would convert it to data:/
(In reply to Magnus Melin from comment #363) > > There's also bug 1317049 which needs to implement the function from bug > > 1315480 in MsgComposeCommands.js. > Maybe maybe not. I wanted to hold off with that one as it may happen > automatically depending on what our composition ends up with internally (=is > everything that should already a data url there). Indeed, thanks for updating us on your train of thought. Do good things and *talk* about them ;-) It has been the aim for a long time to not reference MIME parts of other messages to avoid problems at attach time. I don't think it would be a great effort to do, you'd just have to pre-process any mailnews URIs into data URIs, maybe around nsMsgCompose::ResetUrisForEmbed(). At least that's were mailnews URIs are constantly manipulated to point the latest non-superseded draft. Such processing could of course go if we didn't allow mailnews URIs in the composition. Since this bug has already led to major restructuring, maybe we should go the last mile here, too.
Attached patch bug1151366_sec_file_attach.patch (v3) (obsolete) (deleted) — Splinter Review
I believe this is complete but will test it some more. There's a slight beauty error that for replies/forwards you get "Security Error: Content at about:blank may not load or link to mailbox:///h.....ldir/Inbox?number=3903&header=quotebody&part=1.2.2&filename=aft%C3%B6r.png." info message in the console. But that's a thing we recover from. We're longer an EDITOR.
Attachment #8810223 - Attachment is obsolete: true
Eh, "no longer" an EDITOR.
OK, I've been playing with this: When copying text only from MS Word, the style is maintained. When copying an image, the image is inserted as data URI since it was a bitmap anyway in this case. When copying text and image, the text loses its formatting, for the image I get the content notification although I pasted quickly. So something is wrong there. Also I see: An error occurred updating the cmd_align command: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsICommandController.getCommandStateWithParams]" nsresult: "0x80004005 (NS_ERROR _FAILURE)" location: "JS frame :: chrome://editor/content/ComposerCommands.js :: goUpdateCommandState :: line 226" data: no] Turning now to the positive aspects: I also pasted HTML with file-based images and the options dialogue allows me to include them. Also adding a file-based image via "Insert HTML" brings up the notification, nice. So does "Edit draft" and "Edit as new". When replying, the mailbox/imap reference is replaced with a data URI, that basically implements bug 1318450. Also, pasting from a compose window will now work which fixes bug 1317049. I also appreciate the preference "mail.compose.attachHttp" and that fact that, as far as I saw, data URIs are always sent as CID attachment, right? I general I must say that this solution is 1000 times better than what was first presented for review. This is starting to look acceptable ;-) Can I help fixing the problem with copying text and image from Word?
Attached patch bug1151366_sec_file_attach.patch (v4) (obsolete) (deleted) — Splinter Review
Some further tweaks. I'd assume the cmd_align error is unrelated. For the Word case it seems I now get "TypeError: Not enough arguments to File." when trying to call new File(nsFile). Something must have changed since I worked more closely on this, because it certainly worked before. Yes please check what's going on with your Word case, if it's not the above
Attachment #8814670 - Attachment is obsolete: true
Right: JavaScript error: chrome://messenger/content/messengercompose/MsgComposeCommands.js, line 2300: TypeError: Not enough arguments to File.
The problem is here: https://hg.mozilla.org/mozilla-central/rev/938f7fd2ce2b, landed Nov 14, 2016. You now need to use: let file = File.createFromNsIFile(nsFile); If I put that, I revert back to the functionality of the patch of Oct. 27, 2016 which received f- in comment #302 since the CSS is not inserted and therefore the formatting is lost. Not a surprise since that code hasn't changed. Looks like doc.body.innerHTML doesn't contain the CSS we need, you need so serialise the whole document, not just the body. I originally blamed the loss of the CSS on the sanitising, but - as I said - it turns out that the input to the sanitising is already lacking the information we need. This works as pointed out in comment #288: let html2 = (new XMLSerializer()).serializeToString(doc); html2 = html2.replace(/&lt;!--/g, "<!--").replace(/--&gt;/g, "-->"); out = html2.replace(/<a0:/g, "<"); getBrowser().contentDocument.execCommand("insertHTML", false, out); but then we got told off for using XMLSerializer.
Attached patch bug1151366_sec_file_attach.patch (v5) (obsolete) (deleted) — Splinter Review
Attachment #8814739 - Attachment is obsolete: true
Perfect ;-)
Attached patch bug1151366_sec_file_attach.patch (v6) (obsolete) (deleted) — Splinter Review
Added an ifdef not to totally bust seamonkey until they have time to port everything over, fixed some test, added a (very simple) test. I think this is in shape for review now.
Attachment #8815071 - Attachment is obsolete: true
Attachment #8816255 - Flags: review?(rkent)
Attachment #8816255 - Flags: review?(jorgk)
I've been thinking about 45, and maybe we can just do a very minimal fix there: for files, check that it's actually an image/. That's not perfect, but it reduces the exposure quite a bit, and the full patch (+ dependencies) is very disruptive for an ESR.
Comment on attachment 8816255 [details] [diff] [review] bug1151366_sec_file_attach.patch (v6) Review of attachment 8816255 [details] [diff] [review]: ----------------------------------------------------------------- Just some first impressions. I'll give it another more thorough pass through later. I'm interested to see what Kent thinks. Magnus, you've persistently carried through your solution to completion despite all the opposition and delivered a nice piece of software here. This solution is safe and doesn't affect the users too much, and some add-ons just need to adapt. So I'm happy to approve this. ::: mail/test/mozmill/composition/test-blocked-content.js @@ +32,5 @@ > +function setupModule(module) { > + for (let req of MODULE_REQUIRES) { > + collector.getModule(req).installInto(module); > + } > + gOutboxFolder = get_special_folder(Ci.nsMsgFolderFlags.Queue); Nice, but you need to pass as second parameter |true| here just to be safe. Am I mistaken? @@ +62,5 @@ > + "someone@example.com", > + "testing html paste", > + "See these images- one broken one not\n"); > + > + const fname = "./tb-logo.png"; Did you mean to add this file? I can't see it on my system, so is this meant to exist? ::: mail/test/mozmill/composition/test-multipart-related.js @@ +77,5 @@ > compWin.type(null, "someone@example.com"); > compWin.type(compWin.eid("msgSubject"), "multipart/related"); > compWin.type(compWin.eid("content-frame"), "Here is a prologue.\n"); > > + const fname = "./tb-logo.png"; Hmm, using the same file again. Where is it?
The file is added by the patch. Dunno why splinter review doesn't want to show it, but if you look at the raw diff it's there. Re gOutboxFolder, I copied that code from some other test, so it shouldn't be a problem. I think outbox always exists.
Comment on attachment 8816255 [details] [diff] [review] bug1151366_sec_file_attach.patch (v6) Review of attachment 8816255 [details] [diff] [review]: ----------------------------------------------------------------- I was waiting for Kent to comment, but he never showed up. So I went through it again in more detail. ::: mail/components/compose/content/MsgComposeCommands.js @@ +2256,5 @@ > +function onPasteOrDrop(e) { > + // For paste use e.clipboardData, for drop use e.dataTransfer. > + let dataTransfer = ("clipboardData" in e) ? e.clipboardData : e.dataTransfer; > + > + if (!dataTransfer.types.contains("text/html")) { 'contains' is deprecated, use 'includes'. @@ +5386,5 @@ > + return; > + } > + > + let src = event.target.src; > + if (!src || !/^(file|mailbox|imap):/i.test(src)) { This isn't right. You need to cater for Kent's special protocols. See: https://dxr.mozilla.org/comm-central/rev/d15cff28e5b16679c929fec1e32b1964d8bbd8d8/mailnews/compose/src/nsMsgCompose.cpp#401 @@ +5411,5 @@ > + // Appears to reference a random message. Notify and keep blocking. > + gComposeNotificationBar.setBlockedContent(src); > + } > + } > + else { Nit: Who created this style with else on the next line ;-) @@ +5633,5 @@ > + let contentType = Components.classes["@mozilla.org/mime;1"] > + .getService(Components.interfaces.nsIMIMEService) > + .getTypeFromURI(url); > + if (!contentType.startsWith("image/")) { > + throw new Error("Can't unblock; contentType=" + contentType); Maybe a comment here: This shouldn't throw since we're only processing <img> elements. Actually, what happens if in the attack case someone goes: <img="file:// ... secret.pdf">. Will that then throw? And who catches? I haven't tried it, have you? ::: mail/test/mozmill/composition/test-blocked-content.js @@ +53,5 @@ > + Components.interfaces.nsIClipboard.kGlobalClipboard); > +} > + > +/** > + * Test that .... ... what? @@ +108,5 @@ > + wait_for_window_close(); > + > + be_in_folder(gOutboxFolder); > + let outMsg = select_click_row(0); > + let outMsgContent = get_msg_source(outMsg, true); Nice use of utility function, but you don't even look at the return value ;-( ::: mailnews/compose/src/nsMsgCompose.cpp @@ -4302,5 @@ > NS_ENSURE_SUCCESS(rv, rv); > aData.Replace(fPos, end - fPos, dataURL); > - int32_t gtAfter = aData.FindChar('>', fPos + dataURL.Length()); > - if (gtAfter != kNotFound) { > - aData.Insert(NS_LITERAL_STRING(" moz-do-not-send='false'"), gtAfter); Why remove this? @@ -4512,5 @@ > nsString dataURL; > rv = DataURLForFileURL(NS_ConvertUTF8toUTF16(fileURL), dataURL); > if (NS_SUCCEEDED(rv)) { > sigOutput.Append(dataURL); > - sigOutput.AppendLiteral("' moz-do-not-send='false' border=0>"); Why remove this? @@ +4513,3 @@ > } > else { > + sigOutput.Append(NS_ConvertUTF8toUTF16(fileURL)); Why this change? That will cause the file:// to be inserted and then you get the notification in the compose window? Why? ::: mailnews/compose/src/nsMsgSend.cpp @@ +1401,5 @@ > } > > + // Before going further, check what scheme we're dealing with. Files need to > + // be converted to data URLs during composition. "Attaching" means > + // sending as a cid: part instead of original URL.. Nit. Two .. ? @@ +1433,5 @@ > + > +#ifdef MOZ_SUITE > + bool isFile = > + (NS_SUCCEEDED(attachment->m_url->SchemeIs("file", &isFile)) && isFile); > + if (isFile) Could that be written a little less tricky?
I found a bug. Create a message with an embedded image. Save this message as a draft. In the draft we have: <img src="cid:part1.BE061AF7.CC625775@jorgk.com"> "Edit as new" on the draft. Works like a charm. "Edit draft" doesn't work. The image gets loaded as: <img src="mailbox:///C:/Users/jorgk/AppData/Roaming/Thunderbird/Profiles/testing.testing/Mail/Local%20Folders/Drafts?number=13860110&amp;part=1.2&amp;filename=/Bugzilla-down.bmp"> and then your notification triggers. That's not right.
Another bug. I'm playing attacker now. My prepared template contains: <img src="file://D:/Desktop/BVG-Preise-2016.pdf"> This is offered for unblocking and fails with Error: Can't unblock; contentType=application/pdf MsgComposeCommands.js:5637:11 in the error console. As I said, the throw is most likely not so useful. But worse, the notification hangs around even if you already tried to unblock the content.
(In reply to Jorg K (GMT+1) from comment #380) > I found a bug. > Create a message with an embedded image. Save this message as a draft. In > the draft we have: > <img src="cid:part1.BE061AF7.CC625775@jorgk.com"> > "Edit as new" on the draft. Works like a charm. "Edit draft" doesn't work. Here are the full STR: Create a HTML document with this content: <html> <body> huhu<br> <img src="file://D:/Desktop/Bugzilla-down.bmp" klaus-attr="huhu"><br> hihi </body> </html> Open it in FF, and copy to a composition. Unblock the image. Inspect with ThunderHTMLedit, see: <img src="data:image/bmp;filename=%2FBugzilla-down.bmp;base64,…[1]"> ----------------------------------^^^ See an additional problem: A slash which should be there, you're off by one somewhere. Save as draft. Close the compose window. Edit the draft. Works. Save the draft again. Close the compose window. Edit the draft. Does not work. Puzzling? Yes. I compared the source of the draft saved once with the second saved twice. Difference: The second one has two headers X-Identity-Key: id1 These are some of the headers: From - Sat Dec 03 21:22:11 2016 X-Mozilla-Status: 0001 X-Mozilla-Status2: 00000000 X-Mozilla-Keys: FCC: imap://jorgk%40jorgk.com@mail.your-server.de/INBOX/Sent X-Identity-Key: id1 <============================================ X-Account-Key: account1 From: =?UTF-8?Q?J=c3=b6rg_Knobloch?= <jorgk@jorgk.com> Message-ID: <49036db6-bcf6-32d0-125e-da80cf5eb10b@jorgk.com> X-Identity-Key: id1 <============================================= Date: Sat, 3 Dec 2016 21:22:11 +0100 X-Mozilla-Draft-Info: internal/draft; vcard=0; receipt=0; DSN=0; uuencode=0; attachmentreminder=0; deliveryformat=4 You don't even need a image to get this second header. This is already broken in a current Daily without your patch, but it throws your image processing. Maybe there is an error loading the message and you pick up the error event? Just guessing.
Raised bug 1321996 for the doubled-up header.
(In reply to Jorg K (GMT+1) from comment #379) > > + if (!src || !/^(file|mailbox|imap):/i.test(src)) { > > This isn't right. You need to cater for Kent's special protocols. Don't know what those protocols would be. But it's not doable like in your link, because e.g. news: image urls are similar to imap, but still a different story (no error, not blocked, still attached at send time). > Nit: Who created this style with else on the next line ;-) AFAIK it has been so from the very beginning. > > + if (!contentType.startsWith("image/")) { > > + throw new Error("Can't unblock; contentType=" + contentType); > > Maybe a comment here: This shouldn't throw since we're only processing <img> > elements. Actually, what happens if in the attack case someone goes: > <img="file:// ... secret.pdf">. Will that then throw? And who catches? Well the thing is that if you do get there, there's something wrong. Basically you shouldn't get into this situation except when trying to do an exploit, or you manually added some wrong URL. I don't really want to add a lot of UI to try to describe that situation... so I think just throwing the error is fine. That way you can debug by looking in the console if you need to. There's no use trying to catch it, since we do not want to offer a way to "load it anyway". > Why remove this? Because in this solution, they were not needed after all. (It's the default.) > > + sigOutput.Append(NS_ConvertUTF8toUTF16(fileURL)); > > Why this change? That will cause the file:// to be inserted and then you get > the notification in the compose window? Why? Yes, the else is for the error case. In the unlikely case there were problems converting we just put the file url there, so you get a second chance through the notification. > > + > > +#ifdef MOZ_SUITE > > + bool isFile = > > + (NS_SUCCEEDED(attachment->m_url->SchemeIs("file", &isFile)) && isFile); > > + if (isFile) > > Could that be written a little less tricky? I wouldn't bother. Anyway that code should go away as soon as suite ports the changes they need.
(In reply to Magnus Melin from comment #384) > (In reply to Jorg K (GMT+1) from comment #379) > > > + if (!src || !/^(file|mailbox|imap):/i.test(src)) { > > This isn't right. You need to cater for Kent's special protocols. > Don't know what those protocols would be. Ask Kent. He has special protocols and they need to be treated like our message protocols. I'd say you could mimic // 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; in JS and just skip news, etc. if you want. > Well the thing is that if you do get there, there's something wrong. > Basically you shouldn't get into this situation except when trying to do an > exploit, or you manually added some wrong URL. I don't really want to add a > lot of UI to try to describe that situation. Agreed. But at least remove the item from the list if the insertion failed. Is that too much UI?
(In reply to Magnus Melin from comment #384) > > > + sigOutput.Append(NS_ConvertUTF8toUTF16(fileURL)); > > Why this change? That will cause the file:// to be inserted and then you get > > the notification in the compose window? Why? > Yes, the else is for the error case. In the unlikely case there were > problems converting we just put the file url there, so you get a second > chance through the notification. Coming to think about it, I suggest to remove this: - We don't need this extra complication in the code. - How do you test this? Hack it to make the conversion fail? - If the conversion fails, why would it work seconds later in the compose window? - You do conversion twice, once where the HTML is read from a file and once, when the HTML is directly specified. This error path is only there in one case.
(In reply to Magnus Melin from comment #384) > > This isn't right. You need to cater for Kent's special protocols. > Don't know what those protocols would be. I've just looked, he uses: <img src="exquilla:// ... Anyway, Kent's stuff is already broken now as far as embedded images are concerned. If you did what I suggested we'd fix it for him which would be an added bonus. I just wanted to mention: Another bonus of banning file-URLs is that embedded images via file references never showed in a preview of the saved draft in the preview pane. So there you have it, this solution fixes some other bugs on the way ;-)
Attached patch bug1151366_sec_file_attach.patch (v7) (obsolete) (deleted) — Splinter Review
Attachment #8816255 - Attachment is obsolete: true
Attachment #8816255 - Flags: review?(rkent)
Attachment #8816255 - Flags: review?(jorgk)
Attachment #8816751 - Flags: review?(rkent)
Attachment #8816751 - Flags: review?(jorgk)
The protocol include/exclude was actually easily fixable. We wouldn't end up there for news anyway, so if we end up there and the protocol supports fetching we should fetch. I don't seem to be able to reproduce your Edit Draft bug.
(In reply to Jorg K (GMT+1) from comment #386) > Coming to think about it, I suggest to remove this: Well I can remove it if you insist, but it would help someone debug if there are unexpected problems. > - We don't need this extra complication in the code. > - How do you test this? Hack it to make the conversion fail? Yes :) But if it actually didn't work there's little harm done... > - If the conversion fails, why would it work seconds later in the compose > window? Who knows, this is a file IO error basically, but those do happen.
Comment on attachment 8816751 [details] [diff] [review] bug1151366_sec_file_attach.patch (v7) Review of attachment 8816751 [details] [diff] [review]: ----------------------------------------------------------------- Got it reproduced now.
Attachment #8816751 - Flags: review?(rkent)
Attachment #8816751 - Flags: review?(jorgk)
Comment on attachment 8816751 [details] [diff] [review] bug1151366_sec_file_attach.patch (v7) Review of attachment 8816751 [details] [diff] [review]: ----------------------------------------------------------------- Thanks. I'll be back at around 5 PM to take another look. Please try the "edit saved draft" again. You need to: Create. Save. Close. Edit. Save again (that's where the double header gets written). Close. Edit. I'll attach you a message which fails in "edit draft" since it has the header doubled up. I fear that some error happens and you catch this and display the notification. ::: mail/components/compose/content/MsgComposeCommands.js @@ +5411,5 @@ > + .createInstance(Components.interfaces.nsIMessenger) > + .messageServiceFromURI(gMsgCompose.originalMsgURI); > + let originalMsgNeckoURI = {}; > + msgSvc.GetUrlForUri(gMsgCompose.originalMsgURI, originalMsgNeckoURI, null); > + if (src.startsWith(originalMsgNeckoURI.value.spec + "?")) { Why did you add a ? here, there was none before (see interdiff to last version). These URLs can be tricky, and at times the ? comes later, see: https://dxr.mozilla.org/comm-central/rev/5bb2d288ae3ed011048a8a405eadad245c2448be/mailnews/imap/src/nsImapProtocol.cpp#9154
Attached patch bug1151366_sec_file_attach.patch (v8) (obsolete) (deleted) — Splinter Review
Fixed some bugs with draft. But, the re-re-opening-draft-with-embedded still gives you the notification. The reason is that originalMsgURI refers to another (previous) draft for some reason. You get a situation like this: originalMsgNeckoURI.value.spec=mailbox:///.../Drafts?number=44 img src=mailbox:///..../Drafts?number=45 That you end up in that situation seems like bug, but I haven't figured out where that happens. We can fix that later though.
Attachment #8816751 - Attachment is obsolete: true
Attachment #8816759 - Flags: review?(rkent)
Attachment #8816759 - Flags: review?(jorgk)
OK to looking at re-re-opening-draft-with-embedded later. So it's got nothing to do with the double header? (I thought I took the doubled-up header out and it started working, not sure now.) I'm away from my desk, I can check it all tonight. Looks like you're removing a failed conversion from the notification list as I had suggested. Thanks. I still suggest to remove inserting the file name if the conversion to data URI fails for the signature. It's added complication that no one will understand later. Also, no one wants to be prompted about their own signature image. Sure they want to insert it into the message.
Comment on attachment 8816759 [details] [diff] [review] bug1151366_sec_file_attach.patch (v8) Review of attachment 8816759 [details] [diff] [review]: ----------------------------------------------------------------- I'll test it now. ::: mail/components/compose/content/MsgComposeCommands.js @@ +5412,5 @@ > + .messageServiceFromURI(gMsgCompose.originalMsgURI); > + let originalMsgNeckoURI = {}; > + msgSvc.GetUrlForUri(gMsgCompose.originalMsgURI, originalMsgNeckoURI, null); > + if (src.startsWith(originalMsgNeckoURI.value.spec)) { > + // Reply/Forward/Edit Draft can contain references to the images Edit As New is also an option, right? ::: mail/test/mozmill/composition/test-blocked-content.js @@ +108,5 @@ > + cwc.window.goDoCommand("cmd_sendLater"); > + wait_for_window_close(); > + > + be_in_folder(gOutboxFolder); > + let outMsg = select_click_row(0); I don't understand this test. Why do you send the message (later) and then travel to the outbox? Before you read in the message content. It made sense to check it. Now this is just empty processing.
Comment on attachment 8816759 [details] [diff] [review] bug1151366_sec_file_attach.patch (v8) Review of attachment 8816759 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/components/compose/content/MsgComposeCommands.js @@ +5617,5 @@ > + */ > +function onUnblockResource(aURL, aNode) { > + try { > + loadBlockedImage(aURL); > + } finally { Hmm, if loadBlockedImage() throws, you eat the exception here and don't bubble it up, so nothing shows on the console. Is that desired? Before you wanted to sell the console message as a feature ;-)
OK, I'm still looking into the re-re-opening-draft-with-embedded issue which we can solve in another bug. I confirmed that it has nothing to do with the doubled-up X-Identity-Key header. To get to r+ here, please address the following issue, I'll summarise here: From comment #395 1) Include "Edit As New" in comment. 2) Do something useful in the outbox, or don't even send. From comment #396 3) Consider throwing again so something comes out on the console. From comment #394 4) Remove sigOutput.Append(NS_ConvertUTF8toUTF16(fileURL)); What's your plan? Tomorrow, Dec. 5th is the string cut-off date. Do you want to shift this by a day or will this be ready today?
(In reply to Jorg K (GMT+1) from comment #396) > > + try { > > + loadBlockedImage(aURL); > > + } finally { > > Hmm, if loadBlockedImage() throws, you eat the exception here and don't > bubble it up, so nothing shows on the console. Is that desired? Before you > wanted to sell the console message as a feature ;-) Note that there's no catch, so the exception is not eaten.
The re-re-opening-draft-with-embedded issue: I switched "Order received" on, that shows me the message number. I'm editing draft 11 and get: === Necko mailbox:///C:/Users/jorgk/ ... ?number=9 === src mailbox:///C:/Users/jorgk/ ... ?number=11&part=1.2&filename=/Bugzilla-down.bmp Huh? How can the Necko URI be older?? No I repair the folder, my message goes to number 10. Edit gives: Necko 9, src 10. Crazy. Now a new draft, save, number 11. Edit: Necko and src both at 11. Save. Number goes to 12. Edit again, Necko 11, src 12. Looks like gMsgCompose.originalMsgURI doesn't contain what you expect.
(In reply to Magnus Melin from comment #398) > Note that there's no catch, so the exception is not eaten. OK, but I don't see your throw message on the Error Console any more, so what happened? Comment 400 is mine ;-)
break in the finally {} instead of return.
Did the changes you requested. I do get the error in the console when it's thrown, so dunno why you don't. Other changes: - instanceof instead of QueryInterface (since that throws) - more bullet proof determination of filename - retraced the change about double escaping from some mailbox urls. I only found one such case, and I'm not sure about the origin. Maybe one I edited manually at some point.
Attachment #8816759 - Attachment is obsolete: true
Attachment #8816759 - Flags: review?(rkent)
Attachment #8816759 - Flags: review?(jorgk)
Attachment #8816807 - Flags: review?(rkent)
Attachment #8816807 - Flags: review?(jorgk)
Comment on attachment 8816807 [details] [diff] [review] [checked in, comment 404!] bug1151366_sec_file_attach.patch (v9) (In reply to Magnus Melin from comment #402) > - retraced the change about double escaping from some mailbox urls. Retracted? ;-) I didn't think it was necessary. I've seen the &amp; stuff at times, but I forgot where now. I haven't tried this version, but the changes look right. Do you promise that the test passes? You have my blessing to land this now. Or wait for Kent. And we need another bug for the funny draft number issue.
Attachment #8816807 - Flags: review?(jorgk) → review+
The new test should pass, and I had a successful try-run for the other tests earlier https://hg.mozilla.org/comm-central/rev/14bd3b70a7fda2bfb80b0905adb05ceef296e2d4 -> FIXED, fingers crossed Uplifting to aurora needs at least one change: new File(nsFile) instead of File.createFromNsIFile(nsFile)
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 52.0
TB 52 was wishful thinking ;-)
Target Milestone: Thunderbird 52.0 → Thunderbird 53.0
Comment on attachment 8816807 [details] [diff] [review] [checked in, comment 404!] bug1151366_sec_file_attach.patch (v9) Sorry Kent, you didn't show up at the party on time. Marking it as approval-comm-aurora? since all these will be approved and landed together on Monday.
Attachment #8816807 - Flags: review?(rkent) → approval-comm-aurora?
Attachment #8816807 - Flags: approval-comm-aurora? → approval-comm-aurora+
Damn, we shot ourselves in the foot. The |new File(nsFile)| to |File.createFromNsIFile(nsFile)| change landed on mozilla52 already in bug 1303518. So there was no need for a special Aurora patch. Pushed a fix here: https://hg.mozilla.org/releases/comm-aurora/rev/ab1eb5ee1f6903a9045eb021ed1e87d0bca0e090
Attached patch bug1151366_mozmill-fix.patch (obsolete) (deleted) — Splinter Review
Attachment #8816849 - Flags: review?(jorgk)
Comment on attachment 8816849 [details] [diff] [review] bug1151366_mozmill-fix.patch Does this fix anything or just move a bunch of code into the try {} so we don't see the error? The error is this: INFO - TEST-START | C:\slave\test\build\tests\mozmill\composition\test-blocked-content.js | test_paste_file_urls INFO - JavaScript error: chrome://messenger/content/messengercompose/MsgComposeCommands.js, line 2280: NS_ERROR_FILE_UNRECOGNIZED_PATH: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFileProtocolHandler.getFileFromURLSpec] Failing here: let nsFile = Services.io.getProtocolHandler("file") .QueryInterface(Components.interfaces.nsIFileProtocolHandler) .getFileFromURLSpec(img.src); Did you actually change anything in the block you moved? If the path is wrong on Windows, you need to massage it a bit, no?
Attached patch 1151366-fix-windows-throw.patch (deleted) — Splinter Review
Attachment #8799254 - Attachment is obsolete: true
Attachment #8800870 - Attachment is obsolete: true
Attachment #8801465 - Attachment is obsolete: true
Attachment #8807826 - Attachment is obsolete: true
Attachment #8816849 - Attachment is obsolete: true
Attachment #8816849 - Flags: review?(jorgk)
Attachment #8816867 - Flags: review?(mkmelin+mozilla)
Attachment #8816807 - Attachment description: bug1151366_sec_file_attach.patch (v9) → [checked in, comment 404!] bug1151366_sec_file_attach.patch (v9)
Comment on attachment 8816867 [details] [diff] [review] 1151366-fix-windows-throw.patch Review of attachment 8816867 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/components/compose/content/MsgComposeCommands.js @@ +2276,5 @@ > // Doesn't start with file:. Nothing to do here. > continue; > } > > + // On Windows, this throws. Maybe better: "May throw if the URL is invalid for this OS."
Attachment #8816867 - Flags: review?(mkmelin+mozilla) → review+
Depends on: 1322223
Magnus, we had a complaint from Tonnes, the German localiser. You landed: %S has blocked a file from loading into this message. Unblocking will include the file in your sent message.; %S has blocked some files from loading into this message. Unblocking will include the file in your sent message. Tonnes suggests to change this to: Unblocking will include the file*s* ... in the plural form. Is this a copy/paste error or deliberate since files are unblocked individually? I can do three things here: 1) Do nothing 2) append the "s" without changing the string name 3) append the "s" and change the string name 3) is problematic since it's officially too late for string changes. 2) is probably OK, since the localisers most probably used the plural form in their translation. Please advise.
Flags: needinfo?(mkmelin+mozilla)
Flags: needinfo?(mkmelin+mozilla)
Group: mail-core-security → core-security-release
No longer depends on: 1310377
I discussed this with jorgk, and he and I believe it would be best to hold off including this until TB 52, as it makes some pretty serious changes to the way things are handled. Open for discussion, though.
Agreed.
Attachment #8654958 - Attachment description: armin@rawsec.net,2500?,2015-04-05,,2015-08-31,true,,, → armin@rawsec.net,2500,2015-04-05,,2015-08-31,true,,,
Would it be possible to implement a whitelist for local images? When I use Stationery / signatures to refer local files these may be URL encoded and they will be distrusted. It would be fantastic if I would not have reiterate the "trust" option for one given file (e.g. logo in signature)/ Just make remot-whitelist.json file listing all locations that are allowed. Alterntively this could be a good topic for new Addon. I will add some workaround code into my addon (SmartTemplate4) but it is going to be very XPCOM dependant I can already tell.
I'm not sure what the problem is. Also I don't understand the "... these may be URL encoded and they will be distrusted". Yes, if you place a file: URL into the composition, you get a notification. So don't do it ;-) file: URLs in signatures will be replaced with data: URL in the compose pipeline, that was done in bug 1316570. Some add-ons, like "Signature Switch" and "Shrunked Image Resizer", brought out new versions that also do this conversion so the users doesn't see any change. There is code in C-C you can copy to do that conversion.
Given that this is fixed in Thunderbird 52, and TB 45 is no longer security-fix-supported since 4 months, can I remove the embargo of this bug, please? The fix here broke stuff in other places.
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: