Simplify the "valid-origin" check for cross-iframe messages.
This commit is contained in:
Jonathan Protzenko 2015-04-27 13:51:28 -07:00
Родитель 324a76242f
Коммит f91c0e5ec3
2 изменённых файлов: 8 добавлений и 12 удалений

Просмотреть файл

@ -9,11 +9,9 @@ module TDev {
// ---------- Communication protocol // ---------- Communication protocol
var allowedOrigins = { function isAllowedOrigin(origin: string) {
"http://localhost:4242": null, return origin.indexOf((<any>document.location).origin) == 0;
"https://www.touchdevelop.com": null, }
"https://mbitmain.azurewebsites.net": null
};
// Both of these are written once when we receive the first (trusted) // Both of these are written once when we receive the first (trusted)
// message. // message.
@ -28,7 +26,7 @@ module TDev {
var currentVersion: string; var currentVersion: string;
window.addEventListener("message", (event) => { window.addEventListener("message", (event) => {
if (!(event.origin in allowedOrigins)) if (!isAllowedOrigin(event.origin))
return; return;
if (!outer || !origin) { if (!outer || !origin) {

Просмотреть файл

@ -6,11 +6,9 @@ module TDev {
// ---------- Communication protocol // ---------- Communication protocol
var allowedOrigins: { [index: string]: any } = { function isAllowedOrigin(origin: string) {
"http://localhost:4242": null, return origin.indexOf((<any>document.location).origin) == 0;
"https://www.touchdevelop.com": null, }
"https://mbitmain.azurewebsites.net": null
};
var $ = (s: string) => document.querySelector(s); var $ = (s: string) => document.querySelector(s);
@ -24,7 +22,7 @@ module TDev {
var inMerge: boolean = false; var inMerge: boolean = false;
window.addEventListener("message", (event) => { window.addEventListener("message", (event) => {
if (!(event.origin in allowedOrigins)) { if (!isAllowedOrigin(event.origin)) {
console.error("[inner message] not from the right origin!", event.origin); console.error("[inner message] not from the right origin!", event.origin);
return; return;
} }