Skip to content

Commit 03fd45b

Browse files
committed
fix: remove timing attack when comparing raw tokens
1 parent 3bfce6f commit 03fd45b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

authorization/storage_authorization.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package authorization
22

33
import (
44
"context"
5+
"crypto/subtle"
56
"encoding/json"
67
goerrors "errors"
78
"fmt"
@@ -197,7 +198,7 @@ func (s *Store) GetAuthorizationByID(ctx context.Context, tx kv.Tx, id platform.
197198
// the comparison fails.
198199
func (s *Store) validateToken(auth *influxdb.Authorization, token string) (bool, error) {
199200
if auth.Token != "" {
200-
return auth.Token == token, nil
201+
return subtle.ConstantTimeCompare([]byte(auth.Token), []byte(token)) == 1, nil
201202
}
202203

203204
if auth.HashedToken != "" {

0 commit comments

Comments
 (0)