From c138e76c1ce487beb6a34737a96d7c9239a50cd1 Mon Sep 17 00:00:00 2001 From: Balki <189196+balki@users.noreply.github.com> Date: Wed, 17 Aug 2022 18:25:28 +0000 Subject: [PATCH] Fix panic when an invalid oauth2 name is passed (#20820) --- models/auth/oauth2.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/models/auth/oauth2.go b/models/auth/oauth2.go index 5a58ec62b..ad1d80e25 100644 --- a/models/auth/oauth2.go +++ b/models/auth/oauth2.go @@ -512,10 +512,14 @@ func GetActiveOAuth2ProviderSources() ([]*Source, error) { func GetActiveOAuth2SourceByName(name string) (*Source, error) { authSource := new(Source) has, err := db.GetEngine(db.DefaultContext).Where("name = ? and type = ? and is_active = ?", name, OAuth2, true).Get(authSource) - if !has || err != nil { + if err != nil { return nil, err } + if !has { + return nil, fmt.Errorf("oauth2 source not found, name: %q", name) + } + return authSource, nil }