From 01fccbc3e85ba4a3e4f83420f2537358949a9b81 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 13 Jan 2025 11:48:41 +0100 Subject: [PATCH] util: correctly truncate randomurl string Signed-off-by: Kristoffer Dalby --- hscontrol/util/string.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hscontrol/util/string.go b/hscontrol/util/string.go index ce38b82e..08769060 100644 --- a/hscontrol/util/string.go +++ b/hscontrol/util/string.go @@ -32,7 +32,8 @@ func GenerateRandomBytes(n int) ([]byte, error) { func GenerateRandomStringURLSafe(n int) (string, error) { b, err := GenerateRandomBytes(n) - return base64.RawURLEncoding.EncodeToString(b), err + uenc := base64.RawURLEncoding.EncodeToString(b) + return uenc[:n], err } // GenerateRandomStringDNSSafe returns a DNS-safe