fix(query): avoid spawning git for memory provenance - #168
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR hardens session-memory provenance collection in claurst-query by removing PATH-resolved git process execution and replacing it with filesystem-based .git metadata reads, reducing code-execution risk in attacker-controlled workspaces.
Changes:
- Replaced
Command::new("git")provenance collection withfind_git_dir,read_origin_remote_url, andread_head_commit. - Updated
build_session_memory_provenanceto populatesource_repo/source_commitfrom.gitfiles when available. - Added unit tests for basic
.gitdirectory layouts andgitdir:indirection.
Comments suppressed due to low confidence (2)
src-rust/crates/query/src/lib.rs:165
read_head_commitassumes the ref target exists as a loose ref under<git_dir>/refs/...and only accepts 40-hex SHA-1. In common setups refs are packed (packed-refs) and/or worktrees store refs in thecommondir, so provenance will often misssource_commiteven though it’s available.
fn read_head_commit(git_dir: &Path) -> Option<String> {
let head = fs::read_to_string(git_dir.join("HEAD")).ok()?;
let head = head.trim();
let commit = if let Some(reference) = head.strip_prefix("ref:") {
fs::read_to_string(git_dir.join(reference.trim())).ok()?
} else {
head.to_string()
};
let commit = commit.trim();
if commit.len() == 40 && commit.chars().all(|ch| ch.is_ascii_hexdigit()) {
Some(commit.to_string())
} else {
None
}
}
src-rust/crates/query/src/lib.rs:2812
- Creating a
workspace/gitfile doesn’t affect PATH resolution and doesn’t help validate the test’s intent; it’s currently dead/ misleading setup.
std::fs::write(workspace.join("git"), "not executed").unwrap();
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Val Alexander <68980965+BunsDev@users.noreply.github.com>
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
gitbinary from the background session-memory task to eliminate PATH-based code-execution risk when processing attacker-controlled workspaces.Description
Command::new("git")usage from session-memory provenance collection and stop spawning executables from the workspace context.find_git_dir,read_origin_remote_url, andread_head_committo locate.git(includinggitdir:files), readremote "origin"fromconfig, and read/validateHEADwithout invoking an externalgitprocess.build_session_memory_provenanceto use these helpers and preserve population ofsource_repo,source_commit, andsource_actorwhen available.builds_session_memory_provenance_without_executing_git_from_pathandreads_git_metadata_from_gitdir_fileto cover regular.gitlayouts andgitdir:indirection.Testing
git diff --checkwhich passed on the modified file.cargo fmt --allwhich completed successfully.cargo test --package claurst-query <test>and offline runs, but fullcargo test/cargo check/cargo clippycould not be completed in this environment due to a dependency fetch failure forhttps://github.com/OpenCoven/coven-runtimes(proxy/404/revision lookup), so workspace-wide Rust verification is blocked; the added unit tests are present and intended to pass when dependencies are available.fix(query): avoid spawning git for memory provenance.Codex Task