Skip to content

Conversation

iceweasel-oai
Copy link
Contributor

@iceweasel-oai iceweasel-oai commented Sep 26, 2025

Implement command safety for PowerShell commands on Windows

This change adds a new Windows-specific command-safety module under codex-rs/core/src/command_safety/windows_safe_commands.rs to strictly sanitise PowerShell invocations. Key points:

  • Introduce is_safe_command_windows() to only allow explicitly read-only PowerShell calls.
  • Parse and split PowerShell invocations (including inline -Command scripts and pipelines).
  • Block unsafe switches (-File, -EncodedCommand, -ExecutionPolicy, unknown flags, call operators, redirections, separators).
  • Whitelist only read-only cmdlets (Get-ChildItem, Get-Content, Select-Object, etc.), safe Git subcommands (status, log, show, diff, cat-file), and ripgrep without unsafe options.
  • Add comprehensive unit tests covering allowed and rejected command patterns (nested calls, side effects, chaining, redirections).

This ensures Codex on Windows can safely execute discover-only PowerShell workflows without risking destructive operations.

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

@iceweasel-oai iceweasel-oai force-pushed the dev/iceweasel/actual-windows-safe-commands branch from 09b94df to fb4e871 Compare September 30, 2025 17:58
@@ -1,25 +1,431 @@
// This is a WIP. This will eventually contain a real list of common safe Windows commands.
pub fn is_safe_command_windows(_command: &[String]) -> bool {
use shlex::split as shlex_split;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was never really clear how well this applies to Windows, particularly PowerShell?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

by the time we call shlex_split on a powershell command, the "powershell" part of it has been stripped out and we just call this on the raw command (e.g. Get-Content core/src/safety.rs | Select-Object -First 220) which gets split into ["Get-Content", "code/src/safety.rs", "|", "Select-Object", "-First", "220"]

@iceweasel-oai iceweasel-oai merged commit dde615f into main Oct 1, 2025
20 checks passed
@iceweasel-oai iceweasel-oai deleted the dev/iceweasel/actual-windows-safe-commands branch October 1, 2025 16:56
@github-actions github-actions bot locked and limited conversation to collaborators Oct 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants