Skip to content

Commit

Permalink
make cred validator use STD base64 instead of URL base64 token, consi…
Browse files Browse the repository at this point in the history
…tently with normal auth token
  • Loading branch information
or-else committed Aug 30, 2022
1 parent 59f89b0 commit df465dd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions server/validate/email/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (v *validator) PreCheck(cred string, _ map[string]interface{}) (string, err
return validatorName + ":" + addr.Address, nil
}

// Send a request for confirmation to the user: makes a record in DB and nothing else.
// Send a request for confirmation to the user: makes a record in DB and nothing else.
func (v *validator) Request(user t.Uid, email, lang, resp string, tmpToken []byte) (bool, error) {
// Email validator cannot accept an immediate response.
if resp != "" {
Expand All @@ -358,8 +358,8 @@ func (v *validator) Request(user t.Uid, email, lang, resp string, tmpToken []byt
// Normalize email to make sure Unicode case collisions don't lead to security problems.
email = strings.ToLower(email)

token := make([]byte, base64.URLEncoding.EncodedLen(len(tmpToken)))
base64.URLEncoding.Encode(token, tmpToken)
token := make([]byte, base64.StdEncoding.EncodedLen(len(tmpToken)))
base64.StdEncoding.Encode(token, tmpToken)

// Generate expected response as a random numeric string between 0 and 999999.
// The PRNG is already initialized in main.go. No need to initialize it here again.
Expand All @@ -375,7 +375,7 @@ func (v *validator) Request(user t.Uid, email, lang, resp string, tmpToken []byt
}

content, err := executeTemplate(template, map[string]interface{}{
"Token": string(token),
"Token": url.QueryEscape(string(token)),
"Code": resp,
"HostUrl": v.HostUrl})
if err != nil {
Expand Down Expand Up @@ -403,8 +403,8 @@ func (v *validator) ResetSecret(email, scheme, lang string, tmpToken []byte, par
// Normalize email to make sure Unicode case collisions don't lead to security problems.
email = strings.ToLower(email)

token := make([]byte, base64.URLEncoding.EncodedLen(len(tmpToken)))
base64.URLEncoding.Encode(token, tmpToken)
token := make([]byte, base64.StdEncoding.EncodedLen(len(tmpToken)))
base64.StdEncoding.Encode(token, tmpToken)

var template *textt.Template
if v.langMatcher != nil {
Expand All @@ -422,7 +422,7 @@ func (v *validator) ResetSecret(email, scheme, lang string, tmpToken []byte, par

content, err := executeTemplate(template, map[string]interface{}{
"Login": login,
"Token": string(token),
"Token": url.QueryEscape(string(token)),
"Scheme": scheme,
"HostUrl": v.HostUrl})
if err != nil {
Expand Down

0 comments on commit df465dd

Please sign in to comment.