Skip to content

Commit

Permalink
Fixing security issue when an user gain access to a different account.
Browse files Browse the repository at this point in the history
  • Loading branch information
diegosperes committed Mar 19, 2024
1 parent 6d3d241 commit 8c499f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/services/identity_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ func IdentityReconciler(accountStore data.AccountStore, cfg *app.Config, provide
return nil, errors.Wrap(err, "FindByOauthAccount")
}
if linkedAccount != nil {
if linkedAccount.ID != linkableAccountID && linkableAccountID != 0 {
return nil, errors.New("account already linked")
}

if linkedAccount.Locked {
return nil, errors.New("account locked")
}

return linkedAccount, nil
}

Expand Down
17 changes: 17 additions & 0 deletions server/handlers/get_oauth_return_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ func TestGetOauthReturn(t *testing.T) {
test.AssertRedirect(t, res, "https://localhost:9999/return?status=failed")
})

t.Run("not connect provider account already linked", func(t *testing.T) {
linkedAccount, err := app.AccountStore.Create("[email protected]", []byte("password"))
require.NoError(t, err)

err = app.AccountStore.AddOauthAccount(linkedAccount.ID, "test", "LINKEDID", "TOKEN")
require.NoError(t, err)

account, err := app.AccountStore.Create("[email protected]", []byte("password"))
require.NoError(t, err)

session := test.CreateSession(app.RefreshTokenStore, app.Config, account.ID)

res, err := client.WithCookie(session).Get("/oauth/test/return?code=LINKEDID&state=" + state)
require.NoError(t, err)
test.AssertRedirect(t, res, "https://localhost:9999/return?status=failed")
})

t.Run("log in to existing identity", func(t *testing.T) {
account, err := app.AccountStore.Create("[email protected]", []byte("password"))
require.NoError(t, err)
Expand Down

0 comments on commit 8c499f9

Please sign in to comment.