Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -42,7 +42,7 @@ import { ExtensionHostKind, ExtensionRunningPreference, IExtensionHostKindPicker
import { ExtensionHostManager } from './extensionHostManager.js';
import { IExtensionHostManager } from './extensionHostManagers.js';
import { IResolveAuthorityErrorResult } from './extensionHostProxy.js';
import { IExtensionManifestPropertiesService } from './extensionManifestPropertiesService.js';
import { IExtensionManifestPropertiesService, toSessionsWindowSafeExtension } from './extensionManifestPropertiesService.js';
import { ExtensionRunningLocation, LocalProcessRunningLocation, LocalWebWorkerRunningLocation, RemoteRunningLocation } from './extensionRunningLocation.js';
import { ExtensionRunningLocationTracker, filterExtensionIdentifiers } from './extensionRunningLocationTracker.js';
import { ActivationKind, ActivationTimes, ExtensionActivationReason, ExtensionHostStartup, ExtensionPointContribution, IExtensionHost, IExtensionInspectInfo, IExtensionService, IExtensionsStatus, IInternalExtensionService, IMessage, IProposedApiUsage, IResponsiveStateChangeEvent, IWillActivateEvent, setProposedApiUsageReporter, WillStopExtensionHostsEvent, toExtension, toExtensionDescription } from './extensions.js';
Expand Down Expand Up @@ -300,7 +300,7 @@ export abstract class AbstractExtensionService extends Disposable implements IEx
for (let i = 0, len = _toAdd.length; i < len; i++) {
const extension = _toAdd[i];

const extensionDescription = toExtensionDescription(extension, false);
const extensionDescription = this._getExtensionDescriptionForCurrentWindow(toExtensionDescription(extension, false));
if (!extensionDescription) {
// could not scan extension...
continue;
Expand Down Expand Up @@ -523,15 +523,15 @@ export abstract class AbstractExtensionService extends Disposable implements IEx

for await (const extensions of this._resolveExtensions()) {
if (extensions instanceof ResolverExtensions) {
resolverExtensions = checkEnabledAndProposedAPI(this._logService, this._extensionEnablementService, this._extensionsProposedApi, extensions.extensions, false);
resolverExtensions = checkEnabledAndProposedAPI(this._logService, this._extensionEnablementService, this._extensionsProposedApi, extensions.extensions.map(extension => this._getExtensionDescriptionForCurrentWindow(extension)), false);
this._registry.deltaExtensions(lock, resolverExtensions, []);
this._doHandleExtensionPoints(resolverExtensions, true);
}
if (extensions instanceof LocalExtensions) {
localExtensions = checkEnabledAndProposedAPI(this._logService, this._extensionEnablementService, this._extensionsProposedApi, extensions.extensions, false);
localExtensions = checkEnabledAndProposedAPI(this._logService, this._extensionEnablementService, this._extensionsProposedApi, extensions.extensions.map(extension => this._getExtensionDescriptionForCurrentWindow(extension)), false);
}
if (extensions instanceof RemoteExtensions) {
remoteExtensions = checkEnabledAndProposedAPI(this._logService, this._extensionEnablementService, this._extensionsProposedApi, extensions.extensions, false);
remoteExtensions = checkEnabledAndProposedAPI(this._logService, this._extensionEnablementService, this._extensionsProposedApi, extensions.extensions.map(extension => this._getExtensionDescriptionForCurrentWindow(extension)), false);
}
}

Expand Down Expand Up @@ -1143,12 +1143,22 @@ export abstract class AbstractExtensionService extends Disposable implements IEx

private _safeInvokeIsEnabled(extension: IExtension): boolean {
try {
return this._extensionEnablementService.isEnabled(extension);
const extensionDescription = this._getExtensionDescriptionForCurrentWindow(toExtensionDescription(extension, false));
return this._extensionEnablementService.isEnabled(toExtension(extensionDescription));
} catch (err) {
return false;
}
}

private _getExtensionDescriptionForCurrentWindow(extension: IExtensionDescription): IExtensionDescription {
if (!this._environmentService.isSessionsWindow || this._extensionManifestPropertiesService.canExecuteOnSessionsWindow(extension)) {
return extension;
}

const safeExtension = toSessionsWindowSafeExtension(extension);
Comment on lines +1154 to +1158
return safeExtension ? { ...extension, ...safeExtension } : extension;
}

private _doHandleExtensionPoints(affectedExtensions: IExtensionDescription[], onlyResolverExtensionPoints: boolean): void {
const affectedExtensionPoints: { [extPointName: string]: boolean } = Object.create(null);
for (const extensionDescription of affectedExtensions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ const SESSIONS_WINDOW_ALLOWED_CONTRIBUTION_POINTS: ReadonlySet<keyof IExtensionC
'languages',
]);

/**
* Creates a non-executable extension manifest containing only contribution points supported by the Sessions window.
*/
export function toSessionsWindowSafeExtension(extension: IExtensionManifest): IExtensionManifest | undefined {
const contributes: IExtensionContributions = { ...extension.contributes };
for (const contributionPoint of Object.keys(contributes) as Array<keyof IExtensionContributions>) {
if (!SESSIONS_WINDOW_ALLOWED_CONTRIBUTION_POINTS.has(contributionPoint)) {
delete contributes[contributionPoint];
}
}

if (Object.keys(contributes).length === 0) {
return undefined;
}

return {
...extension,
main: undefined,
browser: undefined,
activationEvents: undefined,
extensionDependencies: undefined,
extensionAffinity: undefined,
contributes,
};
}

export interface IExtensionManifestPropertiesService {
readonly _serviceBrand: undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TestInstantiationService } from '../../../../../platform/instantiation/
import { NullLogService } from '../../../../../platform/log/common/log.js';
import { IProductService } from '../../../../../platform/product/common/productService.js';
import { IWorkspaceTrustEnablementService } from '../../../../../platform/workspace/common/workspaceTrust.js';
import { EXTENSIONS_SUPPORT_AGENTS_WINDOW, ExtensionManifestPropertiesService } from '../../common/extensionManifestPropertiesService.js';
import { EXTENSIONS_SUPPORT_AGENTS_WINDOW, ExtensionManifestPropertiesService, toSessionsWindowSafeExtension } from '../../common/extensionManifestPropertiesService.js';
import { TestProductService, TestWorkspaceTrustEnablementService } from '../../../../test/common/workbenchTestServices.js';

suite('ExtensionManifestPropertiesService - ExtensionKind', () => {
Expand Down Expand Up @@ -145,6 +145,45 @@ suite('ExtensionManifestPropertiesService - SessionsWindowSupport', () => {
], [true, false, false]);
});

test('restricts executable extensions to supported declarative contributions', () => {
testObject = createTestObject();
const extension = getExtensionManifest({
main: './out/extension.js',
browser: './out/extension.web.js',
activationEvents: ['onStartupFinished'],
extensionDependencies: ['pub.dependency'],
extensionAffinity: ['pub.dependency'],
contributes: {
iconThemes: [{ label: 'Custom Icons' }],
commands: [{ command: 'pub.configureIcons', title: 'Configure Icons' }],
}
});

const restrictedExtension = toSessionsWindowSafeExtension(extension);

assert.deepStrictEqual({
main: restrictedExtension?.main,
browser: restrictedExtension?.browser,
activationEvents: restrictedExtension?.activationEvents,
extensionDependencies: restrictedExtension?.extensionDependencies,
extensionAffinity: restrictedExtension?.extensionAffinity,
contributes: restrictedExtension?.contributes,
canExecuteOriginal: testObject.canExecuteOnSessionsWindow(extension),
canExecuteRestricted: restrictedExtension ? testObject.canExecuteOnSessionsWindow(restrictedExtension) : false,
}, {
main: undefined,
browser: undefined,
activationEvents: undefined,
extensionDependencies: undefined,
extensionAffinity: undefined,
contributes: {
iconThemes: [{ label: 'Custom Icons' }],
},
canExecuteOriginal: false,
canExecuteRestricted: true,
});
});

test('uses configured sessions window support override', async () => {
await testConfigurationService.setUserConfiguration(EXTENSIONS_SUPPORT_AGENTS_WINDOW, { 'pub.a': true, 'pub.b': false });
testObject = createTestObject();
Expand Down