-
Notifications
You must be signed in to change notification settings - Fork 0
🔒 security fix for PowerShell command injection #117
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| use base64::Engine; | ||
| use std::collections::{BTreeMap, BTreeSet}; | ||
| use std::path::{Path, PathBuf}; | ||
| use std::process::Command; | ||
|
|
@@ -5164,12 +5165,18 @@ fn execute_shell_command( | |
| timeout: Option<u64>, | ||
| run_in_background: Option<bool>, | ||
| ) -> std::io::Result<runtime::BashCommandOutput> { | ||
| let utf16_bytes: Vec<u8> = command | ||
| .encode_utf16() | ||
| .flat_map(|u| u.to_le_bytes()) | ||
| .collect(); | ||
| let encoded_command = base64::engine::general_purpose::STANDARD.encode(utf16_bytes); | ||
|
Comment on lines
+5168
to
+5172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Switching from Useful? React with 👍 / 👎.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @codex, make changes based on:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have reached your Codex usage limits. You can see your limits in the Codex usage dashboard. |
||
|
|
||
| if run_in_background.unwrap_or(false) { | ||
| let child = std::process::Command::new(shell) | ||
| .arg("-NoProfile") | ||
| .arg("-NonInteractive") | ||
| .arg("-Command") | ||
| .arg(command) | ||
| .arg("-EncodedCommand") | ||
| .arg(encoded_command) | ||
|
Comment on lines
+5178
to
+5179
|
||
| .stdin(std::process::Stdio::null()) | ||
| .stdout(std::process::Stdio::null()) | ||
| .stderr(std::process::Stdio::null()) | ||
|
|
@@ -5197,8 +5204,8 @@ fn execute_shell_command( | |
| process | ||
| .arg("-NoProfile") | ||
| .arg("-NonInteractive") | ||
| .arg("-Command") | ||
| .arg(command); | ||
| .arg("-EncodedCommand") | ||
| .arg(encoded_command); | ||
|
Comment on lines
+5207
to
+5208
Comment on lines
+5207
to
+5208
|
||
| process | ||
| .stdout(std::process::Stdio::piped()) | ||
| .stderr(std::process::Stdio::piped()); | ||
|
|
@@ -6495,7 +6502,9 @@ mod tests { | |
|
|
||
| #[test] | ||
| fn skill_loads_local_skill_prompt() { | ||
| let _guard = env_lock().lock().expect("env lock should acquire"); | ||
| let _guard = env_lock() | ||
| .lock() | ||
| .unwrap_or_else(std::sync::PoisonError::into_inner); | ||
| let home = temp_path("skills-home"); | ||
| let skill_dir = home.join(".agents").join("skills").join("help"); | ||
| fs::create_dir_all(&skill_dir).expect("skill dir should exist"); | ||
|
|
@@ -6552,7 +6561,9 @@ mod tests { | |
|
|
||
| #[test] | ||
| fn skill_resolves_project_local_skills_and_legacy_commands() { | ||
| let _guard = env_lock().lock().expect("env lock should acquire"); | ||
| let _guard = env_lock() | ||
| .lock() | ||
| .unwrap_or_else(std::sync::PoisonError::into_inner); | ||
| let root = temp_path("project-skills"); | ||
| let skill_dir = root.join(".claw").join("skills").join("plan"); | ||
| let command_dir = root.join(".claw").join("commands"); | ||
|
|
@@ -6596,7 +6607,9 @@ mod tests { | |
|
|
||
| #[test] | ||
| fn skill_loads_project_local_claude_skill_prompt() { | ||
| let _guard = env_lock().lock().expect("env lock should acquire"); | ||
| let _guard = env_lock() | ||
| .lock() | ||
| .unwrap_or_else(std::sync::PoisonError::into_inner); | ||
| let root = temp_path("project-skills"); | ||
| let home = root.join("home"); | ||
| let workspace = root.join("workspace"); | ||
|
|
@@ -6647,7 +6660,9 @@ mod tests { | |
|
|
||
| #[test] | ||
| fn skill_loads_project_local_omc_and_agents_skill_prompts() { | ||
| let _guard = env_lock().lock().expect("env lock should acquire"); | ||
| let _guard = env_lock() | ||
| .lock() | ||
| .unwrap_or_else(std::sync::PoisonError::into_inner); | ||
| let root = temp_path("project-omc-skills"); | ||
| let home = root.join("home"); | ||
| let workspace = root.join("workspace"); | ||
|
|
@@ -6717,7 +6732,9 @@ mod tests { | |
|
|
||
| #[test] | ||
| fn skill_loads_learned_skill_from_claude_config_dir() { | ||
| let _guard = env_lock().lock().expect("env lock should acquire"); | ||
| let _guard = env_lock() | ||
| .lock() | ||
| .unwrap_or_else(std::sync::PoisonError::into_inner); | ||
| let root = temp_path("claude-config-learned-skill"); | ||
| let home = root.join("home"); | ||
| let claude_config_dir = root.join("claude-config"); | ||
|
|
@@ -6772,7 +6789,9 @@ mod tests { | |
|
|
||
| #[test] | ||
| fn skill_loads_direct_skill_and_legacy_command_from_claude_config_dir() { | ||
| let _guard = env_lock().lock().expect("env lock should acquire"); | ||
| let _guard = env_lock() | ||
| .lock() | ||
| .unwrap_or_else(std::sync::PoisonError::into_inner); | ||
| let root = temp_path("claude-config-direct-skill"); | ||
| let home = root.join("home"); | ||
| let claude_config_dir = root.join("claude-config"); | ||
|
|
@@ -6844,7 +6863,9 @@ mod tests { | |
|
|
||
| #[test] | ||
| fn skill_loads_project_local_legacy_command_markdown() { | ||
| let _guard = env_lock().lock().expect("env lock should acquire"); | ||
| let _guard = env_lock() | ||
| .lock() | ||
| .unwrap_or_else(std::sync::PoisonError::into_inner); | ||
| let root = temp_path("project-legacy-command"); | ||
| let home = root.join("home"); | ||
| let workspace = root.join("workspace"); | ||
|
|
@@ -8152,7 +8173,7 @@ mod tests { | |
| std::fs::write( | ||
| &script, | ||
| r#"#!/bin/sh | ||
| while [ "$1" != "-Command" ] && [ $# -gt 0 ]; do shift; done | ||
| while [ "$1" != "-EncodedCommand" ] && [ $# -gt 0 ]; do shift; done | ||
| shift | ||
| printf 'pwsh:%s' "$1" | ||
| "#, | ||
|
|
@@ -8182,7 +8203,10 @@ printf 'pwsh:%s' "$1" | |
| let _ = std::fs::remove_dir_all(dir); | ||
|
|
||
| let output: serde_json::Value = serde_json::from_str(&result).expect("json"); | ||
| assert_eq!(output["stdout"], "pwsh:Write-Output hello"); | ||
| assert_eq!( | ||
| output["stdout"], | ||
| "pwsh:VwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIABoAGUAbABsAG8A" | ||
| ); | ||
|
Comment on lines
+8206
to
+8209
|
||
| assert!(output["stderr"].as_str().expect("stderr").is_empty()); | ||
|
|
||
| let background_output: serde_json::Value = serde_json::from_str(&background).expect("json"); | ||
|
|
||
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.
The
encoded_commandis used in two different code paths (background and foreground execution). Sincebase64::Engine::encodereturns aString, passing it by value to.arg()in the background path (line 5179) would move it, making it unavailable for the foreground path (line 5208). Although the background path returns early, it is safer and more idiomatic to pass a reference to.arg()to avoid potential ownership issues if the code is refactored in the future.