Open Bug 1330113 Opened 7 years ago Updated 2 years ago

X-ray wrappers share event listener attributes with untrusted code

Categories

(Core :: XPConnect, defect, P3)

50 Branch
defect

Tracking

()

People

(Reporter: kigorw, Unassigned)

References

Details

(Whiteboard: triaged)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36

Steps to reproduce:

1. In WebExtension code (you have to install simple web extension, and in content script) write: 
```
window.onerror = function() {
  console.log('error')
}
```
2. Open console and write: `window.onerror` then write `window.onerror.something`




Actual results:

It equals function. And then when you execute `window.onerror.something` you will get an exception. 


Expected results:

`window.onerror` should be `undefined` by default
Component: Untriaged → WebExtensions: Untriaged
Product: Firefox → Toolkit
Luca to reproduce and investigate.
webextensions: --- → +
Component: WebExtensions: Untriaged → WebExtensions: General
Priority: -- → P1
Whiteboard: triaged
I tried to reproduce it locally and start looking into it.

Follows some additional detail about this issue.

a "security wrapped function object " is assigned to onerror property, the web content javascript cannot call it (and errors are logged in the console), but it is nevertheless defined (which is unexpected).

by looking a bit more deeply in it, we can notice that:

- if from the content script we try to assign a function to a non existent window property, from the web content that new property is still undefined (as expected),

- if the property is an existent attribute defined in the WebIDL (e.g. onload, onerror, oncontextmenu, etc), the property value is set to the wrapped function (which cannot be used and it will raise exception if we try to call it from the web content).

This issue doesn't look like a "WebExtensions specific" issue, but it seems to be valid for any non-content javascript code that tries to do the same. 

Ideally, what it should happen here is that:

- the value assigned from the addon to the WebIDL attribute should be visible only from the non-content javascript code;

- similarly, if it is the web content to set a value on an existent WebIDL attribute, from the content script we should get an undefined value when we try to access the related property on the "security wrapped window" (while currently, the content script gets the value as assigned from the web content).
NOTE: as a workaround to the particular scenario described in Comment 0, from a content script it would be better to subscribe the error event using the addEventListener method (which should behave correctly on both the browsers).
Hi Kris, do you know if there is any existent plans for implementing something similar to the behavior described in the last part of Comment 2?
Flags: needinfo?(kmaglione+bmo)
This is something we could implement, but I'm not sure whether it's entirely desirable. Or if it's worth the effort, given that `addEventListener` already handles this correctly. But I suppose it is a bit of a footgun for people who aren't expecting it.
webextensions: + → ---
Component: WebExtensions: General → XPConnect
Flags: needinfo?(kmaglione+bmo)
Product: Toolkit → Core
Summary: WebExtension window.onerror shared with page → X-ray wrappers share event listener attributes with untrusted code
Priority: P1 → --
So the console is running in the same context as the Web Extension? Is this intentional?
Flags: needinfo?(kmaglione+bmo)
No, the extension code is running in a Sandbox that inherits from the content window. The console code is running in the context of the content window that it inherits from. The problem is less for code executed in the console, though as for code executed from page scripts.
Flags: needinfo?(kmaglione+bmo)
Thanks for the explanation, Kris! I'll set the priority here as "backlog (aka P3)" but am happy to change that if it's incorrect.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
That's OK with me.

Would it be possible to add a detection for this to the Addon review process? At least then the developers would be notified not to use events directly, but to implement addEventListener() instead.

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.