From 4682af25d588ac160d129697c7e1cc69a60c62f0 Mon Sep 17 00:00:00 2001 From: aoright <102943475+aoright@users.noreply.github.com> Date: Thu, 20 Aug 2026 15:57:31 +0800 Subject: [PATCH] fix: use io.ReadFull(rand.Reader, b) in generateRandomBytes Signed-off-by: aoright <102943475+aoright@users.noreply.github.com> --- helpers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helpers.go b/helpers.go index 99005ee..181e450 100644 --- a/helpers.go +++ b/helpers.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "fmt" "html/template" + "io" "net/http" "net/url" ) @@ -142,14 +143,13 @@ func (cs *csrf) requestToken(r *http.Request) ([]byte, error) { // fails to function correctly. func generateRandomBytes(n int) ([]byte, error) { b := make([]byte, n) - _, err := rand.Read(b) + _, err := io.ReadFull(rand.Reader, b) // err == nil only if len(b) == n if err != nil { return nil, err } return b, nil - } // sameOrigin returns true if URLs a and b share the same origin. The same