Skip to content

Commit

Permalink
fix for #861
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed May 9, 2023
1 parent 72f9cc1 commit 30d2f02
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ func (s *Session) authSecretReset(params []byte) error {
return types.ErrMalformed
}

// Technically we don't need to check it here, but we are going to mail the 'authName' string to the user.
// Technically we don't need to check it here, but we are going to mail the 'authScheme' string to the user.
// We have to make sure it does not contain any exploits. This is the simplest check.
auther := store.Store.GetLogicalAuthHandler(authScheme)
if auther == nil {
Expand All @@ -1010,8 +1010,12 @@ func (s *Session) authSecretReset(params []byte) error {
if err != nil {
return err
}
tempScheme, err := validator.TempAuthScheme()
if err != nil {
return err
}

code, _, err := store.Store.GetLogicalAuthHandler("code").GenSecret(&auth.Rec{
code, _, err := store.Store.GetLogicalAuthHandler(tempScheme).GenSecret(&auth.Rec{
Uid: uid,
AuthLevel: auth.LevelAuth,
Features: auth.FeatureNoLogin,
Expand Down
5 changes: 5 additions & 0 deletions server/validate/email/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ func (v *validator) Remove(user t.Uid, value string) error {
return store.Users.DelCred(user, validatorName, value)
}

// TempAuthScheme returns a temporary authentication method used by this validator.
func (v *validator) TempAuthScheme() (string, error) {
return "token", nil
}

// SendMail replacement
func (v *validator) sendMail(rcpt []string, msg []byte) error {

Expand Down
5 changes: 5 additions & 0 deletions server/validate/tel/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ func (*validator) Remove(user t.Uid, value string) error {
return store.Users.DelCred(user, validatorName, value)
}

// TempAuthScheme returns a temporary authentication method used by this validator.
func (v *validator) TempAuthScheme() (string, error) {
return "code", nil
}

// Implement sending the SMS.
func (*validator) send(to, body string) error {
logs.Info.Println("Send SMS, To:", to, "; Text:", body)
Expand Down
6 changes: 5 additions & 1 deletion server/validate/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Validator interface {
// Returns normalized credential prefixed with an appropriate namespace prefix.
PreCheck(cred string, params map[string]interface{}) (string, error)

// Request sends a request for confirmation to the user. Returns true if it's a new credential,
// Request sends a request for validation to the user. Returns true if it's a new credential,
// false if it re-sent request for an existing unconfirmed credential.
// user: UID of the user making the request.
// cred: credential being validated, such as email or phone.
Expand All @@ -52,6 +52,10 @@ type Validator interface {

// Delete deletes user's record.
Delete(user t.Uid) error

// TempAuthScheme returns a temporary authentication method used by this validator.
// It should be either "code" or "token".
TempAuthScheme() (string, error)
}

func ValidateHostURL(origUrl string) (string, error) {
Expand Down

0 comments on commit 30d2f02

Please sign in to comment.