Skip to content

test(security): Pin that a remote clone's .git is always removed - #1798

Merged
yamadashy merged 1 commit into
mainfrom
security/pin-remote-clone-git-removal
Aug 11, 2026
Merged

test(security): Pin that a remote clone's .git is always removed#1798
yamadashy merged 1 commit into
mainfrom
security/pin-remote-clone-git-removal

Conversation

@yamadashy

Copy link
Copy Markdown
Owner

Summary

execGitShallowClone deletes the clone's .git before the pack runs. The comment called this "Clean up .git directory", which reads as tidiness, but the removal is load-bearing for safety: packing runs git -C <dir> log by default (output.git.sortByChanges), and git honors a repository's own .git/config. If the clone kept its .git, a remote repository could reach host command execution through keys such as gpg.program via log.showSignature.

Nothing guarded that. No comment explained it and no test pinned it, so a reasonable-looking change (keeping .git so diffs work on remote repos, for instance) would have reopened the path silently.

This adds the missing why, and a test that fails if the removal goes away.

Changes

  • src/core/git/gitCommand.ts: explain what the removal protects and why it must stay unconditional
  • tests/core/git/gitCommand.test.ts: assert .git is gone after execGitShallowClone. Unlike its sibling tests, this one uses a real temporary directory, because the guarantee is about what is left on disk rather than which git arguments ran

The same reasoning is already spelled out where the sandboxed MCP path disables git sorting (src/mcp/tools/packCodebaseTool.ts) and where the website drops .git from uploads. This brings the third site in line.

Verification

  • Deleting the fs.rm call turns the new test red, so it is not passing vacuously
  • Full suite green: 1798 tests across 151 files

🤖 Generated with Claude Code

intent(remote-clone): the .git removal is what stops a cloned repository from handing git its own config during the pack, but the code framed it as tidiness, so a later change could drop it without anyone noticing what was lost
constraint(remote-clone): the guarantee is about what is left on disk rather than which git arguments ran, so unlike its sibling tests this one uses a real temporary directory
learned(remote-clone): deleting the fs.rm call turns the new test red, so it pins the behavior instead of passing vacuously

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

⚡ Performance Benchmark

Latest commit:729f712 test(security): Pin that a remote clone's .git is always removed
Status:✅ Benchmark complete!
Ubuntu:0.81s (±0.02s) → 0.81s (±0.02s) · -0.00s (-0.1%)
macOS:0.84s (±0.10s) → 0.82s (±0.13s) · -0.02s (-2.6%)
Windows:1.03s (±0.03s) → 1.04s (±0.02s) · +0.01s (+0.6%)
Details
  • Packing the repomix repository with node bin/repomix.cjs
  • Warmup: 2 runs (discarded), interleaved execution
  • Measurement: 20 runs / 30 on macOS (median ± IQR)
  • Workflow run

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a977cb0-3b5b-4e0e-b91b-ef816826c945

📥 Commits

Reviewing files that changed from the base of the PR and between ebed8e7 and 729f712.

📒 Files selected for processing (2)
  • src/core/git/gitCommand.ts
  • tests/core/git/gitCommand.test.ts

📝 Walkthrough

Walkthrough

The change documents why execGitShallowClone always removes the cloned repository’s .git directory. A test creates .git/config, verifies its removal, and cleans up the temporary directory.

Changes

Git clone cleanup

Layer / File(s) Summary
Document and verify .git cleanup
src/core/git/gitCommand.ts, tests/core/git/gitCommand.test.ts
The cleanup comment explains the risk of retained Git configuration. The test verifies .git removal and temporary-directory cleanup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: serhiizghama

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the security regression test that ensures a remote clone's .git directory is removed.
Description check ✅ Passed The description explains the security rationale, implementation changes, and verification results, but it omits the repository checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security/pin-remote-clone-git-removal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.87%. Comparing base (8175eb1) to head (729f712).
⚠️ Report is 15 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1798   +/-   ##
=======================================
  Coverage   91.87%   91.87%           
=======================================
  Files         133      133           
  Lines        5574     5574           
  Branches     1365     1365           
=======================================
  Hits         5121     5121           
  Misses        453      453           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yamadashy
yamadashy merged commit 34e7432 into main Aug 11, 2026
51 of 52 checks passed
@yamadashy
yamadashy deleted the security/pin-remote-clone-git-removal branch August 11, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant