Summary
Gitea 1.25.5 incorrectly caches branch-specific write permissions across multiple refs during a single pre-receive hook session.
This allows a maintainer with write access to one branch to reuse that grant for other refs, potentially escalating to full repository write access when multiple refs are pushed.
Affected context
This vulnerability occurs in Gitea instances that rely on pre-receive hooks to enforce branch-specific write permissions.
It becomes relevant when users push changes involving multiple refs or branches in a single operation, and the hook logic uses cached authorization decisions instead of re-evaluating each ref individually.
Environments with fine-grained branch protection and delegated maintainer rights are more exposed, especially where repository write access is expected to remain limited to certain branches.
Exploit preconditions
- Attack surface: Git push operations handled by Gitea's pre-receive hook logic.
- Required access: Legitimate write permission to at least one protected branch or ref in the target repository.
- Trigger point: A multi-ref push where the attacker includes updates to other branches or refs beyond those they are authorized to modify.
- Why exploitation is possible: The hook caches a positive authorization decision for one branch and reuses it for subsequent refs within the same session, instead of performing a separate permission check per ref, leading to incorrect privilege propagation.
Why this happens
The underlying issue is an authorization logic flaw where access-control decisions are cached too broadly within a pre-receive hook session.
Rather than associating the cached result with the specific branch or ref that was checked, the implementation effectively treats the prior grant as valid for later refs, conflating distinct authorization contexts.
This aligns with CWE-863: Incorrect Authorization, where permission checks are either incomplete or applied to the wrong resource, causing privilege escalation when multiple related objects share a common control path.
Potential impact
- Maintainers with per-branch rights may gain unintended write access to additional branches.
- Attackers can push changes to protected branches they are not supposed to modify.
- Repository history and integrity can be altered across previously restricted refs.
- Security controls relying on branch protection policies can be bypassed.
- Downstream pipelines and deployments may consume unauthorized or malicious changes.
General mitigation guidance
Effective mitigation typically focuses on tightening authorization scope and enforcing per-ref checks consistently.
Common defensive patterns include:
- Ensuring that every ref or branch processed by hooks undergoes an independent permission evaluation.
- Avoiding shared authorization caches that are not explicitly keyed by resource identity (e.g., branch name, ref ID).
- Designing hook and access-control logic with clear separation between authentication (who) and authorization (what for which resource).
- Applying least-privilege principles for maintainer roles so that access is narrowly scoped to intended branches.
- Incorporating defense-in-depth policies (such as server-side branch protection) that do not rely solely on hook-level decisions.
How teams detect issues like this
Detection can center on reviewing authorization code paths and enforcing policy checks for multi-ref operations.
Strategies may include:
- Static analysis or manual code review to identify authorization results that are cached or reused without being keyed to specific resources.
- Examining hook implementations for single-pass permission checks that are applied globally across refs in a session.
- Logging and monitoring write operations by branch, looking for patterns where users modify branches outside their expected scope.
- Implementing automated policy enforcement in CI/CD pipelines that validates branch-level access controls independently of the server hooks.
- Using security-focused code review tools to flag authorization logic that mixes resource-independent and resource-specific decisions.

