From 7fd524f70b82021df5e7d58f2a6d5fc483ecafe1 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Fri, 1 Mar 2024 01:04:50 +0100 Subject: [PATCH] Default to generating request IDs using UUIDv4 format in CA --- internal/requestid/requestid.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/requestid/requestid.go b/internal/requestid/requestid.go index 97f58f8ca..7008d4696 100644 --- a/internal/requestid/requestid.go +++ b/internal/requestid/requestid.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/rs/xid" + "go.step.sm/crypto/randutil" ) const ( @@ -61,9 +62,16 @@ func (h *Handler) Middleware(next http.Handler) http.Handler { return http.HandlerFunc(fn) } -// newRequestID creates a new request ID using github.com/rs/xid. +// newRequestID generates a new random UUIDv4 request ID. If UUIDv4 +// generation fails, it'll fallback to generating a random ID using +// github.com/rs/xid. func newRequestID() string { - return xid.New().String() + requestID, err := randutil.UUIDv4() + if err != nil { + requestID = xid.New().String() + } + + return requestID } type requestIDKey struct{}