Skip to content

Commit

Permalink
auth: Add extra random bytes to session token
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspcr committed Oct 7, 2024
1 parent eac16c7 commit 57e9385
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/deserver/internal/server/handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"context"
"crypto/rand"
"encoding/base64"
"errors"

Expand Down Expand Up @@ -69,7 +70,14 @@ func (ah authHandler) Login(
return nil, errors.New("invalid credentials")
}

authToken := base64.StdEncoding.EncodeToString([]byte(usr.Ids.Email))
tokenSuffix := make([]byte, 4)
if _, err := rand.Read(tokenSuffix); err != nil {
return nil, err
}

authToken := base64.StdEncoding.EncodeToString(
append([]byte(usr.Ids.Email), tokenSuffix...),
)
ah.session.Add(authToken)

return &api.AuthServiceLoginResponse{Token: authToken}, nil
Expand Down

0 comments on commit 57e9385

Please sign in to comment.