fix(core): avoid spawning cmd for Windows prompt env#34
Open
BunsDev wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens system-prompt environment info generation on Windows by removing a cmd /c ver process spawn during prompt assembly, reducing exposure to search-path hijacking from an untrusted working directory.
Changes:
- Replaces the Windows OS-version detection logic in
build_env_info_sectionwith environment-variable reads (OS,PROCESSOR_ARCHITECTURE) instead of spawningcmd /c ver. - Keeps non-Windows behavior unchanged (still runs
uname -s -rfor the OS version string).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+355
to
+359
| // Avoid spawning command processors while constructing the prompt: | ||
| // the current working directory may be an untrusted repository. | ||
| let os_name = std::env::var("OS") | ||
| .ok() | ||
| .map(|s| s.trim().to_string()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Command::new("cmd").args(["/c","ver"])from system-prompt assembly which ran during normal request preparation.Description
build_env_info_section(src-rust/crates/core/src/system_prompt.rs) to readOSandPROCESSOR_ARCHITECTUREenvironment variables instead of spawningcmd /c ver.uname -s -rto obtain an OS version string.Testing
rg 'Command::new\("cmd"\)|cmd"\)\s*\.args\(\["/c", "ver"\]\)' src-rust/crates/core/src/system_prompt.rs src-rust/crates/query/src/lib.rswhich returned no matches.cargo check --workspacewhich failed due to the container missing system development packages (alsa.pcforalsa-sys) and thus the workspace could not be fully checked.timeout 180 cargo check --package claurst-core --libwhich timed out while compiling dependencies (external crates likeopenssl-sys), so full crate check could not complete within this environment.rustfmt --check crates/core/src/system_prompt.rsand observed it failed because of pre-existing formatting differences elsewhere in the file unrelated to the security change.Codex Task