Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions packages/terminal-security/test/terminalCommandSecurity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading