Skip to content

Consider using crypto/rand for PKCE code_verifier and jti generation #144

@kblissett

Description

@kblissett

Hey! I was looking through the code and noticed that RandomString() in internal/oauth2/crypto.go uses math/rand seeded with time.Now().UnixNano():

  func init() {
        r = rand.New(rand.NewSource(time.Now().UnixNano()))
  }

This is used for:

  • PKCE code_verifier (request.go:89)
  • jti claims in JWT assertions (jwt.go:86, jwt.go:136)

This probably doesn't present a practical security risk, but wouldn't it be more in line with best practices to use crypto/rand instead? Something like:

import "crypto/rand"

func RandomString(n int) string {
      b := make([]byte, n)
      rand.Read(b)
      for i := range b {
              b[i] = letter[b[i]%byte(len(letter))]
      }
      return string(b)
}

Anyway, not urgent, just thought I'd flag it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions