Repository navigation
Conversation
…t gathering
ProjectContextProvider._run_git() ran `git status`/`branch`/`log` via
`subprocess.run(["git", "--no-optional-locks", *args], ...)` on every
session start, before any trust dialog is shown to the user (and
unconditionally in `-p` programmatic mode too). git's core.fsmonitor
config can name an arbitrary command that git executes on commands like
`status` to refresh the index -- and that config is repo-local, so a
malicious repo the user merely opens or clones can plant
[core]
fsmonitor = <payload>
in its own .git/config and have <payload> run with the user's full
privileges as soon as get_git_status() is called. Reported publicly with
a full PoC and CVSS 3.1 base score 8.8 (High) in mistralai#942.
Fix: pass `-c core.fsmonitor=` on the git invocation itself. Command-line
-c overrides take precedence over a repo's own .git/config, so this can't
be bypassed by whatever the inspected repo declares, and it requires no
change to the four call sites that share _run_git (branch --show-current,
branch -r, status --porcelain, log).
Verified against a live reproduction of the reported PoC (a real git repo
with a malicious core.fsmonitor entry that touches a marker file): without
the fix, `git status --porcelain` executes the payload; with `-c
core.fsmonitor=` added, it does not, and status output is unaffected.
Added two tests to tests/core/test_system_prompt.py:
- test_run_git_disables_fsmonitor_hook: asserts the flag is present in the
argv actually passed to git, ahead of the subcommand.
- test_fetch_git_status_does_not_execute_malicious_fsmonitor_hook: full
end-to-end reproduction of the mistralai#942 PoC against a real git repo; asserts
the payload marker is never created and get_git_status() still returns
a normal, non-error status string.
Both confirmed to fail against the pre-fix code (git stash isolating just
system_prompt.py) -- the malicious-hook test's failure is the payload
marker file actually being created by the test harness itself, i.e. a
live reproduction of the RCE, not just an assertion mismatch.
Full suite: 8084 passed, 17 skipped, 5 failed -- same 5 pre-existing
failures (TUI widget mounting, file-fingerprint mtime-resolution timing,
two unrelated e2e timeouts, latin1 grep-encoding matching) reproduced
against a clean upstream/main checkout; none touch system_prompt.py or
this call path. ruff check / ruff format clean.
Contributor
|
Hi @mittalpk , thanks for your contribution! It's been integrated in our internal repo, you'll be credited as co-author in the next release. Sorry for the abrupt closing, it looks like some automation closed your PR when we merged our PR internally 😛 |
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.
Fixes #942.
Summary
ProjectContextProvider._run_git()runsgit status/branch/logviasubprocess.run(["git", "--no-optional-locks", *args], ...)on every session start, before any trust dialog is shown to the user (and unconditionally in-pprogrammatic mode too, per the original report).git's
core.fsmonitorconfig can name an arbitrary command that git executes on commands likestatusto refresh the index — and that config is repo-local, so a malicious repo the user merely opens or clones can plantin its own
.git/configand have<payload>run with the user's full privileges as soon asget_git_status()is called. Reported publicly with a full PoC and CVSS 3.1 base score 8.8 (High) in #942.Fix
Pass
-c core.fsmonitor=on the git invocation itself:Command-line
-coverrides take precedence over a repo's own.git/config, so this can't be bypassed by whatever the inspected repo declares. Since all four call sites (branch --show-current,branch -r,status --porcelain,log) share_run_git, one change covers all of them.Verification
I reproduced the reported PoC locally before and after the fix, not just read the code and assumed:
Tests
Added two tests to
tests/core/test_system_prompt.py:test_run_git_disables_fsmonitor_hook— asserts-c core.fsmonitor=is present in the argv actually passed to git, positioned ahead of the subcommand.test_fetch_git_status_does_not_execute_malicious_fsmonitor_hook— full end-to-end reproduction of the bug: [Security] Remote Code Execution viagitconfiguration #942 PoC against a real git repo; asserts the payload marker is never created andget_git_status()still returns a normal, non-error status string.Both confirmed to fail against the pre-fix code (
git stashisolating justsystem_prompt.py) — the malicious-hook test's failure is the payload marker file actually being created by the test harness itself, i.e. a live reproduction of the RCE, not just an assertion mismatch.