CVE-2023-41040: GitPython Arbitrary File Read Vulnerability
Summary
CVE-2023-41040: GitPython is a python library used to interact with Git repositories. Affects gitpython versions < 3.1.35. Fixed in 3.1.35. How to fix ↓
Also tracked for
- python-git · Debian:11
The same CVE-2023-41040 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
GitPython is a Python library used for interacting with Git repositories. It provides functionality to read files from the .git directory and resolve Git references. This vulnerability arises from a lack of validation when reading user-provided file names, allowing an attacker to make GitPython read any file from the system. Although the vulnerability does not expose file contents, it could potentially be exploited to trigger a denial of service. The vulnerable code can be found in the git/refs/symbolic.py file of the GitPython repository.
Vulnerability Detail
The vulnerability in GitPython arises from the insecure handling of file paths provided by users. The code in question joins a base directory with a user-supplied string without verifying if the resulting path is located outside the base directory. This oversight allows an attacker to specify a file outside the .git directory, potentially leading to a denial of service. The vulnerability has been assigned a CVSSv3 score of 6.5 (Medium severity).
How To Fix
Latest published version: 3.2.1 as of 23 Oct 2026
pip install --upgrade "gitpython==3.2.1"
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
3.1.35
This is the first release that contains the fix.
pip install --upgrade "gitpython==3.1.35"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a workaround, users can manually modify the vulnerable code in the git/refs/symbolic.py file of their GitPython installation. The following code snippet demonstrates the necessary modification:
# Before
path = os.path.join(base, user_supplied_file)
# After
if not os.path.isabs(user_supplied_file):
path = os.path.join(base, user_supplied_file)
Conclusion
In conclusion, the GitPython library is vulnerable to an arbitrary file read issue, which can potentially lead to a denial of service. Users are advised to update GitPython to version 3.1.35 or later to mitigate this vulnerability. Alternatively, a temporary workaround involving code modification is available. For further assistance or support in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for gitpython →
FAQ
GitPython is a Python library that provides functionality to interact with Git repositories. It allows users to perform various Git operations programmatically.
The vulnerability allows an attacker to make GitPython read any file from the system. While it does not expose file contents, it can potentially be used to trigger a denial of service.
The recommended fix is to update GitPython to version 3.1.35 or later. This update includes the necessary validation checks to prevent arbitrary file reads.
Yes, a temporary workaround involves manually modifying the vulnerable code in the git/refs/symbolic.py file of the GitPython installation. Refer to the provided code snippet for the necessary modification.
The CVSSv3 score assigned to this vulnerability is 6.5, indicating a medium severity level.
References
Related vulnerabilities
Recent vulnerabilities recorded for gitpython.