From 11eb25eaae655861f276789998c653185275df5b Mon Sep 17 00:00:00 2001 From: Daniel Brain Date: Wed, 2 Jan 2019 10:36:54 +0000 Subject: [PATCH] Extra safety around getting source window from post message --- src/drivers/receive/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/drivers/receive/index.js b/src/drivers/receive/index.js index 1f06908c..e7595278 100644 --- a/src/drivers/receive/index.js +++ b/src/drivers/receive/index.js @@ -124,11 +124,19 @@ export function messageListener(event : { source : CrossDomainWindowType, origin // $FlowFixMe let messageEvent : MessageEvent = { - source: event.source || event.sourceElement, + source: event.source || event.sourceElement || event.srcElement, origin: event.origin || (event.originalEvent && event.originalEvent.origin), data: event.data }; + if (!messageEvent.source) { + throw new Error(`Post message did not have source window`); + } + + if (!messageEvent.origin) { + throw new Error(`Post message did not have origin domain`); + } + if (__TEST__) { if (needsGlobalMessagingForBrowser() && isSameTopWindow(messageEvent.source, window) === false) { return;