fix(commands): avoid untrusted coven path lookup#92
Open
BunsDev wants to merge 1 commit into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Hardens /coven shell-outs by resolving coven to a trusted absolute executable path (instead of relying on PATH search order), reducing risk of PATH hijacking.
Changes:
- Added helpers to resolve a trusted
covenbinary from a safe PATH entry (and prefer co-located binary). - Updated
coven_shell_outto spawn the resolved absolute binary path. - Added unit tests and a small helper for creating fake
covenbinaries.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+10180
to
+10190
| fn coven_path_entry_is_trusted(dir: &Path, cwd: Option<&Path>) -> bool { | ||
| if !dir.is_absolute() { | ||
| return false; | ||
| } | ||
| if let Some(cwd) = cwd { | ||
| if let (Ok(canonical_dir), Ok(canonical_cwd)) = (dir.canonicalize(), cwd.canonicalize()) { | ||
| return canonical_dir != canonical_cwd; | ||
| } | ||
| } | ||
| true | ||
| } |
Comment on lines
+10170
to
+10178
| fn coven_binary_in_dir(dir: &Path) -> Option<PathBuf> { | ||
| for name in coven_executable_names() { | ||
| let candidate = dir.join(name); | ||
| if candidate.is_file() { | ||
| return Some(candidate); | ||
| } | ||
| } | ||
| None | ||
| } |
Comment on lines
+11807
to
+11826
| #[test] | ||
| fn coven_binary_from_path_ignores_current_dir_and_relative_entries() { | ||
| let tmp = tempfile::tempdir().unwrap(); | ||
| let project = tmp.path().join("project"); | ||
| let relative = tmp.path().join("relative-bin"); | ||
| let trusted = tmp.path().join("trusted-bin"); | ||
| let trusted_coven = write_fake_coven(&trusted); | ||
| write_fake_coven(&project); | ||
| write_fake_coven(&relative); | ||
|
|
||
| let path = std::env::join_paths([ | ||
| project.as_path(), | ||
| Path::new("relative-bin"), | ||
| trusted.as_path(), | ||
| ]) | ||
| .unwrap(); | ||
|
|
||
| let resolved = coven_binary_from_path(Some(path.as_os_str()), Some(&project)); | ||
| assert_eq!(resolved.as_deref(), Some(trusted_coven.as_path())); | ||
| } |
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
covenbinaries discovered via untrusted PATH entries (repository-local or relative directories) when users run/covensubcommands./covenUX while forcing resolution to a trusted absolutecovenexecutable to eliminate PATH search-order hijacking risk.Description
coven_executable_names,coven_binary_in_dir,coven_path_entry_is_trusted,coven_binary_from_path, andcoven_binary_pathto locate a concretecovenbinary in absolute, non-project PATH entries.coven_shell_outto callcoven_binary_path()and spawn the resolved absolute path instead ofCommand::new("coven").coven, and prefer acovencolocated with the runningcoven-codebinary if present.coven_binary_from_path_ignores_current_dir_and_relative_entriesandcoven_binary_from_path_rejects_untrusted_entries_without_fallback, plus a small test helperwrite_fake_covenand a minor import cleanup (use std::path::{Path, PathBuf};).Testing
cargo test --package claurst-commands coven_binary_from_path -- --nocapture, and both tests passed.cargo check --package claurst-commands, which completed successfully for the package.cargo check --workspace, which was blocked by a missing system dependency (alsa.pc) required byalsa-sysand therefore could not complete in this environment.cargo clippyis blocked (and there are unrelated clippy findings incrates/tui/src/image_paste.rs) so full workspace linting was not completed here.Codex Task