Skip to content

Commit 8d0a095

Browse files
feat(terminal): restrict default allowed commands to 'ls' and 'echo'
Change the default value of `terminal.allowCommands` from an empty array to `['ls', 'echo']`. This update enhances security and focus by limiting the commands available in tutorials by default. Lesson authors can still enable all commands by setting `terminal.allowCommands: []` explicitly in the metadata. BREAKING CHANGE: The default value of `terminal.allowCommands` is now restricted to `['ls', 'echo']`. To allow all commands, explicitly set `terminal.allowCommands: []` in the metadata. Closes #372
1 parent 69ec710 commit 8d0a095

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

packages/runtime/src/webcontainer/terminal-config.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe('TerminalConfig', () => {
150150
expect(config.panels[1].title).toBe('TERM 2');
151151
expect(config.panels[1].processOptions).toEqual({
152152
allowRedirects: true,
153-
allowCommands: ['ls', 'echo'],
153+
allowCommands: ['echo'],
154154
});
155155

156156
expect(config.panels[2].title).toBe('OUT');
@@ -171,7 +171,7 @@ describe('TerminalConfig', () => {
171171
expect(config.panels[0].title).toBe('TERM 1');
172172
expect(config.panels[0].processOptions).toEqual({
173173
allowRedirects: false,
174-
allowCommands: ['ls', 'echo'],
174+
allowCommands: ['echo'],
175175
});
176176

177177
expect(config.panels[1].title).toBe('TERM 2');

packages/runtime/src/webcontainer/terminal-config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,21 @@ function normalizeTerminalConfig(config?: TerminalSchema): NormalizedTerminalCon
235235

236236
const panels: TerminalPanel[] = [];
237237

238-
const resolveAllowCommands = (allowCommands?: string[]): string[] | undefined => {
239-
if (allowCommands === undefined) {
240-
return DEFAULT_COMMANDS;
238+
const resolveAllowCommands = (globalCommands?: string[], panelCommands?: string[]): string[] | undefined => {
239+
if (panelCommands === undefined) {
240+
return globalCommands ?? DEFAULT_COMMANDS;
241241
}
242242

243-
if (Array.isArray(allowCommands) && allowCommands.length === 0) {
243+
if (Array.isArray(panelCommands) && panelCommands.length === 0) {
244244
return undefined;
245245
}
246246

247-
return allowCommands;
247+
return panelCommands;
248248
};
249249

250250
const options = {
251251
allowRedirects: config.allowRedirects,
252-
allowCommands: resolveAllowCommands(config.allowCommands),
252+
allowCommands: config.allowCommands,
253253
};
254254

255255
if (config.panels) {
@@ -273,7 +273,7 @@ function normalizeTerminalConfig(config?: TerminalSchema): NormalizedTerminalCon
273273
id: panel.id,
274274
title: panel.title,
275275
allowRedirects: panel.allowRedirects ?? config.allowRedirects,
276-
allowCommands: panel.allowCommands ? resolveAllowCommands(panel.allowCommands) : options.allowCommands,
276+
allowCommands: resolveAllowCommands(config.allowCommands, panel.allowCommands),
277277
});
278278
}
279279

0 commit comments

Comments
 (0)