Skip to content

Commit ef6744c

Browse files
beeonthegounknwon
authored andcommitted
csrf: token uses raw url encoding without padding (#8)
this will get the token ready for use in query string directly.
1 parent aea9bbd commit ef6744c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

xsrf.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func generateTokenAtTime(key, userID, actionID string, now time.Time) string {
5050
h := hmac.New(sha1.New, []byte(key))
5151
fmt.Fprintf(h, "%s:%s:%d", clean(userID), clean(actionID), now.UnixNano())
5252
tok := fmt.Sprintf("%s:%d", h.Sum(nil), now.UnixNano())
53-
return base64.URLEncoding.EncodeToString([]byte(tok))
53+
return base64.RawURLEncoding.EncodeToString([]byte(tok))
5454
}
5555

5656
// Valid returns true if token is a valid, unexpired token returned by Generate.
@@ -61,7 +61,7 @@ func ValidToken(token, key, userID, actionID string) bool {
6161
// validTokenAtTime is like Valid, but it uses now to check if the token is expired.
6262
func validTokenAtTime(token, key, userID, actionID string, now time.Time) bool {
6363
// Decode the token.
64-
data, err := base64.URLEncoding.DecodeString(token)
64+
data, err := base64.RawURLEncoding.DecodeString(token)
6565
if err != nil {
6666
return false
6767
}

0 commit comments

Comments
 (0)