Only allow webviews protocol in top level editor windows

This commit is contained in:
Matt Bierner
2022-03-08 11:16:35 -08:00
parent 98e5315c0d
commit fa6ee6ce91

View File

@@ -195,9 +195,41 @@ export class CodeApplication extends Disposable {
return false;
};
const isAllowedWebviewRequest = (details: Electron.OnBeforeRequestListenerDetails): boolean => {
const url = URI.parse(details.url);
// Only restrict top level page of webviews: index.html
if (url.path !== '/index.html') {
return true;
}
const frame = details.frame;
if (!frame || !this.windowsMainService) {
return false;
}
// Check to see if the request comes from one of the main editor windows.
for (const window of this.windowsMainService.getWindows()) {
if (window.win) {
if (frame.processId === window.win.webContents.mainFrame.processId) {
return true;
}
}
}
return false;
};
session.defaultSession.webRequest.onBeforeRequest((details, callback) => {
const uri = URI.parse(details.url);
if (uri.scheme === Schemas.vscodeWebview) {
if (!isAllowedWebviewRequest(details)) {
this.logService.error('Blocked vscode-webview request', details.url);
return callback({ cancel: true });
}
}
if (uri.scheme === Schemas.vscodeFileResource) {
if (!isAllowedVsCodeFileRequest(details)) {
this.logService.error('Blocked vscode-file request', details.url);