[v8.5.x] Chore: Release 8.5.14 (#56698)

* remove support for v1

(cherry picked from commit 8630a7a991af74edc4030f57d37a4bc263202fde)

* Security: Make proxy endpoints not leak sensitive HTTP headers

Fixes CVE-2022-31130

(cherry picked from commit 2974574a53ab6d26be7b706e76271173a91fea3a)

* Security: Fix do not forward login cookie in outgoing requests

(cherry picked from commit 54a32fc83b233f5910495b5fcca0b4f881221538)

* Add test for username/login field conflict

(cherry picked from commit 7aabcf2694)

* Swap order of login fields

(cherry picked from commit 5ec176cada)

* "Release: Updated versions in package to 8.5.14" (#547)

Co-authored-by: Will Browne <will.browne@grafana.com>
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>
Co-authored-by: Grot (@grafanabot) <43478413+grafanabot@users.noreply.github.com>
This commit is contained in:
Sofia Papagiannaki
2022-10-11 15:25:10 +03:00
committed by GitHub
co-authored by Will Browne Marcus Efraimsson linoman Grot
parent 811b6c06b0
commit 58b7ae14ce
30 changed files with 260 additions and 86 deletions
+15 -10
View File
@@ -295,20 +295,25 @@ func (ss *SQLStore) GetUserByLogin(ctx context.Context, query *models.GetUserByL
return models.ErrUserNotFound
}
// Try and find the user by login first.
// It's not sufficient to assume that a LoginOrEmail with an "@" is an email.
var has bool
var err error
user := &models.User{Login: query.LoginOrEmail}
has, err := sess.Where(notServiceAccountFilter(ss)).Get(user)
if err != nil {
return err
}
if !has && strings.Contains(query.LoginOrEmail, "@") {
// If the user wasn't found, and it contains an "@" fallback to finding the
// user by email.
// Since username can be an email address, attempt login with email address
// first if the login field has the "@" symbol.
if strings.Contains(query.LoginOrEmail, "@") {
user = &models.User{Email: query.LoginOrEmail}
has, err = sess.Get(user)
if err != nil {
return err
}
}
// Lookup the login field instead of email field
if !has {
user = &models.User{Login: query.LoginOrEmail}
has, err = sess.Where(notServiceAccountFilter(ss)).Get(user)
}
if err != nil {
+39
View File
@@ -47,6 +47,45 @@ func TestUserDataAccess(t *testing.T) {
require.False(t, query.Result.IsDisabled)
})
t.Run("Get User by login - user_2 uses user_1.email as login", func(t *testing.T) {
ss = InitTestDB(t)
// create user_1
cmd := models.CreateUserCommand{
Email: "user_1@mail.com",
Name: "user_1",
Login: "user_1",
Password: "user_1_password",
IsDisabled: true,
}
user_1, err := ss.CreateUser(context.Background(), cmd)
require.Nil(t, err)
// create user_2
cmd = models.CreateUserCommand{
Email: "user_2@mail.com",
Name: "user_2",
Login: "user_1@mail.com",
Password: "user_2_password",
IsDisabled: true,
}
user_2, err := ss.CreateUser(context.Background(), cmd)
require.Nil(t, err)
// query user database for user_1 email
query := models.GetUserByLoginQuery{LoginOrEmail: "user_1@mail.com"}
err = ss.GetUserByLogin(context.Background(), &query)
require.Nil(t, err)
// expect user_1 as result
require.Equal(t, user_1.Email, query.Result.Email)
require.Equal(t, user_1.Login, query.Result.Login)
require.Equal(t, user_1.Name, query.Result.Name)
require.NotEqual(t, user_2.Email, query.Result.Email)
require.NotEqual(t, user_2.Login, query.Result.Login)
require.NotEqual(t, user_2.Name, query.Result.Name)
})
t.Run("Testing DB - creates and loads disabled user", func(t *testing.T) {
ss = InitTestDB(t)
cmd := models.CreateUserCommand{