mirror of
https://github.com/coder/code-server.git
synced 2026-05-07 21:07:26 +02:00
chore(vscode): update to 1.54.2
This commit is contained in:
@@ -31,33 +31,30 @@ export class FileProtocolHandler extends Disposable {
|
||||
// Define an initial set of roots we allow loading from
|
||||
// - appRoot : all files installed as part of the app
|
||||
// - extensions : all files shipped from extensions
|
||||
// - storage : all files in global and workspace storage (https://github.com/microsoft/vscode/issues/116735)
|
||||
this.validRoots.set(URI.file(environmentService.appRoot), true);
|
||||
this.validRoots.set(URI.file(environmentService.extensionsPath), true);
|
||||
this.validRoots.set(environmentService.globalStorageHome, true);
|
||||
this.validRoots.set(environmentService.workspaceStorageHome, true);
|
||||
|
||||
// Register vscode-file:// handler
|
||||
defaultSession.protocol.registerFileProtocol(Schemas.vscodeFileResource, (request, callback) => this.handleResourceRequest(request, callback as unknown as ProtocolCallback));
|
||||
|
||||
// Block any file:// access (explicitly enabled only)
|
||||
if (isPreferringBrowserCodeLoad) {
|
||||
this.logService.info(`Intercepting ${Schemas.file}: protocol and blocking it`);
|
||||
|
||||
defaultSession.protocol.interceptFileProtocol(Schemas.file, (request, callback) => this.handleFileRequest(request, callback as unknown as ProtocolCallback));
|
||||
}
|
||||
// Intercept any file:// access
|
||||
defaultSession.protocol.interceptFileProtocol(Schemas.file, (request, callback) => this.handleFileRequest(request, callback as unknown as ProtocolCallback));
|
||||
|
||||
// Cleanup
|
||||
this._register(toDisposable(() => {
|
||||
defaultSession.protocol.unregisterProtocol(Schemas.vscodeFileResource);
|
||||
if (isPreferringBrowserCodeLoad) {
|
||||
defaultSession.protocol.uninterceptProtocol(Schemas.file);
|
||||
}
|
||||
defaultSession.protocol.uninterceptProtocol(Schemas.file);
|
||||
}));
|
||||
}
|
||||
|
||||
injectWindowsMainService(windowsMainService: IWindowsMainService): void {
|
||||
this._register(windowsMainService.onWindowReady(window => {
|
||||
this._register(windowsMainService.onDidSignalReadyWindow(window => {
|
||||
if (window.config?.extensionDevelopmentPath || window.config?.extensionTestsPath) {
|
||||
const disposables = new DisposableStore();
|
||||
disposables.add(Event.any(window.onClose, window.onDestroy)(() => disposables.dispose()));
|
||||
disposables.add(Event.any(window.onDidClose, window.onDidDestroy)(() => disposables.dispose()));
|
||||
|
||||
// Allow access to extension development path
|
||||
if (window.config.extensionDevelopmentPath) {
|
||||
@@ -85,10 +82,29 @@ export class FileProtocolHandler extends Disposable {
|
||||
}
|
||||
|
||||
private async handleFileRequest(request: Electron.ProtocolRequest, callback: ProtocolCallback) {
|
||||
const uri = URI.parse(request.url);
|
||||
const fileUri = URI.parse(request.url);
|
||||
|
||||
this.logService.error(`Refused to load resource ${uri.fsPath} from ${Schemas.file}: protocol`);
|
||||
callback({ error: -3 /* ABORTED */ });
|
||||
// isPreferringBrowserCodeLoad: false
|
||||
// => ensure the file path is in our expected roots
|
||||
if (!isPreferringBrowserCodeLoad) {
|
||||
if (this.validRoots.findSubstr(fileUri)) {
|
||||
return callback({
|
||||
path: fileUri.fsPath
|
||||
});
|
||||
}
|
||||
|
||||
this.logService.error(`${Schemas.file}: Refused to load resource ${fileUri.fsPath} from ${Schemas.file}: protocol (original URL: ${request.url})`);
|
||||
|
||||
return callback({ error: -3 /* ABORTED */ });
|
||||
}
|
||||
|
||||
// isPreferringBrowserCodeLoad: true
|
||||
// => block any file request
|
||||
else {
|
||||
this.logService.error(`Refused to load resource ${fileUri.fsPath} from ${Schemas.file}: protocol (original URL: ${request.url})`);
|
||||
|
||||
return callback({ error: -3 /* ABORTED */ });
|
||||
}
|
||||
}
|
||||
|
||||
private async handleResourceRequest(request: Electron.ProtocolRequest, callback: ProtocolCallback) {
|
||||
@@ -102,9 +118,10 @@ export class FileProtocolHandler extends Disposable {
|
||||
return callback({
|
||||
path: fileUri.fsPath
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.logService.error(`${Schemas.vscodeFileResource}: Refused to load resource ${fileUri.fsPath} from ${Schemas.vscodeFileResource}: protocol (original URL: ${request.url})`);
|
||||
|
||||
this.logService.error(`${Schemas.vscodeFileResource}: Refused to load resource ${fileUri.fsPath}}`);
|
||||
callback({ error: -3 /* ABORTED */ });
|
||||
return callback({ error: -3 /* ABORTED */ });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user