Skip to content

Commit 4ba87c8

Browse files
webview: check message source frame (#10202)
Mitigate https://bugs.eclipse.org/bugs/show_bug.cgi?id=575924
1 parent 6abc784 commit 4ba87c8

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

packages/plugin-ext/src/main/browser/webview/pre/host.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,28 @@
2525
const hostMessaging = new class HostMessaging {
2626
constructor() {
2727
this.handlers = new Map();
28-
window.addEventListener('message', (e) => {
29-
if (e.data && (e.data.command === 'onmessage' || e.data.command === 'do-update-state')) {
28+
window.addEventListener('message', e => {
29+
let sourceIsChildFrame = false;
30+
for (let i = 0; i < window.frames.length; i++) {
31+
const frame = window.frames[i];
32+
if (e.source === frame) {
33+
sourceIsChildFrame = true;
34+
break;
35+
}
36+
}
37+
if (sourceIsChildFrame && e.data && (e.data.command === 'onmessage' || e.data.command === 'do-update-state')) {
3038
// Came from inner iframe
3139
this.postMessage(e.data.command, e.data.data);
32-
return;
3340
}
34-
35-
const channel = e.data.channel;
36-
const handler = this.handlers.get(channel);
37-
if (handler) {
38-
handler(e, e.data.args);
39-
} else {
40-
console.error('no handler for ', e);
41+
// Note: `window.parent === window` when there is no parent...
42+
if (sourceIsChildFrame || e.source === window.parent) {
43+
const channel = e.data.channel;
44+
const handler = this.handlers.get(channel);
45+
if (handler) {
46+
handler(e, e.data.args);
47+
} else {
48+
console.error('no handler for ', e);
49+
}
4150
}
4251
});
4352
}

packages/plugin-ext/src/main/browser/webview/pre/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@
193193
initialScrollProgress: undefined
194194
};
195195

196-
197196
/**
198197
* @param {HTMLDocument?} document
199198
* @param {HTMLElement?} body

0 commit comments

Comments
 (0)