Skip to content

Commit 248a5b8

Browse files
GiteaBotarcher-321wxiaoguang
authored andcommitted
Prevent automatic OAuth grants for public clients (go-gitea#30790) (go-gitea#30836)
Backport go-gitea#30790 by archer-321 This commit forces the resource owner (user) to always approve OAuth 2.0 authorization requests if the client is public (e.g. native applications). As detailed in [RFC 6749 Section 10.2](https://www.rfc-editor.org/rfc/rfc6749.html#section-10.2), > The authorization server SHOULD NOT process repeated authorization requests automatically (without active resource owner interaction) without authenticating the client or relying on other measures to ensure that the repeated request comes from the original client and not an impersonator. With the implementation prior to this patch, attackers with access to the redirect URI (e.g., the loopback interface for `git-credential-oauth`) can get access to the user account without any user interaction if they can redirect the user to the `/login/oauth/authorize` endpoint somehow (e.g., with `xdg-open` on Linux). Fixes go-gitea#25061. Co-authored-by: Archer <[email protected]> Co-authored-by: wxiaoguang <[email protected]> (cherry picked from commit 6d83f5e)
1 parent 5678e9a commit 248a5b8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

routers/web/auth/oauth.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,9 @@ func AuthorizeOAuth(ctx *context.Context) {
469469
return
470470
}
471471

472-
// Redirect if user already granted access
473-
if grant != nil {
472+
// Redirect if user already granted access and the application is confidential.
473+
// I.e. always require authorization for public clients as recommended by RFC 6749 Section 10.2
474+
if app.ConfidentialClient && grant != nil {
474475
code, err := grant.GenerateNewAuthorizationCode(ctx, form.RedirectURI, form.CodeChallenge, form.CodeChallengeMethod)
475476
if err != nil {
476477
handleServerError(ctx, form.State, form.RedirectURI)

0 commit comments

Comments
 (0)