fix(auth): harden oauth callback adoption flows
This commit is contained in:
@@ -464,15 +464,7 @@ func (h *AuthHandler) findOAuthIdentityUser(ctx context.Context, identity servic
|
||||
}
|
||||
return nil, infraerrors.InternalServer("AUTH_IDENTITY_LOOKUP_FAILED", "failed to inspect auth identity ownership").WithCause(err)
|
||||
}
|
||||
|
||||
userEntity, err := client.User.Get(ctx, record.UserID)
|
||||
if err != nil {
|
||||
if dbent.IsNotFound(err) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, infraerrors.InternalServer("AUTH_IDENTITY_USER_LOOKUP_FAILED", "failed to load auth identity user").WithCause(err)
|
||||
}
|
||||
return userEntity, nil
|
||||
return findActiveUserByID(ctx, client, record.UserID)
|
||||
}
|
||||
|
||||
func (h *AuthHandler) BindLinuxDoOAuthLogin(c *gin.Context) { h.bindPendingOAuthLogin(c, "linuxdo") }
|
||||
@@ -998,6 +990,9 @@ func findActiveUserByID(ctx context.Context, client *dbent.Client, userID int64)
|
||||
}
|
||||
return nil, infraerrors.InternalServer("AUTH_IDENTITY_USER_LOOKUP_FAILED", "failed to load auth identity user").WithCause(err)
|
||||
}
|
||||
if !strings.EqualFold(strings.TrimSpace(userEntity.Status), service.StatusActive) {
|
||||
return nil, service.ErrUserNotActive
|
||||
}
|
||||
return userEntity, nil
|
||||
}
|
||||
|
||||
@@ -1801,6 +1796,11 @@ func (h *AuthHandler) ExchangePendingOAuthCompletion(c *gin.Context) {
|
||||
response.ErrorFrom(c, err)
|
||||
return
|
||||
}
|
||||
if err := ensureLoginUserActive(loginUser); err != nil {
|
||||
clearCookies()
|
||||
response.ErrorFrom(c, err)
|
||||
return
|
||||
}
|
||||
if err := h.ensureBackendModeAllowsUser(c.Request.Context(), loginUser); err != nil {
|
||||
clearCookies()
|
||||
response.ErrorFrom(c, err)
|
||||
|
||||
Reference in New Issue
Block a user