-
Notifications
You must be signed in to change notification settings - Fork 5.5k
implement command safety for PowerShell commands #4269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement command safety for PowerShell commands #4269
Conversation
There was a problem hiding this 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
09b94df
to
fb4e871
Compare
@@ -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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"]
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:is_safe_command_windows()
to only allow explicitly read-only PowerShell calls.-Command
scripts and pipelines).-File
,-EncodedCommand
,-ExecutionPolicy
, unknown flags, call operators, redirections, separators).Get-ChildItem
,Get-Content
,Select-Object
, etc.), safe Git subcommands (status
,log
,show
,diff
,cat-file
), and ripgrep without unsafe options.This ensures Codex on Windows can safely execute discover-only PowerShell workflows without risking destructive operations.