Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LeftAndMain.js assumes iframe postmessages are strings #6562

Closed
roed opened this issue Jan 24, 2017 · 4 comments
Closed

LeftAndMain.js assumes iframe postmessages are strings #6562

roed opened this issue Jan 24, 2017 · 4 comments

Comments

@roed
Copy link
Contributor

roed commented Jan 24, 2017

In LeftAndMain.js, there is a method that handles messages triggered in iframes (postMessage):

$(window).on("message", function(e) {
    var target,
        event = e.originalEvent,
        data = JSON.parse(event.data);

I tried to integrate a third party app that uses such messages, but the event.data is an object, not a string. This causes an error, because it tries to parse an object. Perhaps it is better to check if event.data is a string, and, if so, parse it:

data = typeof event.data == 'string' ? JSON.parse(event.data) : event.data;
@dhensby
Copy link
Contributor

dhensby commented Jan 24, 2017

want to open a PR?

roed added a commit to roed/silverstripe-framework that referenced this issue Jan 24, 2017
See issue: silverstripe#6562

This is a fix for that, which was already implemented in the code for version 4.0.
@roed
Copy link
Contributor Author

roed commented Jan 24, 2017

Was already fixed in 4.0, but still made a PR.

@dhensby
Copy link
Contributor

dhensby commented Jan 24, 2017

thanks

@sminnee sminnee closed this as completed May 1, 2017
@michalkleiner
Copy link
Contributor

Came across a Chrome plugin for Grammarly using this mechanism.
It sends string messages in event.data. The JS here fails to JSON.parse them. The logic needs further strengthening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants