mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-12-02 02:17:01 +00:00
1b9070605e
* Make MongShell message handler backwards compatible * Fix test title and add one more test case
35 lines
933 B
TypeScript
35 lines
933 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;
|
|
}
|
|
}
|
|
console.error(`Invalid parent frame origin detected: ${eventOrigin}`);
|
|
return false;
|
|
}
|
|
|
|
export function isReadyMessage(event: MessageEvent): boolean {
|
|
if (!event?.data?.kind && !event?.data?.data) {
|
|
return false;
|
|
}
|
|
|
|
if (event.data.kind !== "ready" && event.data.data !== "ready") {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|