Skip to content

Conversation

@hdcodedev
Copy link

What

Implemented detection for dangerous "force delete" commands on Windows to trigger the user approval prompt when --ask-for-approval on-request is set. This aligns Windows behavior with the existing safety checks for rm -rf on Linux.

Why

Fixes #8567 - a critical safety gap where destructive Windows commands could bypass the approval prompt. This prevents accidental data loss by ensuring the user explicitly confirms operations that would otherwise suppress the OS's native confirmation prompts.

How

Updated the Windows command safety module to identify and flag the following patterns as dangerous:

  • PowerShell: Remove-Item (and aliases) when used with the -Force flag.
  • CMD: del /f (force delete files).
  • CMD: rd /s /q (recursive delete quiet).
    • Note: rd /s (without /q) is NOT flagged because it already natively prompts the user.

Testing

Added comprehensive unit tests covering:

  • Remove-Item -Path 'test' -Recurse -Force (Exact reproduction case).
  • del /f (Flagged).
  • rd /s /q (Flagged).
  • rd /s (Not flagged - confirms no false positives).
  • Standard deletions without force flags.
  • Verified with cargo test and cargo clippy.

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 175 to 177
let has_force = tokens
.iter()
.any(|t| t == "-force" || t.starts_with("-force:"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle PowerShell -Force with trailing separators

This check only matches tokens exactly equal to -force or starting with -force:, but PowerShell command sequences commonly use semicolons to separate statements (e.g., Remove-Item test -Force; Write-Host done). With the current shlex tokenization, the -Force; token retains the semicolon, so has_force stays false and the dangerous delete is not flagged. That leaves a bypass for the approval prompt in a common usage pattern; consider trimming trailing ; (and similar separators) on tokens before the -force check or normalizing punctuation the same way URL detection does.

Useful? React with 👍 / 👎.

Copy link
Author

@hdcodedev hdcodedev Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the logic to trim common trailing punctuation (;, ), }, ]) from the tokens before checking for the -Force flag. This should handle cases like remove-Item test -force; or usages inside ([{ correctly.

I opted for trim_end_matches here for performance/simplicity since we strictly care about the flag suffix, though we can switch to a fuller Regex approach (like the URL detector uses) if we hit more complex edge cases.

@hdcodedev hdcodedev changed the title fix: require approval for force delete on Windows fix(core): require approval for force delete on Windows Dec 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: Force delete without confirmation

1 participant