Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safeguard init exthost message #142486

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class WebWorkerExtensionHost extends Disposable implements IExtensionHost

// Send over message ports for extension API
const messagePorts = this._environmentService.options?.messagePorts ?? new Map();
iframe.contentWindow!.postMessage(messagePorts, '*', [...messagePorts.values()]);
iframe.contentWindow!.postMessage({ type: 'vscode.init', data: messagePorts }, '*', [...messagePorts.values()]);

port.onmessage = (event) => {
const { data } = event;
Expand Down
17 changes: 15 additions & 2 deletions src/vs/workbench/services/extensions/worker/extensionHostWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,33 @@ function connectToRenderer(protocol: IMessagePassingProtocol): Promise<IRenderer

let onTerminate = (reason: string) => nativeClose();

interface IInitMessage {
readonly type: 'vscode.init';
readonly data: ReadonlyMap<string, MessagePort>;
}

function isInitMessage(a: any): a is IInitMessage {
return !!a && typeof a === 'object' && a.type === 'vscode.init' && a.data instanceof Map;
}

export function create(): { onmessage: (message: any) => void } {
performance.mark(`code/extHost/willConnectToRenderer`);
const res = new ExtensionWorker();

return {
onmessage(messagePorts: ReadonlyMap<string, MessagePort>) {
onmessage(message: any) {
if (!isInitMessage(message)) {
return; // silently ignore foreign messages
}

connectToRenderer(res.protocol).then(data => {
performance.mark(`code/extHost/didWaitForInitData`);
const extHostMain = new ExtensionHostMain(
data.protocol,
data.initData,
hostUtil,
null,
messagePorts
message.data
);

onTerminate = (reason: string) => extHostMain.terminate(reason);
Expand Down