Skip to content

Commit

Permalink
crash in store due to a bug in mysql adapter on missing auth record
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Aug 20, 2021
1 parent b0e2b17 commit f7a42cd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/db/mongodb/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ func (a *adapter) AuthGetRecord(uid t.Uid, scheme string) (string, auth.Level, [
err := a.db.Collection("auth").FindOne(a.ctx, filter, findOpts).Decode(&record)
if err != nil {
if err == mdb.ErrNoDocuments {
return "", 0, nil, time.Time{}, t.ErrNotFound
err = t.ErrNotFound
}
return "", 0, nil, time.Time{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions server/db/mysql/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,8 @@ func (a *adapter) AuthGetRecord(uid t.Uid, scheme string) (string, auth.Level, [
if err := a.db.GetContext(ctx, &record, "SELECT uname,secret,expires,authlvl FROM auth WHERE userid=? AND scheme=?",
store.DecodeUid(uid), scheme); err != nil {
if err == sql.ErrNoRows {
// Nothing found - clear the error
err = nil
// Nothing found - use standard error.
err = t.ErrNotFound
}
return "", 0, nil, expires, err
}
Expand Down
3 changes: 2 additions & 1 deletion server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,8 @@ func (s *Session) login(msg *ClientComMessage) {
}

// authSecretReset resets an authentication secret;
// params: "auth-method-to-reset:credential-method:credential-value".
// params: "auth-method-to-reset:credential-method:credential-value",
// for example: "basic:email:[email protected]".
func (s *Session) authSecretReset(params []byte) error {
var authScheme, credMethod, credValue string
if parts := strings.Split(string(params), ":"); len(parts) == 3 {
Expand Down
7 changes: 6 additions & 1 deletion server/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,13 @@ func (UsersObjMapper) GetAuthRecord(user types.Uid, scheme string) (string, auth
unique, authLvl, secret, expires, err := adp.AuthGetRecord(user, scheme)
if err == nil {
parts := strings.Split(unique, ":")
unique = parts[1]
if len(parts) > 1 {
unique = parts[1]
} else {
err = types.ErrInternal
}
}

return unique, authLvl, secret, expires, err
}

Expand Down

0 comments on commit f7a42cd

Please sign in to comment.