From 130e5f504b65dfeaff3c3fd51f610dbc9de66cea Mon Sep 17 00:00:00 2001 From: majkel Date: Fri, 13 May 2022 17:28:53 +0800 Subject: [PATCH 1/2] Clone data to avoid altering the original postMessage payload Currently xdomain modifies the original data array in the postMessage handler, which breaks other scripts on the host that send arrays through postMessage. --- src/lib/socket.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/socket.js b/src/lib/socket.js index a3564fa..ee1dea0 100644 --- a/src/lib/socket.js +++ b/src/lib/socket.js @@ -112,6 +112,7 @@ exports.initialise = () => { if (!(d instanceof Array)) { return; } + d = d.slice(); //return unless lead by an xdomain id const id = d.shift(); if (!/^xdomain-/.test(id)) { From 66ddc187974dded1f5ac53fd70abad8e951b5879 Mon Sep 17 00:00:00 2001 From: majkel Date: Tue, 17 May 2022 11:47:40 +0800 Subject: [PATCH 2/2] Don't clone FormData, as sometimes it results in an error In some cases the browser won't allow cloning the FormData object using slice method. To avoid potential errors like this, we revert the change allowing xdomain to work on the original FormData object, but only after checking that the message originated from xdomain library. --- src/lib/socket.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/socket.js b/src/lib/socket.js index ee1dea0..04a106c 100644 --- a/src/lib/socket.js +++ b/src/lib/socket.js @@ -112,12 +112,11 @@ exports.initialise = () => { if (!(d instanceof Array)) { return; } - d = d.slice(); //return unless lead by an xdomain id - const id = d.shift(); - if (!/^xdomain-/.test(id)) { + if (!/^xdomain-/.test(d[0])) { return; } + const id = d.shift(); //finally, create/get socket let socket = sockets[id]; //closed