Skip to content

Commit

Permalink
fix #115 state variable alpha num
Browse files Browse the repository at this point in the history
  • Loading branch information
bnfinet committed May 3, 2019
1 parent 998906f commit 346ac40
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"mime/multipart"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -261,6 +262,17 @@ func HealthcheckHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "{ \"ok\": true }")
}

var regExJustAlphaNum, _ = regexp.Compile("[^a-zA-Z0-9]+")

func generateStateNonce() (string, error) {
state, err := securerandom.URLBase64InBytes(base64Bytes)
if err != nil {
return "", err
}
state = regExJustAlphaNum.ReplaceAllString(state, "")
return state, nil
}

// LoginHandler /login
// currently performs a 302 redirect to Google
func LoginHandler(w http.ResponseWriter, r *http.Request) {
Expand All @@ -273,7 +285,7 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
log.Warnf("couldn't find existing encrypted secure cookie with name %s: %s (probably fine)", cfg.Cfg.Session.Name, err)
}

state, err := securerandom.URLBase64OfBytes(base64Bytes)
state, err := generateStateNonce()
if err != nil {
log.Error(err)
}
Expand Down

0 comments on commit 346ac40

Please sign in to comment.