Source Code Repository Exposed
A version control directory such as .git is served by the web server, letting anyone rebuild the application's source code and full change history.
| Severity | High |
| CVSS 3.1 | 7.5 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N Open in the calculator |
| CVSS 4.0 | 8.7 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-527: Exposure of Version-Control Repository to an Unauthorized Control Sphere |
| MITRE ATT&CK | T1213.003 Code Repositories, T1552.001 Credentials In Files |
| Category | Information Disclosure |
Description
The application has been deployed as a working copy of its version control repository, and the repository's metadata directory, most often .git but also .svn, .hg or .bzr, is inside the web root and served. For Git, files such as HEAD, config, index and the object store can be downloaded and, because object names can be worked out from the references and the index, the whole repository can be rebuilt even when directory listing is disabled. Tools such as git-dumper and GitTools automate this. For Subversion, the wc.db database lists every file, and pristine copies of their contents are kept alongside it.
An attacker can therefore obtain the application's complete source code and history without authentication. The code allows a detailed search for further vulnerabilities, and repositories commonly hold secrets in configuration files, such as database credentials, API keys, cloud access keys and private keys, including secrets deleted in later commits, which remain in the history. Commit metadata also reveals developers' names and email addresses and internal host names, and the weakness frequently leads to a compromise that extends beyond the application itself.
The weakness is identified by requesting files such as /.git/HEAD, which returns a reference line beginning ref:, /.git/config and /.svn/wc.db. A 403 response for the directory itself does not mean that the files inside are protected, so individual files are requested directly. Content discovery tools and many web scanners check these paths.
Remediation
Remove the repository metadata from the web server and treat everything in it as disclosed:
- Deploy build artefacts produced by a pipeline or by
git archive, rather than cloning or pulling a working copy into the web root. - Delete version control directories from the deployed site.
- Block requests for version control directories at the web server as defence in depth, as below. On IIS, add
.gitand the other directory names as hidden segments in request filtering. - Rotate every credential and key that appears anywhere in the repository or its history, and move secrets out of the code into a secrets manager or the deployment environment.
- Review the code for vulnerabilities on the assumption that it is public, and check logs for earlier downloads of repository files.
Confirm the fix by requesting /.git/HEAD, /.git/config and the equivalent files for other systems: each should return 404 or 403, and dumping tools should recover nothing.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.