Closed Bug 848939 Opened 12 years ago Closed 12 years ago

De-field in-content XBL bindings

Categories

(Toolkit :: General, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla22
Tracking Status
firefox22 --- fixed
firefox-esr17 --- wontfix
b2g18 --- wontfix

People

(Reporter: bholley, Assigned: bholley)

References

Details

(Keywords: sec-other, Whiteboard: [adv-main22-])

Attachments

(3 files, 4 obsolete files)

The semantics of XBL fields dictate that they must be accessible to code running in the bound scope, which made things tricky when hoisting XBL into a separate compartment. We ended up defining the field as a property on the bound node (as before), and then waiving Xray whenever the XBL code accesses the field. Various in-content bindings make heavy use of <field>s to store state. Because we're waiving Xray here, this ends up losing us a lot of the protections introduced by XBL scopes. Talking to dolske and jaws, it doesn't sound like there's no real reason we need to do things this way, and could instead define them in the constructor as expandos on the Xray-ed |this|. In bug 843829, I'm trying to reduce the attack surface of XBL scopes by making all content objects without an explicit Xray waiver opaque. But this involves applying a full Xray waiver whenever accessing fields, which, in the current field-happy world, causes this waiver to propagate just about everywhere, losing our Xray vision. But really, this is nothing that a clever attacker couldn't do anyway. All bets are off once Xray is waived, and content can lead us wherever it wants. Marking this s-s because I don't want to make too much noise about this XBL stuff for the time being.
Attached patch Part 1 - De-field scale.xml. v1 (deleted) — Splinter Review
Attachment #722630 - Flags: review?(jAwS)
Attached patch Part 2 - De-field videocontrols.xml. v1 (obsolete) (deleted) — Splinter Review
Attachment #722631 - Flags: review?(jAwS)
Attached patch Part 3 - De-field marquee. v1 (deleted) — Splinter Review
Attachment #722632 - Flags: review?(jAwS)
Attachment #722631 - Flags: review?(jAwS) → review+
Attachment #722630 - Flags: review?(jAwS) → review+
Comment on attachment 722632 [details] [diff] [review] Part 3 - De-field marquee. v1 Review of attachment 722632 [details] [diff] [review]: ----------------------------------------------------------------- I'd like to get a sign-off from Neil that these changes are OK too.
Attachment #722632 - Flags: review?(jAwS)
Attachment #722632 - Flags: review?(enndeakin)
Attachment #722632 - Flags: review+
(In reply to Jared Wein [:jaws] from comment #5) > Comment on attachment 722632 [details] [diff] [review] > Part 3 - De-field marquee. v1 > > Review of attachment 722632 [details] [diff] [review]: > ----------------------------------------------------------------- > > I'd like to get a sign-off from Neil that these changes are OK too. Where these refers to all three patches.
Once we do this, can we kill off the automatic Xray waiver for fields altogether?
Comment on attachment 722632 [details] [diff] [review] Part 3 - De-field marquee. v1 I don't know anything about marquee elements nor what this bug is even talking about.
Attachment #722632 - Flags: review?(enndeakin)
(In reply to Boris Zbarsky (:bz) from comment #7) > Once we do this, can we kill off the automatic Xray waiver for fields > altogether? It would be green in our tree, sure. But it seems like the main point of all of our field shenanigans is to preserve compat as much as possible, right? It seems like it would require changes to every in-content XBL binding that uses <field>s, since most all of them would depend on manipulating that field from XBL in some way, right?
Jared, in light of comment 9: Am I green to land, or do you want input from someone else?
Flags: needinfo?(jAwS)
It would be good to get another set of eyes looking at this too. Maybe Dao can help?
Status: NEW → ASSIGNED
Flags: needinfo?(jAwS) → needinfo?(dao)
What info do you need? Would you like me to review a patch? All patches?
Flags: needinfo?(dao)
(In reply to Dão Gottwald [:dao] from comment #12) > What info do you need? Would you like me to review a patch? All patches? Yeah, if you could.
> It seems like it would require changes to every in-content XBL binding that uses <field>s Oh, I guess the issue would be extensions (remote XBL is handled by just not using a separate scope there is the plan, iirc). Yeah, ok.
Comment on attachment 722631 [details] [diff] [review] Part 2 - De-field videocontrols.xml. v1 > <constructor> > <![CDATA[ >+ this.scrubberNameFormat = "&scrubberScale.nameFormat;"; <![CDATA[... &scrubberScale.nameFormat; ...]]> isn't going to work as intended.
Attachment #722631 - Flags: review?(dao) → review-
(In reply to Dão Gottwald [:dao] from comment #15) > Comment on attachment 722631 [details] [diff] [review] > <![CDATA[... &scrubberScale.nameFormat; ...]]> isn't going to work as > intended. Can you suggest a fix? This isn't my area of expertise.
You can break out of the CDATA section like this: ]]>&scrubberScale.nameFormat;<![CDATA[
Attached patch Part 2 - De-field videocontrols.xml. v2 r=jaws (obsolete) (deleted) — Splinter Review
Attachment #722631 - Attachment is obsolete: true
Attachment #724284 - Flags: review?(dao)
Attachment #724284 - Flags: review?(dao) → review+
(In reply to Dão Gottwald [:dao] from comment #15) > Comment on attachment 722631 [details] [diff] [review] > Part 2 - De-field videocontrols.xml. v1 > > > <constructor> > > <![CDATA[ > >+ this.scrubberNameFormat = "&scrubberScale.nameFormat;"; > > <![CDATA[... &scrubberScale.nameFormat; ...]]> isn't going to work as > intended. Thank you for catching that.
Comment on attachment 722632 [details] [diff] [review] Part 3 - De-field marquee. v1 Flagging for aurora approval. This applies to all three patches. One of the major features that's now on aurora is the ability to run in-content XBL in a separate compartment. This grants us a number of security wins, but the security invariants are weakened each time we enter the content compartment, which we have to do for <field>. A number of our in-content XBL bindings use <field>, though there's no effective difference in doing that as opposed to just defining expandos on the target object. This patch is low-ish risk, insofar as everything that touches XBL bindings has an inherent risk. I suggest baking this for a few days on m-c, and then landing it on m-a if there's no fallout.
Attachment #722632 - Flags: approval-mozilla-aurora?
Whiteboard: [leave open]
Whiteboard: [leave open]
Bobby, the test failure looks to come from this line: http://mxr.mozilla.org/mozilla-central/source/toolkit/content/widgets/videocontrols.xml#707 Does that usage of document.getAnonymousElementByAttribute not work in this scenario?
Comment on attachment 722632 [details] [diff] [review] Part 3 - De-field marquee. v1 Removing approval for now.
Attachment #722632 - Flags: approval-mozilla-aurora?
Ugh, so I just sunk a number of hours into this. After a very very long trail of breadcrumbs, I've figured out what's happening. The videoControls binding has a <field> called randomID. This is turns out to be the culprit, and the error goes away when I undo the change from <field> to Xray expando. This was somewhat baffling at first, because none of the code seemed to depend on that property living on the underlying object. After some time, however, I discovered that the property was actually being undefined on the underlying object by content/xbl when the binding was stripped off. And the videoControls code actually depends on randomID becoming |undefined| when the element is unbound and it encounters this element in an event handler. Yuck. So anyway. The most straightforward solution is to replace access to randomID with a function that checks whether the element is bound and returns undefined if it isn't. What's the cleanest way to detect whether an element is bound or not?
I decided to hack something up with document.getAnonymousNodes, which seems to work. I also de-fielded TouchUtils, which I missed last time: https://tbpl.mozilla.org/?tree=Try&rev=ba48f66d7c25
Attached patch Part 2 - De-field videocontrols.xml. v3 (obsolete) (deleted) — Splinter Review
Looks green modulo intermittent orange. Flagging jaws for review.
Attachment #724284 - Attachment is obsolete: true
Attachment #726272 - Flags: review?(jAwS)
Attachment #726272 - Flags: review?(jAwS) → review?(dao)
(In reply to Bobby Holley (:bholley) from comment #27) > videoControls code actually depends on randomID becoming |undefined| when > the element is unbound and it encounters this element in an event handler. Sounds like you could just delete randomID in the XBL <destructor>?
(In reply to Dão Gottwald [:dao] from comment #30) > (In reply to Bobby Holley (:bholley) from comment #27) > > videoControls code actually depends on randomID becoming |undefined| when > > the element is unbound and it encounters this element in an event handler. > > Sounds like you could just delete randomID in the XBL <destructor>? Yes, but AFAICT XBL <destructor>s aren't reliably called, per bug 230086.
(In reply to Bobby Holley (:bholley) from comment #31) > (In reply to Dão Gottwald [:dao] from comment #30) > > (In reply to Bobby Holley (:bholley) from comment #27) > > > videoControls code actually depends on randomID becoming |undefined| when > > > the element is unbound and it encounters this element in an event handler. > > > > Sounds like you could just delete randomID in the XBL <destructor>? > > Yes, but AFAICT XBL <destructor>s aren't reliably called, per bug 230086. Because the binding wouldn't be detached in that case, so we'd get the same behavior as with <field>.
Well, ClearDocument doesn't appear to fire destructors, for example: http://mxr.mozilla.org/mozilla-central/source/content/xbl/src/nsBindingManager.cpp#858 If you prefer though, I can try implementing it with a <destructor> and see if anything breaks.
Yes, I'd prefer that.
Attached patch Part 2 - De-field videocontrols.xml. v4 (obsolete) (deleted) — Splinter Review
Attachment #726272 - Attachment is obsolete: true
Attachment #726272 - Flags: review?(dao)
Attachment #726420 - Flags: review?(dao)
Comment on attachment 726420 [details] [diff] [review] Part 2 - De-field videocontrols.xml. v4 >@@ -1628,18 +1625,19 @@ > // If the video is not at the start, then we probably just > // transitioned into or out of fullscreen mode, and we don't want > // the controls to remain visible. this.controlsTimeout is a full > // 5s, which feels too long after the transition. > if (video.currentTime !== 0) { > this.delayHideControls(this.Utils.HIDE_CONTROLS_TIMEOUT_MS); > } > } >- }) ]]> >- </field> >+ }; >+ ]]> >+ </constructor> > > </implementation> nit: indent ]]> and </constructor> with two more spaces
Attachment #726420 - Flags: review?(dao) → review+
Doh, stupid typo in TouchControls, which only affects android (the call to init needs to come after the property is defined). https://tbpl.mozilla.org/?tree=Try&rev=db513a6851de
So, _this_ one is orange, because it looks like XBL bindings with inheritance don't execute the <destructor> of their super-binding. Indeed, I don't see anywhere in the code that would make that happen. :-( bz, is this a known bug? I don't see one on file...
Flags: needinfo?(bzbarsky)
Not known offhand to me, but XBL destructors are generally so broken I haven't really looked into them much....
Flags: needinfo?(bzbarsky)
This just duplicates the destructor. Let me know if you want me to go back to my old approach pre comment 31 and comment 33.
Attachment #727434 - Flags: review?(dao)
Attachment #726420 - Attachment is obsolete: true
Attachment #727434 - Flags: review?(dao) → review+
Depends on: 853747
Whiteboard: [adv-main22-]
Group: core-security
(In reply to Bobby Holley (busy) from comment #4) > Created attachment 722632 [details] [diff] [review] > Part 3 - De-field marquee. v1 This makes the certain marquee properties undefined while the constructor of the binding hasn't been called yet.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: