Skip to content

Commit

Permalink
Fix 500 when getting user as unauthenticated user (#8653) (#8663)
Browse files Browse the repository at this point in the history
Backport #8653

When doing GET /api/v1/users/{user} as an unauthenticated user,
gitea throws a 500 because it's trying to dereference elements
from the context user. It wants to do this to see whether to
show the primary email and will do that if the logged in user
is admin or the user in question. However, if ctx.User is nil there is a panic
  • Loading branch information
emonty authored and zeripath committed Oct 25, 2019
1 parent fa03af8 commit 9bde52f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion routers/api/v1/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func GetInfo(ctx *context.APIContext) {
return
}

ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User.ID == u.ID || ctx.User.IsAdmin))
ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User != nil && (ctx.User.ID == u.ID || ctx.User.IsAdmin)))
}

// GetAuthenticatedUser get current user's information
Expand Down

0 comments on commit 9bde52f

Please sign in to comment.