
Gitea diffpatch RCE (CVE-2026-60004) PoC - repo-write to RCE as Gitea service account
Remote code execution PoC for the Gitea diffpatch endpoint. An account with write access to a repository (on instances with open registration, simply registering an account suffices) can execute arbitrary shell commands on the server as the Gitea service account.
POST /api/v1/repos/{owner}/{repo}/diffpatch applies an attacker-controlled patch in a shared bare temporary clone repository:
git apply --index --recount --cached --binary # Git ≥ 2.32 时追加 -3 三路合并回退
Attack chain: submitting the same patch twice → add/add conflict → the three-way merge fallback checks out the index paths (even with --cached) → in a bare repository root = $GIT_DIR, and the checked-out hooks/post-index-change (100755) becomes an active Git hook → Git automatically executes it when writing the index → RCE.
AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H470d34b1)-3 three-way merge)diffpatch endpoint available# 设置账户密码
export GITEA_PASSWORD='account-password'
python3 gitea_diffpatch_rce_poc.py \
https://<gitea-base-url> \
<username> \
'id; uname -srm; pwd'
| Parameter | Description |
|---|---|
url | Gitea base URL |
username | An existing Gitea username (availability: open registration by default) |
Requirements: Python 3 + a local git client.
PoC flow: authenticate → create a private initialized repository → craft a hooks/post-index-change patch → deliver it to diffpatch twice in a row (triggering an add/add conflict) → Git executes the hook → retrieve command output over authenticated Smart HTTP. No outbound callback; output is returned in-band.
For security research, vulnerability validation, and defensive testing only. This PoC creates repositories, submits patches, and triggers server-side command execution on the target instance. Run it only on your own test instance; do not use it against unauthorized or production environments.
command | The shell command to execute on the target |
GITEA_PASSWORD | Account password (environment variable, or interactive input) |