mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-03-03 00:19:30 +00:00
22 lines
615 B
TypeScript
22 lines
615 B
TypeScript
import { configContext } from "../ConfigContext";
|
|
|
|
export function isInvalidParentFrameOrigin(event: MessageEvent): boolean {
|
|
return !isValidOrigin(configContext.allowedParentFrameOrigins, event);
|
|
}
|
|
|
|
function isValidOrigin(allowedOrigins: string[], event: MessageEvent): boolean {
|
|
const eventOrigin = (event && event.origin) || "";
|
|
const windowOrigin = (window && window.origin) || "";
|
|
if (eventOrigin === windowOrigin) {
|
|
return true;
|
|
}
|
|
|
|
for (const origin of allowedOrigins) {
|
|
const result = new RegExp(origin).test(eventOrigin);
|
|
if (result) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|