<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Gitpython — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/tags/gitpython/</link><description>Trending threats, MITRE ATT&amp;CK coverage, and detection metadata — refreshed continuously.</description><generator>Hugo</generator><language>en</language><managingEditor>hello@craftedsignal.io</managingEditor><webMaster>hello@craftedsignal.io</webMaster><lastBuildDate>Tue, 23 Jan 2024 12:00:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/tags/gitpython/feed.xml" rel="self" type="application/rss+xml"/><item><title>GitPython Vulnerability Allows Arbitrary Code Execution via Git Hooks</title><link>https://feed.craftedsignal.io/briefs/2024-01-23-gitpython-hook-execution/</link><pubDate>Tue, 23 Jan 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-23-gitpython-hook-execution/</guid><description>A vulnerability in GitPython versions prior to 3.1.47 allows for command execution during repository cloning by manipulating the `multi_options` parameter to inject malicious Git configurations, such as `core.hooksPath`, leading to the execution of attacker-controlled hooks.</description><content:encoded><![CDATA[<p>GitPython before version 3.1.47 is susceptible to a command execution vulnerability. The issue stems from how the <code>_clone()</code> function validates the <code>multi_options</code> parameter used in the <code>clone_from()</code>, <code>clone()</code>, or <code>Submodule.update()</code> methods. Specifically, the validation occurs on the original list of options before the <code>shlex.split</code> transformation. This allows an attacker to craft a string like <code>&quot;--branch main --config core.hooksPath=/x&quot;</code> which passes the initial validation because it starts with a safe option (<code>--branch</code>). However, after the string is split into tokens, the <code>--config</code> option becomes active, allowing the attacker to inject a malicious <code>core.hooksPath</code> configuration. This configuration points Git to a directory containing attacker-controlled Git hooks, which are then executed during the clone operation. This vulnerability is similar in nature to CVE-2023-40267.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker identifies a vulnerable application using GitPython to clone repositories.</li>
<li>The attacker crafts a malicious string containing a Git configuration option, such as <code>--config core.hooksPath=/path/to/malicious/hooks</code>, embedded within a seemingly benign option string like <code>--branch main --config core.hooksPath=/path/to/malicious/hooks</code>.</li>
<li>The attacker injects this malicious string into the <code>multi_options</code> parameter of the <code>clone_from()</code>, <code>clone()</code>, or <code>Submodule.update()</code> methods.</li>
<li>GitPython&rsquo;s <code>_clone()</code> function validates the <code>multi_options</code> parameter using <code>Git.check_unsafe_options()</code> <em>before</em> it is processed by <code>shlex.split()</code>.</li>
<li>Because the malicious string starts with a safe option (<code>--branch</code>), it bypasses the validation check.</li>
<li>The <code>shlex.split()</code> function then transforms the string into a list of individual options, making the <code>--config</code> option active.</li>
<li>The <code>git clone</code> command is executed with the injected <code>--config core.hooksPath=/path/to/malicious/hooks</code> option, causing Git to use the attacker-controlled directory for Git hooks.</li>
<li>Git executes the malicious hooks (e.g., <code>post-checkout</code>), resulting in arbitrary code execution on the victim&rsquo;s machine.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation of this vulnerability allows an attacker to execute arbitrary code on the system where the GitPython library is used. Any application that passes user-supplied input to the <code>multi_options</code> parameter of the affected functions is vulnerable. This can lead to complete system compromise, data exfiltration, or denial of service. The vulnerability affects GitPython versions prior to 3.1.47.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Upgrade GitPython to version 3.1.47 or later to patch the vulnerability (Affected Packages).</li>
<li>Implement input validation and sanitization for any user-supplied input used to construct the <code>multi_options</code> parameter to prevent injection of malicious Git configurations (Code).</li>
<li>Monitor process creation events for the execution of unexpected processes from directories specified as <code>core.hooksPath</code> (see Sigma rule <code>Detect Suspicious Git Hook Execution</code>).</li>
<li>Deploy the Sigma rules in this brief to your SIEM and tune for your environment.</li>
</ul>
]]></content:encoded><category domain="severity">high</category><category domain="type">advisory</category><category>gitpython</category><category>code-execution</category><category>git-hooks</category><category>command-injection</category></item><item><title>GitPython Command Injection Vulnerability</title><link>https://feed.craftedsignal.io/briefs/2024-01-09-gitpython-cmd-injection/</link><pubDate>Tue, 09 Jan 2024 10:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-09-gitpython-cmd-injection/</guid><description>GitPython versions 3.1.30 through 3.1.46 are vulnerable to command injection by passing attacker-controlled kwargs into `Repo.clone_from()`, `Remote.fetch()`, `Remote.pull()`, or `Remote.push()`, leading to arbitrary command execution due to bypassed safety checks.</description><content:encoded><![CDATA[<p>GitPython, a library providing programmatic interaction with Git repositories, is susceptible to a command injection vulnerability in versions 3.1.30 to 3.1.46. The vulnerability stems from insufficient validation of keyword arguments (kwargs) passed to functions like <code>Repo.clone_from()</code>, <code>Remote.fetch()</code>, <code>Remote.pull()</code>, and <code>Remote.push()</code>. Specifically, when underscore-form kwargs (e.g., <code>upload_pack</code>) are used, they bypass the intended safety checks designed to prevent the execution of arbitrary commands via Git options like <code>--upload-pack</code>. This occurs because the validation logic only checks for hyphenated forms (e.g., <code>upload-pack</code>). Attackers can exploit this by injecting malicious commands through these kwargs, even when <code>allow_unsafe_options</code> is set to its default value of <code>False</code>. This issue was reported on April 25, 2026.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker identifies a web application or system that uses GitPython to manage Git repositories.</li>
<li>The attacker finds an endpoint or function where they can control kwargs passed to <code>Repo.clone_from()</code>, <code>Remote.fetch()</code>, <code>Remote.pull()</code>, or <code>Remote.push()</code>.</li>
<li>The attacker crafts a malicious payload, using underscore-form kwargs such as <code>upload_pack</code> or <code>receive_pack</code>, setting their value to a command they want to execute (e.g., a shell script path or a direct command).</li>
<li>The application or system, using a vulnerable version of GitPython, receives these kwargs and bypasses the intended safety check.</li>
<li>GitPython&rsquo;s <code>Git.transform_kwarg()</code> method converts the underscore-form kwargs into their corresponding hyphenated Git options (e.g., <code>upload_pack</code> becomes <code>--upload-pack</code>).</li>
<li>The Git command is executed with the attacker-controlled option, leading to arbitrary command execution on the system.</li>
<li>The attacker gains unauthorized access, potentially stealing credentials, modifying repositories, or moving laterally within the network.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation of this vulnerability can lead to severe consequences, especially in web applications, CI/CD systems, and automation tools that rely on GitPython for repository management. Attackers could steal SSH keys, API tokens, cloud credentials, or other sensitive information. They could also modify repositories, build outputs, or release artifacts, leading to supply chain attacks. In CI/CD environments, this vulnerability could enable lateral movement from worker nodes or compromise the entire automation infrastructure. The number of affected systems depends on the prevalence of vulnerable GitPython versions in exposed applications.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Upgrade GitPython to version 3.1.47 or later to remediate the vulnerability (affected_products).</li>
<li>Review code that uses <code>Repo.clone_from()</code>, <code>Remote.fetch()</code>, <code>Remote.pull()</code>, or <code>Remote.push()</code> and ensure that kwargs are properly validated to prevent attacker-controlled input (references).</li>
<li>Implement input validation to block underscore-form kwargs such as <code>upload_pack</code> or <code>receive_pack</code> before they are passed to GitPython functions (references).</li>
<li>Deploy the Sigma rule <code>Detect GitPython Kwarg Command Injection</code> to identify potential exploitation attempts in application logs (rules).</li>
</ul>
]]></content:encoded><category domain="severity">high</category><category domain="type">advisory</category><category>command-injection</category><category>gitpython</category><category>vulnerability</category></item></channel></rss>