Stop using raw HTML strings in chat (chat broken)
Categories
(Chat Core :: General, defect, P1)
Tracking
(thunderbird_esr78 unaffected, thunderbird78 unaffected, thunderbird79 wontfix, thunderbird80 fixed)
Tracking | Status | |
---|---|---|
thunderbird_esr78 | --- | unaffected |
thunderbird78 | --- | unaffected |
thunderbird79 | --- | wontfix |
thunderbird80 | --- | fixed |
People
(Reporter: darktrojan, Assigned: lasana)
References
()
Details
(Keywords: regression)
Attachments
(1 file, 6 obsolete files)
9.57 KB,
patch
|
mkmelin
:
review+
wsmwk
:
approval-comm-beta+
|
Details | Diff | Splinter Review |
I'm not sure if it's because of bug 1646483 or it just turned up at the same time, but code such as this which modifies HTML strings and adds them to documents is no longer working ("the operation is insecure"). I did a quick replacement of this function using DOM methods, which worked, but I realised there's much more, so I didn't land that.
Chat is currently broken by this.
Comment 1•4 years ago
|
||
Geoff -- just to confirm, this affects > 79, correct?
Updated•4 years ago
|
Reporter | ||
Comment 2•4 years ago
|
||
Correct.
Comment 4•4 years ago
|
||
(In reply to Geoff Lankow (:darktrojan) from comment #0)
I'm not sure if it's because of bug 1646483 or it just turned up at the same time, but code such as this which modifies HTML strings and adds them to documents is no longer working ("the operation is insecure"). I did a quick replacement of this function using DOM methods, which worked, but I realised there's much more, so I didn't land that.
Would it be possible to get this patch or do we know if something can be backed out to get this to work again? I wanted to work on some chat stuff and this is interfering unfortunately! I might just throw some log statements in that code and read it on the console too...
Comment 5•4 years ago
|
||
Florian -- curious if you've seen anything that might be causing this? Bug 1646483 doesn't quite feel right to me, but it might be the cause!
Reporter | ||
Comment 6•4 years ago
|
||
Here's what I did at the time. As you can see I didn't get far, and I don't recall what the last piece is about.
Updated•4 years ago
|
Comment 7•4 years ago
|
||
Florian, Lasana,
This is now a blocker for 79
Assignee | ||
Comment 8•4 years ago
|
||
I'm looking into it but I'm still learning what does what (using 68 to figure some of it out). If anyone more experienced has a quick fix I'll be happy to submit a patch. I don't get the "the operation is insecure" message and I see some of the initial HTML in the document so I have been digging further to see what's going on.
Comment 9•4 years ago
|
||
I'm unlikely to have time to fix this soon, but if you have questions about what the existing code does or was trying to do, I can likely answer them.
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Comment 10•4 years ago
|
||
Ok this is what I have learned about this so far:
I was able to see the error message after some try catch fiddling and a debug build. There was an if clause in a progress listener in conversations-browser
as well that bails out before we run into the failure.
The source of the failure seems to be here:
https://searchfox.org/comm-central/source/mozilla/dom/security/DOMSecurityMonitor.cpp#101
This might be a duplicate of bug 1636388.
Basically APIs like innerHTML etc are not allowed in privileged (chrome) code with a few exceptions for specific files. It would take me a while to figure out all the various functions operating on raw HTML and convert them to DOM (not to mention possibly break things) so I opted instead for a simpler path of using iframes like here:
https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Displaying_web_content_in_an_extension_without_security_issues
The only thing with this approach is that I can't access the iframe body content until a load event is fired, possibly because of bug 543435. So I had to make a few functions async
. Currently I don't have any catch
at their call sites, advice on handling potential errors in a user friendly manner is welcome!
I'm attaching a patch for feedback before I go any further.
Assignee | ||
Comment 11•4 years ago
|
||
With this irc seems to work again.
Assignee | ||
Comment 12•4 years ago
|
||
There is another use of Range#createContextualFragment
to update and possibly other uses of innerHTML
. I'll do other patches for them. This one at least makes chat usable again.
The functions I made async mostly get called in event handler style code or as a side effect as with MozConversationBrowser#isActive
so they should not cause any immediate problems.
Assignee | ||
Updated•4 years ago
|
Comment 13•4 years ago
•
|
||
We are proceeding to make 79.0b1 live with chat broken. So it will be urgent to quickly pick up the fixing patch in b2.
Comment 14•4 years ago
|
||
A couple of comments / questions I see:
- This seems to add an iframe per message, I would be surprised if this worked properly with all of themes. Have you tested the bubbles theme, for example? Are we concerned about the performance impact of all the additional nodes?
- I think Florian also asked a reasonable question which was not answered:
what's the cause of the problem exactly? I was wondering if there might be a way to create a document with lower privileges so that the security code doesn't care if we are using 'unsafe' methods there.
Link to previous conversation about this: https://matrix.to/#/!fubIsJzeAcCcjYTQvm:mozilla.org/$SzRWsaXQvaV8xQhpxGZvX-PBTzgi6ylYsFCJy2BLhd8?via=mozilla.org&via=matrix.org&via=privacytools.io
I think the general approach that this uses DOM methods is OK, it is really the iframe piece I'm unsure about.
Comment 15•4 years ago
|
||
Assignee | ||
Comment 17•4 years ago
|
||
Here is an additional but broken patch.
I reverted insertHTMLMessage
to be sync and added a custom protocol handler to load the conv.html
called conv://
. This still runs into the innerHTML() in privileged code error.
I assume it's because I still use a chrome URL to actually load the file but I'm unsure. Also not sure how else the file can be loaded, maybe via a file URL?
Comment 19•4 years ago
|
||
Were you able to test whether MozChatConversation
class should have a type="content"
assigned (as https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Displaying_web_content_in_an_extension_without_security_issues suggests)?
It might be worth reaching out to someone on the DOM team to see if they can help us solve this?
Assignee | ||
Comment 21•4 years ago
|
||
Were you able to test whether MozChatConversation class should have a type="content"
That does not appear to make a difference. The MozConversationBrowser where the messages gets displayed has a type="content"
attribute in any case and does not appear to resolve this.
I spent some hours looking at the custom protocol handler approach and I don't think it would work here. In order to load the conv.html
I need to set some security flags and I could not figure out a way to do that from nsIWebnavigation.loadURI
.
Assignee | ||
Comment 22•4 years ago
|
||
In this patch, I kept the getDocumentFragmentFromHTML
function but I'm providing it without using iframes. I use the nsIParserUtils
api so no need to make anything async here.
Updated•4 years ago
|
Comment 24•4 years ago
|
||
Assignee | ||
Comment 25•4 years ago
|
||
Updated after some changes landed that affect imThemes.jsm.
Yes Geoff's patch can be obsoleted now.
Updated•4 years ago
|
Comment 26•4 years ago
|
||
Updated•4 years ago
|
Comment 27•4 years ago
|
||
Assignee | ||
Comment 29•4 years ago
|
||
Additional patch for html variable.
Comment 30•4 years ago
|
||
Comment 31•4 years ago
|
||
Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/c9d5f6ed6aaa
Use nsIParserUtils instead of innerHTML for chat messages. r=mkmelin
Comment 32•4 years ago
|
||
Comment on attachment 9167743 [details] [diff] [review]
use-nsIParserUtils-updated.patch
[Approval Request Comment]
Regression caused by (bug #): We're not 100%, maybe an m-c change?
User impact if declined: chat won't work
Testing completed (on c-c, etc.): I've tested it on local builds.
Risk to taking this patch (and alternatives if risky): I don't think we can make things worse than they are?
Comment 33•4 years ago
|
||
Comment on attachment 9167743 [details] [diff] [review]
use-nsIParserUtils-updated.patch
[Triage Comment]
Approved for beta
Yay
Comment 34•4 years ago
|
||
bugherder uplift |
Thunderbird 80.0b2:
https://hg.mozilla.org/releases/comm-beta/rev/97990ee27996
Updated•4 years ago
|
Comment 35•4 years ago
|
||
Chat (IRC) is working in my testing of the 80.0b2 release candidate on Ubuntu 18.04.4.
Comment 36•4 years ago
|
||
However after a few days of using it I went to check something in a previous conversation and the chat area was blank.
Caused by the fix to this bug?
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Comment 37•4 years ago
|
||
Not sure. All this patch really does is replace direct innerHTML
and createContextualFragment
use with calls to the nsIParserUtils
api. Maybe somewhere else we are running into the security exception? I was using a debug build to track them down.
Comment 38•4 years ago
|
||
(In reply to WaltS48 [:walts48] from comment #36)
However after a few days of using it I went to check something in a previous conversation and the chat area was blank.
Caused by the fix to this bug?
It looks like logs aren't showing up properly. Can you (WaltS48 or Lasana) file a follow-up issue to this? Thank you!
Assignee | ||
Comment 39•4 years ago
|
||
Regarding the issue of what caused the problem in the first place, as far as I could tell anything loaded via a chrome://
scheme is going to be treated as privileged code by the security mechanism and thus not allowed to use innerHTML
etc. That is to say; as far as I can tell we are not allowed to load chrome code and treat it as content. That's the impression I got by looking at some of the nsISecurityPrincipal
and nsILoadInfo
code. I could not find a way to properly change the loadingPrincipal when I tried making the custom protocol.
Description
•