The vulnerability lies in the CheckRepoScopedToken function within services/context/permission.go. This function is responsible for verifying if an access token has the necessary scopes to perform operations on a repository. The analysis of the security advisory and the corresponding patch 677ab982bfbe9d72b7479f4618e423f93829371d reveals that the function included a check !ctx.IsBasicAuth. This check meant that the function would immediately return, and thus skip scope validation, if the authentication method was not HTTP Basic Auth.
Git Smart HTTP in Gitea allows for Bearer token authentication (e.g., for Personal Access Tokens or OAuth2 tokens). When such a token was used, ctx.IsBasicAuth would be false, triggering the early exit and bypassing the crucial scope validation. As a result, a token lacking read:repository or write:repository scopes could still be used to clone private repositories or push changes, respectively. The fix removes the !ctx.IsBasicAuth condition, ensuring that token scopes are checked for all API requests, regardless of the authentication mechanism, effectively patching the incorrect authorization vulnerability.