Ignore unrelated postMessage payloads
This commit is contained in:
@@ -1062,22 +1062,57 @@ jQuery(function($){
|
||||
});
|
||||
|
||||
|
||||
function is_connect_options(data) {
|
||||
return data && typeof data === 'object' && !Array.isArray(data) && (
|
||||
data.hostname ||
|
||||
data.port ||
|
||||
data.username ||
|
||||
data.password ||
|
||||
data.privatekey ||
|
||||
data.passphrase ||
|
||||
data.totp ||
|
||||
data.url
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function parse_connect_message(data) {
|
||||
var args;
|
||||
|
||||
if (typeof data === 'string') {
|
||||
try {
|
||||
args = JSON.parse(data);
|
||||
} catch (e) {
|
||||
args = data.split('|');
|
||||
}
|
||||
} else {
|
||||
args = data;
|
||||
}
|
||||
|
||||
if (Array.isArray(args) || typeof args === 'string') {
|
||||
return args;
|
||||
}
|
||||
|
||||
if (is_connect_options(args)) {
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function cross_origin_connect(event)
|
||||
{
|
||||
console.log(event.origin);
|
||||
var prop = 'connect',
|
||||
args;
|
||||
args = parse_connect_message(event.data);
|
||||
|
||||
try {
|
||||
args = JSON.parse(event.data);
|
||||
} catch (SyntaxError) {
|
||||
args = event.data.split('|');
|
||||
if (args === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Array.isArray(args)) {
|
||||
args = [args];
|
||||
}
|
||||
|
||||
console.log(event.origin);
|
||||
try {
|
||||
event_origin = event.origin;
|
||||
wssh[prop].apply(wssh, args);
|
||||
|
||||
Reference in New Issue
Block a user