From 82f032912456501df6c045642ff0a2635d39fe39 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 19 Jun 2024 10:11:15 -0700 Subject: [PATCH] warn user if potentially dangerous command is generated --- core/commands/slash/cmd.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/commands/slash/cmd.ts b/core/commands/slash/cmd.ts index 797bd9826..c171384bd 100644 --- a/core/commands/slash/cmd.ts +++ b/core/commands/slash/cmd.ts @@ -2,6 +2,14 @@ import { streamLines } from "../../diff/util.js"; import { SlashCommand } from "../../index.js"; import { removeQuotesAndEscapes } from "../../util/index.js"; +function commandIsPotentiallyDangerous(command: string) { + return ( + command.includes("rm -rf") || + command.includes("sudo") || + command.includes("cd / ") + ); +} + const GenerateTerminalCommand: SlashCommand = { name: "cmd", description: "Generate a shell command", @@ -35,8 +43,12 @@ Please write a shell command that will do what the user requested. Your output s break; } - await ide.runCommand(cmd); yield `Generated shell command: ${cmd}`; + if (commandIsPotentiallyDangerous(cmd)) { + yield "\n\nWarning: This command may be potentially dangerous. Please double-check before pasting it in your terminal."; + } else { + await ide.runCommand(cmd); + } }, };