Summary
Gitea's OAuth2 implementation fails to correctly persist the PKCE S256 challenge method, allowing an authorization code to be exchanged for a token without enforcing the expected verifier check.
In deployments that rely on PKCE for additional authorization protection, this flaw can let an attacker bypass the intended proof-of-possession step and gain tokens under certain conditions.
Affected context
The vulnerability appears in Gitea instances that act as an OAuth2 authorization server and advertise support for PKCE with the S256 method.
It is most relevant where clients and operators assume that PKCE is correctly enforced as a second layer of defense beyond client secrets, particularly for public or mobile clients.
The issue manifests during the OAuth2 authorization code flow, where the PKCE method is not reliably persisted or enforced between the authorization request and the token exchange.
Exploit preconditions
- Attack surface: OAuth2 authorization and token endpoints exposed by a Gitea server.
- Required access: Ability to initiate OAuth2 authorization code flows against the affected Gitea instance (e.g., as a legitimate or semi-trusted client).
- Trigger point: The attacker completes an authorization request with PKCE parameters and later performs a token exchange that is processed without the expected S256 verifier validation.
- Why exploitation is possible: The PKCE challenge method is not consistently stored or re-applied, so the server may accept a token request without correctly validating the code verifier, weakening or bypassing the intended proof-of-key possession requirement.
Why this happens
This flaw stems from incomplete enforcement of authorization controls in the OAuth2 PKCE implementation.
Instead of treating the PKCE S256 challenge method and verifier as mandatory, coupled state that must be validated throughout the entire authorization code flow, the server fails to reliably persist or re-check the declared challenge method at token exchange time.
Conceptually, this maps to CWE-284: Improper Access Control, because the system assumes PKCE-based proof-of-possession but does not consistently enforce it, allowing tokens to be issued under weaker or missing verification constraints.
Potential impact
- An attacker may obtain access tokens without presenting a valid PKCE verifier when the flow is mis-enforced.
- OAuth2 clients that rely on PKCE for protection of public clients may experience reduced security guarantees.
- Session hijacking or impersonation may become more feasible if authorization codes can be exchanged by parties that did not prove possession of the correct key material.
- Broader compromise of Gitea-hosted resources may occur if tokens issued under weak verification are used to access repositories or APIs.
General mitigation guidance
Mitigation generally focuses on strengthening and simplifying authorization flows and access control enforcement.
Recommended patterns include:
- Treat PKCE challenge method and verifier as required, immutable state across the authorization and token exchange steps.
- Design authorization servers so that any declared PKCE parameters are always validated before issuing tokens, failing closed on inconsistent or missing values.
- Adopt a defense-in-depth approach, combining PKCE with robust client identification, scoped tokens, and least-privilege access policies.
- Minimize trust in user-controllable OAuth2 parameters by validating them against whitelisted or server-controlled expectations.
- Regularly review and test authentication and authorization flows, including edge cases and error-handling paths, to ensure controls are consistently applied.
How teams detect issues like this
Detection often involves reviewing both configuration and implementation of OAuth2 flows:
- Perform code audits or static analysis focused on authorization and token issuance paths, ensuring that PKCE parameters and access control checks are enforced consistently.
- Introduce automated tests that simulate OAuth2 flows with and without valid PKCE verifiers, verifying that token issuance fails when proof-of-possession is missing or malformed.
- Use logging and monitoring to capture details of OAuth2 exchanges, including presence of PKCE parameters, and alert on anomalous patterns such as tokens issued without corresponding verifier checks.
- Employ security testing tools or manual penetration testing targeted at the OAuth2 endpoints to discover inconsistencies in PKCE handling and authorization enforcement.

