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

window.addEventListener('message') should verify the message origin #329

Closed
jchayan opened this issue Feb 20, 2017 · 2 comments
Closed

window.addEventListener('message') should verify the message origin #329

jchayan opened this issue Feb 20, 2017 · 2 comments

Comments

@jchayan
Copy link
Contributor

jchayan commented Feb 20, 2017

I notice you are using the postMessage API for cross-origin communication. In my application there are other programs implementing this as well, which causes these messages to enter in your event listener (relay.js:28: events.bind(window, 'message', listener)).

In my use case, I'm receiving strings via postMessage, which causes relay.js:29: var data = JSON.parse(event.data) to fail. There should exist origin checking in order to avoid conflicts, e.g:

events.bind(window, 'message', function listener (event) {
    if (event.origin === 'https://api.recurly.com') { /* or whatever property that holds this value */
        var data = JSON.parse(event.data);
        var name = data.recurly_event;
        var body = data.recurly_message;
        var err = body.error ? errors('api-error', body.error) : null;
        events.unbind(window, 'message', listener);
        if (name) self.emit(name, err, body);
        if (frame) document.body.removeChild(frame);
    }
});
@jchayan
Copy link
Contributor Author

jchayan commented Feb 20, 2017

I can merge the fix for this

jchayan added a commit to jchayan/recurly-js that referenced this issue Feb 20, 2017
jchayan added a commit to jchayan/recurly-js that referenced this issue Feb 22, 2017
chrissrogers added a commit that referenced this issue Feb 22, 2017
@jchayan
Copy link
Contributor Author

jchayan commented Feb 23, 2017

@chrissrogers This should be closed :)

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

2 participants