diff --git a/packages/terminal-security/src/evaluateTerminalCommandSecurity.ts b/packages/terminal-security/src/evaluateTerminalCommandSecurity.ts index 693eef25f9c..060c1d75a5a 100644 --- a/packages/terminal-security/src/evaluateTerminalCommandSecurity.ts +++ b/packages/terminal-security/src/evaluateTerminalCommandSecurity.ts @@ -465,9 +465,12 @@ function isCriticalCommand(baseCommand: string, args: string[]): boolean { // Windows destructive commands if (baseCommand === "del") { - const hasRecursive = args.includes("/s") && args.includes("/q"); - const hasSystemDrive = args.some( - (arg) => arg.toLowerCase().includes("c:\\") || arg.includes("c:/"), + // Windows switches and drive letters are case-insensitive, so `/S /Q C:\` + // has to be treated exactly like `/s /q c:\` + const lowerArgs = args.map((arg) => arg.toLowerCase()); + const hasRecursive = lowerArgs.includes("/s") && lowerArgs.includes("/q"); + const hasSystemDrive = lowerArgs.some( + (arg) => arg.includes("c:\\") || arg.includes("c:/"), ); if (hasRecursive || hasSystemDrive) { return true; diff --git a/packages/terminal-security/test/terminalCommandSecurity.test.ts b/packages/terminal-security/test/terminalCommandSecurity.test.ts index 7d2e484765e..22663dea9ae 100644 --- a/packages/terminal-security/test/terminalCommandSecurity.test.ts +++ b/packages/terminal-security/test/terminalCommandSecurity.test.ts @@ -60,6 +60,22 @@ describe("evaluateTerminalCommandSecurity", () => { expect(result).toBe("disabled"); }); + it("should disable Windows del with uppercase recursive flags", () => { + const result = evaluateTerminalCommandSecurity( + "allowedWithoutPermission", + "DEL /S /Q C:\\", + ); + expect(result).toBe("disabled"); + }); + + it("should disable Windows del on the system drive regardless of case", () => { + const result = evaluateTerminalCommandSecurity( + "allowedWithoutPermission", + "del /Q C:/Windows", + ); + expect(result).toBe("disabled"); + }); + it("should disable dd commands that could overwrite disk", () => { const result = evaluateTerminalCommandSecurity( "allowedWithoutPermission",