Code Repository (Git)
- CWE 425
- WASC 34
Exposed Code Repositories occur when source code, version control directories, or repository metadata (e.g., .git, .svn, .hg) are publicly accessible via the web. This can happen due to misconfigured web servers, accidental uploads, or unprotected development directories. Attackers can download source code, gain insight into application logic, credentials, API keys, or other sensitive data, and use this information to craft targeted attacks such as SQL Injection, Remote Code Execution, or privilege escalation.
Common patterns leading to exposed code repositories:
- Version control directories deployed to the web root (e.g.,
/repo/.git/,/svn/). - Backup or export copies of repositories accessible without authentication.
- Misconfigured web servers that serve hidden files or directories.
- Inclusion of repository metadata in public deployments.
Impacts:
- Information Disclosure: Source code, credentials, configuration files, and internal logic may be exposed.
- Facilitates Targeted Attacks: Knowledge of application internals helps attackers exploit vulnerabilities.
- Intellectual Property Theft: Proprietary code can be copied or modified.
- Increased Attack Surface: Attackers can identify endpoints, functions, and potential vulnerabilities.
Detection indicators:
- Publicly accessible
.git,.svn,.hg, or similar directories. - Downloadable repository archives or metadata files.
- Security scanners flagging repository files or directories.
Remediation
Mitigation focuses on access control, repository management, and secure deployment:
Restrict Access to Repositories
Do not expose version control directories or files to the public internet.Remove Metadata Before Deployment
Ensure.git,.svn,.hg, and backup files are excluded from production deployments.Enforce Authentication and Authorization
Protect internal code repositories with proper access control and strong authentication.Audit Deployment Pipelines
Check build and deployment processes to prevent accidental inclusion of source code or metadata.Monitor and Scan for Exposed Repositories
Regularly scan the web application for exposed version control files or directories.Educate Developers
Train teams on secure repository management and deployment practices.Security Testing
Include repository exposure tests during penetration testing and automated scans.