Summary
A critical command or code injection vulnerability in Gitea's diffpatch API may allow an attacker to achieve remote code execution through Git hook installation. The risk arises when the API processes attacker-controlled patch or repository-related input in a way that permits hook creation or execution.
Affected context
The vulnerability affects Gitea deployments using the diffpatch API and Git-related functionality that permits hook installation. It becomes especially risky when the API is reachable by untrusted or insufficiently trusted users and the resulting Git hooks execute with the privileges of the Gitea service or an associated repository process.
Exploit preconditions
- Attack surface: Gitea's remotely accessible diffpatch API
- Required access: Access sufficient to submit requests to the affected API; the exact requirement may depend on deployment authorization controls
- Trigger point: Processing a diff or patch operation that reaches Git hook installation behavior
- Why exploitation is possible: Attacker-controlled input can influence a repository operation in a manner that permits executable hook content or commands to be installed and subsequently run
Why this happens
The underlying bug is an insufficient separation between patch data and executable Git configuration or hook behavior. When API-controlled input is allowed to influence Git hook installation without strict validation, canonicalization, and authorization checks, attacker-supplied data may be interpreted as executable logic. This behavior maps to CWE-94, Improper Control of Generation of Code, commonly described as code injection.
Potential impact
- An attacker may execute arbitrary code on the Gitea host or service container
- The compromise could expose repositories, credentials, and application secrets
- Attackers could modify source code, workflows, or repository contents
- The vulnerability may enable lateral movement or broader infrastructure compromise
- Service availability could be disrupted through unauthorized commands or resource use
General mitigation guidance
Mitigation generally focuses on preventing untrusted API input from creating
executable Git hooks or influencing command execution.
Common defensive patterns include:
- Enforcing strict authorization for diff, patch, repository, and hook-related operations
- Treating patch content and repository metadata as data rather than executable configuration
- Validating, canonicalizing, and constraining all paths and hook-related values
- Using secure-by-default repository handling that disables unnecessary hook installation or execution
- Running Gitea with a dedicated, least-privileged service identity
- Isolating repository-processing workers and limiting filesystem, network, and secret access
- Applying request filtering and policy controls at the API boundary
How teams detect issues like this
Detection approaches may include:
- Static analysis for code paths that concatenate or derive Git hook paths, shell commands, or executable configuration from request data
- Code review checks for diffpatch handlers that lack strict authorization, path validation, or output encoding
- Runtime monitoring for unexpected hook creation, modification, or execution in repository directories
- Audit logging for patch API requests, repository changes, and process launches by the Gitea service account
- Policy enforcement that blocks unapproved executable files or hooks in managed repositories
- Automated security review tools that identify command and code injection patterns

