Summary
A logic flaw in Gitea's pre-receive hook handling allows oversized input to bypass branch-protection checks when scanner errors are not treated as failures.
Under certain error conditions, pushes that should be blocked may be accepted, letting attackers circumvent repository protection rules and modify restricted branches.
Affected context
This vulnerability manifests in Gitea instances that rely on pre-receive hooks and branch protection to enforce repository policies.
It is relevant when push input is processed using buffered scanners that can encounter errors on large or malformed payloads.
When scanner failures are not handled in a fail-closed manner, the protection logic can be skipped, creating a gap between intended authorization rules and actual enforcement.
Exploit preconditions
- Attack surface: Git push operations to repositories hosted on the affected Gitea instance.
- Required access: Ability to push to the repository (e.g., a user with any level of write access to a branch or fork).
- Trigger point: Submission of oversized or specially crafted input to the pre-receive hook that causes the scanner to error.
- Why exploitation is possible: The authorization checks depend on successful scanning of hook input; scanner errors are not treated as denial conditions, allowing the operation to proceed without enforcing branch protection.
Why this happens
The root cause is improper handling of authorization logic when dependent input processing fails.
Pre-receive hooks rely on bufio.Scanner to parse incoming data before applying branch-protection rules, but errors from this scanner are not treated as hard failures.
This aligns with CWE-863: Incorrect Authorization, where the system assumes successful input processing and does not default to denying the operation on parsing errors, resulting in an authorization bypass.
Potential impact
- Protected branches may be modified by users who should be blocked by branch-protection rules.
- Code that should be subject to mandatory reviews or approvals can be pushed directly.
- Security controls based on pre-receive hooks, such as policy or compliance checks, may be silently bypassed.
- Integrity of critical branches (e.g., main, release, or security branches) can be compromised.
General mitigation guidance
Mitigation typically focuses on enforcing fail-closed behavior for authorization-related input processing.
Common defensive patterns include:
- Treating any scanner or parsing error in pre-receive hooks as a hard failure that blocks the push.
- Designing hook logic so that protection checks run only when inputs are fully and correctly parsed, and deny on any uncertainty.
- Separating authorization decisions from fragile parsing paths where possible, or validating input size and format before deeper processing.
- Applying least-privilege principles to repository write permissions so that fewer accounts can trigger edge-case behavior.
How teams detect issues like this
Detection approaches commonly include:
- Code review focused on authorization paths, verifying that all error states from parsers or scanners lead to explicit denial of the operation.
- Static analysis rules that flag authorization checks dependent on non-validated or potentially failing input-processing routines.
- Logging and monitoring of pre-receive hook failures versus successful pushes, looking for anomalous cases where hooks encounter errors but the push still succeeds.
- Periodic security tests or policy enforcement audits that attempt to push oversized or malformed data to confirm hooks fail closed.

