Summary
Gitea up to and including version 1.26.1 contains an authorization issue where Git smart HTTP requests authenticated with bearer tokens can bypass repository token scope checks.
This can allow an attacker with a valid token to perform operations outside the intended repository scope when using the smart HTTP interface.
Affected context
The vulnerability appears in Gitea deployments that:
- Use Git smart HTTP as a transport for repository access
- Rely on bearer or repository tokens with scoped permissions
- Expect token scopes to limit access to specific repositories or operations
It manifests when the authorization layer does not fully enforce or correctly map token scopes for smart HTTP Git operations.
Exploit preconditions
- Attack surface: Git smart HTTP endpoints exposed by Gitea
- Required access: Possession of a valid bearer or repository token, even if configured with restricted scope
- Trigger point: Performing Git smart HTTP requests (e.g., fetch, push, or other smart protocol calls) against repositories
- Why exploitation is possible: The authorization logic for smart HTTP requests does not correctly enforce repository-level token scope checks, allowing operations beyond the token's intended scope.
Why this happens
This issue stems from incomplete or inconsistent enforcement of authorization policies for token-scoped access, mapping to CWE-863: Incorrect Authorization.
The code path handling Git smart HTTP requests accepts bearer tokens but fails to verify that the token's declared repository scope actually covers the target repository or operation.
As a result, the system grants access based on token possession alone, without robust scope validation, breaking the intended least-privilege model.
Potential impact
- Unauthorized access to repositories the token holder should not reach
- Ability to read code or metadata from unintended repositories
- Potential to push or modify content in repositories beyond the token's scope
- Expansion of a limited-service token into broader account- or instance-level access
General mitigation guidance
Mitigation generally focuses on tightening authorization checks and reducing implicit trust in bearer tokens.
Common defensive patterns include:
- Ensuring that every authorization decision for Git smart HTTP requests cross-checks the token's declared scope against the target repository and requested action
- Centralizing authorization logic so that all access paths reuse the same scope validation mechanisms
- Designing tokens with minimally necessary privileges and separating tokens for automation from those used by humans
- Implementing defense-in-depth controls such as repository-level allowlists and explicit permissions for automation identities
- Periodically rotating tokens and monitoring for unexpected access patterns tied to scoped tokens
How teams detect issues like this
Detection can rely on both code-centric and operational controls:
- Static analysis or code review focusing on authorization middleware, confirming that smart HTTP handlers invoke consistent scope checks
- Verification that all token-authenticated endpoints pass through a unified access-control layer rather than custom per-endpoint checks
- Log analysis to identify tokens accessing repositories outside their expected scope or role
- Policy-driven tests or security unit tests that attempt access with deliberately under-scoped tokens to confirm enforcement
- Use of automated security testing tools that model role- and scope-based authorization rules and probe for inconsistencies

