Use custom event rather than window.postMessage
ClosedPublic

Authored by broulik on Aug 29 2019, 3:05 PM.

Details

Summary

window.postMessage requires a targetOrigin which isn't enforced by all browsers.
This patch changes it to send a custom event which reduces the likelihood of interference and eavesdropping.

BUG: 411423

Test Plan
  • Firefox and Chrome still get proper media controls
  • Waterfox works fine now

Diff Detail

Repository
R856 Plasma Browser Integration
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
broulik created this revision.Aug 29 2019, 3:05 PM
Restricted Application added a project: Plasma. · View Herald TranscriptAug 29 2019, 3:05 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
broulik requested review of this revision.Aug 29 2019, 3:05 PM
broulik edited the test plan for this revision. (Show Details)
broulik edited the summary of this revision. (Show Details)
fvogt added a comment.Aug 29 2019, 3:20 PM

Always provide a specific targetOrigin, not *, if you know where the other window's document should be located. Failing to provide a specific target discloses the data you send to any interested malicious site.

I wonder whether that is relevant to us?

broulik added a comment.EditedAug 29 2019, 3:46 PM

Further down it says

It is not possible for content or web context scripts to specify a targetOrigin to communicate directly with an extension (either the background script or a content script).

I can probably set it to document.location.href but not sure what that'll gain us?

broulik added a comment.EditedAug 29 2019, 4:04 PM

What we could also do which I just realized is that we could send a CustomEvent to the window instead of using postMessage
Basically what we did before except without a wrapper div as while the JavaScript contexts are different, events posted to window are visible from the content script.

fvogt added a comment.Aug 29 2019, 4:48 PM

What we could also do which I just realized is that we could send a CustomEvent to the window instead of using postMessage
Basically what we did before except without a wrapper div as while the JavaScript contexts are different, events posted to window are visible from the content script.

That does sound much nicer actually. Looking at the documentation it seems like that's intended as the main way for communication with extensions even.

broulik updated this revision to Diff 64957.Aug 29 2019, 4:57 PM
broulik retitled this revision from Call window.postMessage with targetOrigin to Use custom event rather than window.postMessage.
broulik edited the summary of this revision. (Show Details)
broulik edited the test plan for this revision. (Show Details)
  • Use custom event
fvogt accepted this revision.Aug 29 2019, 5:04 PM

Tested, works fine

This revision is now accepted and ready to land.Aug 29 2019, 5:04 PM
This revision was automatically updated to reflect the committed changes.
This comment was removed by bcooksley.
bcooksley removed a subscriber: fuksitter.