From 37458bffbf4d9ee79fe7861f13bb9b68b1a9872e Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 22 Aug 2022 04:23:48 +0100 Subject: [PATCH] Fix panic when an invalid oauth2 name is passed (#20820) (#20900) --- 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 c5c6e9112..9c479becd 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 }