2020-08-06 20:03:46 +01:00
|
|
|
import { configContext } from "../ConfigContext";
|
2020-05-26 03:30:55 +01:00
|
|
|
|
|
|
|
export function isInvalidParentFrameOrigin(event: MessageEvent): boolean {
|
2020-08-06 20:03:46 +01:00
|
|
|
return !isValidOrigin(configContext.allowedParentFrameOrigins, event);
|
2020-05-26 03:30:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function isValidOrigin(allowedOrigins: RegExp, event: MessageEvent): boolean {
|
|
|
|
const eventOrigin = (event && event.origin) || "";
|
|
|
|
const windowOrigin = (window && window.origin) || "";
|
|
|
|
if (eventOrigin === windowOrigin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = allowedOrigins && allowedOrigins.test(eventOrigin);
|
|
|
|
return result;
|
|
|
|
}
|