src/vs/platform/sandbox/common/terminalSandboxRuntimeConfigurationPerOperation.ts

117 LOC · 91 covered · 26 uncovered · 19 ranges · 1052 concepts · 3 introducers · 489 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- terminalSandboxEngine.ts ×71
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { OperatingSystem } from '../../../base/common/platform.js';
7 > import type { ITerminalSandboxCommand } from './terminalSandboxService.js';
8 > import { type ITerminalSandboxCommandRule, matchesTerminalSandboxCommandRule } from './terminalSandboxCommandRules.js';
9 >
10 > export const enum TerminalSandboxRuntimeConfigurationOperation {
11 > GnuPG = 'gnupg',
12 > Node = 'node',
13 > }
14 >
15 > const terminalSandboxRuntimeConfigurationCommandRules: readonly ITerminalSandboxCommandRule<TerminalSandboxRuntimeConfigurationOperation>[] = [
16 > {
17 > keywords: ['node', 'npm', 'npx', 'pnpm', 'yarn', 'corepack', 'bun', 'deno', 'nvm', 'volta', 'fnm', 'asdf', 'mise'],
18 > value: TerminalSandboxRuntimeConfigurationOperation.Node,
19 > },
20 > {
21 > keywords: ['git'],
22 > value: TerminalSandboxRuntimeConfigurationOperation.GnuPG,
23 > condition: ({ os }) => os !== OperatingSystem.Windows,
24 > },
25 > ];
26 >
27 > function getTerminalSandboxRuntimeConfigurationForOperation(operation: TerminalSandboxRuntimeConfigurationOperation, os: OperatingSystem): Record<string, unknown> { terminalSandboxReadAllowList.ts ×15
28 > switch (operation) {
29 > case TerminalSandboxRuntimeConfigurationOperation.GnuPG:
30 > switch (os) {
31 > case OperatingSystem.Windows:
32 return {};
33 > case OperatingSystem.Macintosh: terminalSandboxReadAllowList.ts ×15
34 > case OperatingSystem.Linux:
35 > default:
36 > return {
37 > network: {
38 > allowAllUnixSockets: true
39 > },
40 > filesystem: {
41 > allowRead: [
42 > '~/.gnupg'
43 > ],
44 > allowWrite: [
45 > '~/.gnupg'
46 > ]
47 > }
48 > };
49 > }
50 >
51 > case TerminalSandboxRuntimeConfigurationOperation.Node:
52 switch (os) {
53 case OperatingSystem.Windows:
54 return {};
55 case OperatingSystem.Macintosh:
56 case OperatingSystem.Linux:
57 default:
58 return {
59 filesystem: {
60 allowWrite: [
61 '~/.volta/'
62 ]
63 }
64 };
65 }
67 > }
69 > export function getTerminalSandboxRuntimeConfigurationForCommands(os: OperatingSystem, commandDetails: readonly ITerminalSandboxCommand[]): Record<string, unknown> {
70 > const operations = new Set<TerminalSandboxRuntimeConfigurationOperation>(); terminalSandboxEngine.ts ×11
71 > for (const command of commandDetails) {
72 > for (const rule of terminalSandboxRuntimeConfigurationCommandRules) { terminalSandboxReadAllowList.ts ×15
73 > if (matchesTerminalSandboxCommandRule(command, rule, { os }) && shouldApplyRuntimeConfigurationOperation(rule.value, commandDetails)) {
74 > operations.add(rule.value);
75 > }
76 > }
77 > }
79 > const configuration: Record<string, unknown> = {};
80 > for (const operation of operations) {
81 > mergeAdditionalSandboxConfigProperties(configuration, getTerminalSandboxRuntimeConfigurationForOperation(operation, os)); terminalSandboxReadAllowList.ts ×15
82 > }
83 > return configuration; terminalSandboxEngine.ts ×11
84 > }
86 > function shouldApplyRuntimeConfigurationOperation(operation: TerminalSandboxRuntimeConfigurationOperation, commandDetails: readonly ITerminalSandboxCommand[]): boolean { terminalSandboxReadAllowList.ts ×15
87 > switch (operation) {
88 > case TerminalSandboxRuntimeConfigurationOperation.GnuPG:
89 > // Docker socket access can grant host-level privileges, so do not allow all Unix
90 > // sockets when a Docker-related command is part of the sandbox invocation.
91 > return commandDetails.every(command => !command.keyword.toLowerCase().startsWith('docker'));
92 > case TerminalSandboxRuntimeConfigurationOperation.Node:
93 return true;
95 > }
97 > function mergeAdditionalSandboxConfigProperties(target: Record<string, unknown>, additional: Record<string, unknown>): void { terminalSandboxReadAllowList.ts ×15
98 > for (const [key, value] of Object.entries(additional)) {
99 > if (!Object.prototype.hasOwnProperty.call(target, key)) {
100 > target[key] = value;
101 > continue;
102 > }
103
104 const existingValue = target[key];
105 > if (Array.isArray(existingValue) && Array.isArray(value)) { terminalSandboxReadAllowList.ts ×15
106 target[key] = [...new Set([...existingValue, ...value])];
107 continue;
108 }
109 > if (isObjectForSandboxConfigMerge(existingValue) && isObjectForSandboxConfigMerge(value)) { terminalSandboxReadAllowList.ts ×15
110 mergeAdditionalSandboxConfigProperties(existingValue, value);
111 }
113 > }
115 function isObjectForSandboxConfigMerge(value: unknown): value is Record<string, unknown> {
116 return typeof value === 'object' && value !== null && !Array.isArray(value);
117 }