## https://sploitus.com/exploit?id=0D713120-944A-54D1-8462-A83F53952638
# CVE-2026-52813 â Gogs path traversal leading to remote code execution in GitHooks (Defensive Analysis)
> Security research / BlueTeam writeup. This repository **does not contain weaponized PoCs**. Researchers who need to reproduce this issue should use the public PoCs referenced in official advisories. | Project | Content |
|---|---|
| CVE | [CVE-2026-52813](https://github.com/gogs/gogs/security/advisories/GHSA-c39w-43gm-34h5) |
| Alias | GHSA-c39w-43gm-34h5 / GO-2026-5305 |
| Affected Versions | **Gogs**, where malicious `hooks/update` can be executed locally in a checkout of another repository, executed by Git automatically â RCE as the `git` user. ---
## Affected Versions and Mitigations
| Gogs Version | Status |
|---|---|
| `= 0.14.3` | Fixed |
**Upgrade is the only complete fix**:
```bash
# Docker
docker pull gogs/gogs:0.14.3
# Or source code
git checkout v0.14.3 && go build
```
Temporaryďźwhen upgrading is not possible):
- **Disable registration** (`app.ini` â `[service] DISABLE_REGISTRATION = true`), lower the precondition from âunauthorizedâ to âexisting account requiredâ;
- Add WAF rules at the reverse proxy layers (nginx/Caddy/Traefik) to block requests to `/api/v1/user/orgs` and `/api/v1/org/*/repos` with fields `username`/`name` containing `..` or `/` (see [detection/](detection/));
- Restrict Gogs containersâ write permissions to paths outside `/data/gogs/data/tmp/` (selinux/apparmor). ---
## Root Cause Analysis
### 1. Verification asymmetry: Web side exists, API does not
Web form (`internal/form/org.go`, v0.14.2):
```go
type CreateOrg struct {
OrgName string `binding:"Required;AlphaDashDash;MaxSize(35)"` // Regular expression ^[a-zA-Z0-9._-]+$
}
```
API (`internal/route/api/v1/org/org.go`, v0.14.2):
```go
// The binding tag for api.CreateOrgOption (go-gogs-client):
type CreateOrgOption struct {
UserName string `json:"username" binding:"Required"` // No AlphaDashDash!
}
```
â The `username` field in `POST /api/v1/user/orgs` can carry any character directly to the database layer. ### 2. Database layer only checks reserved names, not character sets
`internal/database/users.go:1532` `isNameAllowed` only blocks reserved names/paths like `admin`, `-bot`, **does not check character sets**, so `../` can pass. ### 3. Path sinks lack purification
`internal/repoutil/repoutil.go` (v0.14.2):
```go
func UserPath(user string) string {
return filepath.Join(conf.Repository.Root, strings.ToLower(user)) // Directly concatenate
}
```
`internal/database/org.go:165`:
```go
os.MkdirAll(repoutil.UserPath(org.Name), os.ModePerm) // org.Name contains../ â Any path can be written to
```
### 4. Exploitation of local-r working tree hooks
When Gogs processes web/API file edits, it checksouts the repository to `/data/gogs/data/tmp/local-r//`. This path **exactly matches the database `id` of the repository**. Attackers can:
1. Create a personal repository `writer`, get `id == n`;
2.
The API triggered file operations on âwriterâ within the organizationâs working tree â The physical directory is located in âwriterââs working tree.
3. Created a repository named ârce-xâ under that organization â Itâs located at âlocal-r/n/nested/rce-x.gitâ.
4. Cloned âwriterâ, submitted ânested/rce-x.git/hooks/updateâ as a **normal file** and pushed it (itâs located in writerâs working tree).
5. The API triggered file operations on âwriterâ; Gogs executed âhooks/updateâ in âlocal-r/â. This constitutes **RCE**. Key point: The malicious hook was introduced as part of normal repository content via a normal push; thereâs **no need** to enable âENABLE_GIT_HOOKSâ configurationâthis is the difference between this vulnerability and traditional âgit hooks abuseâ. For detailed patch analysis, see [patch/ANALYSIS.md](patch/ANALYSIS.md).
### Detection
Full rules are available at [detection/](detection/):
- **Sigma rules**: [detection/sigma/](detection/sigma/) â Cover attack attempts (API requests containing â..â) and successful exploitation (file system execution).
- **SIEM queries**: [detection/queries.md](detection/queries.md) â Splunk / Elastic / Kibana / Loki.
- **IOC detections**: [detection/iocs.md](detection/iocs.md) â File system traces, log signatures, username characteristics.
**Two key points:**
1. **WAF/Proxy layer interception**: Requests like âPOST /api/v1/user/orgsâ and âPOST /api/v1/org/*/reposâ have fields like âusernameâ/ânameâ containing â..â or â/â.
2. **File system inspections**: Unusual subdirectories appear in â/data/gogs/data/tmp/local-r/â, such as ânested/â, ârce-*.gitâ, and âhooks/updateâ.
### Defensive tools
- [tools/check_version.py](tools/check_version.py) â **Non-invasive** version scanner: Checks whether Gogs instances are **armed**. For reproduction, use the public PoC referenced in [official advisory](https://github.com/gogs/gogs/security/advisories/GHSA-c39w-43gm-34h5), and perform tests only in isolated environments.
### Experimental environment
Rules from [detection/](detection/) need to be tested on affected Gogs. The isolated Gogs 0.14.2 environment provided in [lab/docker-compose.yml](lab/docker-compose.yml) can be used for testing rule effectiveness. **Do not expose it to the public internet; use it only locally.**
### Timeline
| Date | Event |
---|---|
| 2026-06-08 | CVE reserved |
| 2026-06-24 | Public disclosure; Gogs 0.14.3 released |
| 2026-06-24 | Official advisory GHSA-c39w-43gm-34h5 published |
### References
- Official advisory: https://github.com/gogs/gogs/security/advisories/GHSA-c39w-43gm-34h5
- Fixing PR: https://github.com/gogs/gogs/pull/8334
- OSV: https://osv.dev/vulnerability/CVE-2026-52813
- Gogs 0.14.3 release: https://github.com/gogs/gogs/releases/tag/v0.14.3
### Note regarding âgitrebase parameter injectionâ misinformation
Some online sources describe this CVE as âgitrebase parameter injection leading to remote code executionââ**thatâs incorrect**. This vulnerability has nothing to do with âgit rebaseâ or âgitrebaseâ; the root cause is API path traversal. This document analyzes the vulnerability based on its true nature.
### License
MIT â See [LICENSE](LICENSE).