New Gitea RCE Lets Repository Writers Plant a Git Hook to Run Shell Commands
A critical remote code execution (RCE) vulnerability, CVE-2026-60004 (CVSS 9.8), exists in Gitea versions 1.17 through 1.27.0, allowing authenticated repository writers to execute arbitrary shell commands via a crafted Git patch. The exploit leverages a three-way merge fallback in `git apply` when submitting an identical patch twice, causing a bare temporary clone to write an executable hook file into the `$GIT_DIR/hooks/post-index-change` directory, which Git automatically executes during index
Analysis
TL;DR
- A critical remote code execution (RCE) vulnerability, CVE-2026-60004 (CVSS 9.8), exists in Gitea versions 1.17 through 1.27.0, allowing authenticated repository writers to execute arbitrary shell commands via a crafted Git patch.
- The exploit leverages a three-way merge fallback in
git applywhen submitting an identical patch twice, causing a bare temporary clone to write an executable hook file into the$GIT_DIR/hooks/post-index-changedirectory, which Git automatically executes during index updates. - Default open registration on unmodified Gitea instances allows anonymous attackers to create accounts and repositories, enabling exploitation without prior credentials.
- The fix, released in version 1.27.1, changes the temporary clone from bare to non-bare, preventing the hook from being placed in the Git directory; however, this change was misclassified as a "MISC refactor" in release notes, increasing risk of oversight.
- A separate, unpatched file-inclusion issue involving Org-mode’s
#+INCLUDEdirective was also addressed in 1.27.1 but not formally disclosed with a CVE or advisory.
Why It Matters
This vulnerability underscores the risks inherent in default configurations of widely used DevOps tools—Gitea’s open-by-default registration policy transforms a privilege escalation flaw into a full remote compromise for any unpatched instance. For AI practitioners and security teams managing CI/CD pipelines or code hosting platforms, it highlights the importance of hardening default settings, monitoring for subtle code changes labeled as refactors, and treating even minor API endpoints like /diffpatch as high-risk surfaces when they interact with system-level tools such as Git.
Technical Details
- Vulnerable Endpoint:
POST /api/v1/repos/{owner}/{repo}/diffpatch, which applies user-supplied patches usinggit apply --index --recount --cached --binarywith a-3fallback on Git ≥2.32. - Exploit Mechanism: Submitting the same patch twice triggers an add/add conflict in the three-way merge. Despite using
--cached, the merge writes files to the working tree due to the bare nature of the temporary clone ($GIT_DIR), placing an executable script athooks/post-index-change. - Execution Context: Git automatically runs
post-index-changehooks during index updates, executing the attacker’s payload as the Gitea service OS account. - Persistence & Exfiltration: The hook stores command output in Git objects, creates a branch with the data, and allows retrieval via authenticated smart HTTP—no outbound callback required.
- Fix Implementation: Version 1.27.1 switches the temporary clone from bare to non-bare, ensuring
--indexoperations affect the working tree outside the Git directory. However, this change was documented under “MISC” rather than “SECURITY,” reducing visibility. - Secondary Issue: A concurrent fix altered Gitea’s Org-mode renderer to treat
#+INCLUDEpaths as literal strings instead of reading them from the filesystem, mitigating a potential local file inclusion (LFI) vulnerability that allowed access to/etc/passwd.
Industry Insight
Organizations using self-hosted Git platforms should immediately audit their Gitea installations for version 1.27.0 or earlier and disable public registration until patched, even if only temporarily. Security teams must treat refactor commits in core infrastructure software with heightened scrutiny, especially those involving low-level tool integrations like Git CLI calls, as they may inadvertently introduce or resolve critical vulnerabilities. Additionally, vendors should prioritize explicit security labeling in changelogs and publish coordinated advisories for all related fixes—even those not assigned CVEs—to ensure comprehensive threat awareness across the ecosystem.
Disclaimer: The above content is generated by AI and is for reference only.