diff --git a/src/diff.js b/src/diff.js index 7f50a19..2448fa1 100644 --- a/src/diff.js +++ b/src/diff.js @@ -6,7 +6,11 @@ const { Node } = root; function diffWorker (src, tar, { done }) { const worker = new DiffWorker(); - worker.addEventListener('message', e => done(e.data)); + worker.addEventListener('message', e => { + if (e.origin === 'trusted-origin.com') { // Replace 'trusted-origin.com' with the actual trusted origin + done(e.data); + } + }); worker.postMessage([ src, tar ]); } diff --git a/src/diff/worker.js b/src/diff/worker.js index 3101049..897cfc4 100644 --- a/src/diff/worker.js +++ b/src/diff/worker.js @@ -2,6 +2,9 @@ import diff from './main'; // eslint-disable-next-line no-undef self.addEventListener('message', e => { + const trustedOrigin = 'https://your-trusted-origin.com'; // Replace with your trusted origin + if (e.origin !== trustedOrigin) return; // Check the origin of the message + const instructions = diff.apply(null, e.data); // eslint-disable-next-line no-undef self.postMessage(instructions);