server/auth: fix oss-fuzz issue 44478

This commit is contained in:
AdamKorcz 2022-02-10 16:31:05 +00:00
parent 20c89df5e5
commit 9d83325db8

View File

@ -20,6 +20,7 @@ package auth
import (
"context"
"crypto/rand"
"errors"
"fmt"
"math/big"
"strconv"
@ -212,7 +213,11 @@ func (t *tokenSimple) info(ctx context.Context, token string, revision uint64) (
func (t *tokenSimple) assign(ctx context.Context, username string, rev uint64) (string, error) {
// rev isn't used in simple token, it is only used in JWT
index := ctx.Value(AuthenticateParamIndex{}).(uint64)
var index uint64
var ok bool
if index, ok = ctx.Value(AuthenticateParamIndex{}).(uint64); !ok {
return "", errors.New("failed to assign")
}
simpleTokenPrefix := ctx.Value(AuthenticateParamSimpleTokenPrefix{}).(string)
token := fmt.Sprintf("%s.%d", simpleTokenPrefix, index)
t.assignSimpleTokenToUser(username, token)